/*
* Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef SHORTCUTPANELPLUGIN_H
#define SHORTCUTPANELPLUGIN_H
#include "shortCutPanelInterface.h"
#include <QObject>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDebug>
#include <QPainterPath>

#include "bluetoothwidgetModify.h"
#include "wifiwidget.h"
#include "accountinformation.h"
#include "scrollingareawidgetmajor.h"
#include "weatherwidget.h"
#include "powershow.h"
#include "../platforminfo.h"
#include "../dbusmanager.h"
#include "quickoperationdbus.h"
#include "templatewidget.h"

#define MAJOR_QUICK_PANEL_HEIGHT 460
#define MAJOR_QUICK_PANEL_CHANGE_HEIGHT  235
#define MAJOR_QUICK_PANEL_WIDTH  392

#define SIDEBAR_AND_PANEL_DISTANCE 8
#define ANIMATIONSPEED 300

#define KYLIN_TOP_OPEN_NORMAL_MAJOR_PATH        ":/image_major/open-pressed.svg"
#define KYLIN_TOP_CLOSE_NORMAL_MAJOR_PATH       ":/image_major/fold-pressed.svg"

#define THEME_QT_SCHEMA   "org.ukui.style"
#define MODE_QT_KEY       "style-name"


enum InterfaceEnum {
    PAD,
    WIFI,
    NODISTURB,
    SETTING,
    BLUETOOTH,
    HOTSPOT,
    CALCULATOR,
    SCREENSHOT,
    Else
};

class StateSpreadOrFoldWidget;
class PartLineWidget;
class MainWidget;

class shortcutPanelPlugin : public QObject, public shortCutPanelInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.ukui.sidebar-qt.plugin-iface.shortCutPanelInterface" FILE "shortcutPanelPlugin.json")
    Q_INTERFACES(shortCutPanelInterface)

public:
    explicit shortcutPanelPlugin(QObject *parent = nullptr);

    enum PanelStatePosition
    {
        PanelDown = 0,
        PanelUp,
        PanelLeft,
        PanelRight
    };

    //插件接口
    QWidget *getShortCutPanelWidget() override;

    /* Hash表  查、删、增 */
    InterfaceEnum getInterfaceMark(QString key);
    QHash<QString, InterfaceEnum> m_InterfaceHash;

    void removeInterfaceMark(QString key);
    void insertInterfaceMark(QString key, InterfaceEnum value);

private:

    //通用函数
    void initsetShortWidget();           //布局快捷按钮界面
    void initTranslations();             //初始化翻译文件
    void initDbusService();              //初始化dbus

    void initAnimation();                //初始化动画
    void hideAnimation();                //隐藏动画
    void showAnimation();                //显示动画

    void setScrollWidget();              //背光文件
    void initMemberVariablesMajor();     //初始化3.1插件成员变量
    void initShortButtonWidgetMajor();   //初始化3.1快捷按钮界面
    void setWidgetMajor();               //3.1将切换按钮和ListView界面set进插件主界面
    void setGridLayoutWidgetHide();      //隐藏部分界面
    void setGridLayoutWidgetShow();      //展开全部界面


    //通用变量
    QVBoxLayout  *m_pMainVLayout            = nullptr;  //主纵向布局
    QHBoxLayout  *m_userAndPowerHLayout     = nullptr;  //用户信息、折叠按钮、关机按钮的水平布局
    QVBoxLayout  *m_foldAndSpreadVLayout    = nullptr;  //折叠按钮的垂直布局
    QGridLayout  *m_pShortGLayout           = nullptr;  //快捷操作面板下半部分布局
    QHBoxLayout  *m_plowHLayout             = nullptr;  //底边天气于电量显示布局

    MainWidget   *m_pMainWidget   = nullptr;  //主界面
    QWidget      *m_pShortWidget  = nullptr;  //快捷按钮群界面

    PartLineWidget      *m_PartLine1  = nullptr;   //分割线1
    PartLineWidget      *m_PartLine2  = nullptr;   //分割线2
    PartLineWidget      *m_PartLine3  = nullptr;   //分割线3

    QList<QWidget*> ShortButtonWidgetList;            //保存按钮的列表

    AccountInformation       *m_PAccountInfoWidget;   //显示用户信息界面
    StateSpreadOrFoldWidget  *m_pSpreadOrFoldButton;  //显示折叠按钮界面
    ShutDownWidget           *m_shutDownButton;       //显示关机按钮
    weatherWidget            *m_pWeatherWidget;       //显示天气界面

    QuickOperationDbus    *m_QuickOperationDbus;      //快捷操作面板dbus

    QPropertyAnimation    *m_pAnimationShowSidebarWidget; //实例展开动画类
    QPropertyAnimation    *m_pAnimationHideSidebarWidget; //实例隐藏动画类

    //3.1特性变量
    bool                       m_bBacklitFile;               //背光文件状态值
    ScrollingAreaWidgetMajor   *m_pScrollingAreaWidgetMajor; //声音亮度滑动条
    int                        m_pChangeSize = 0;

public slots:
    void spreadClikedSlots();
    void foldClikedSlots();
};


class StateSpreadOrFoldWidget : public QWidget
{
    Q_OBJECT
public:
    explicit StateSpreadOrFoldWidget(QWidget *parent = nullptr);
    ~StateSpreadOrFoldWidget();

protected:
    virtual void mouseReleaseEvent(QMouseEvent *ev);

Q_SIGNALS:
    void LabelClicked(bool isFoldState);

private:
    bool isFoldState;
    QHBoxLayout *m_hlayout;
    QLabel * button;
    PictureToWhite *m_pPictureToWhite;
};

class PartLineWidget : public QWidget
{
    Q_OBJECT
public:
    explicit PartLineWidget(QWidget *parent = nullptr);
    void initStyle();
    void paintEvent(QPaintEvent *event);
    QGSettings* m_pStyleGsetting;
    QString m_pStyleName;

};

class MainWidget : public QWidget
{
public:
    MainWidget();
private:
    double      m_dtranSparency;
    void getTransParency();
    void setTransParency();

protected:
    void paintEvent(QPaintEvent *e);
};

#endif // SHORTCUTPANELPLUGIN_H
