/*
 * Copyright (C) 2020, KylinSoft 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 of the License, 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 <https://www.gnu.org/licenses/>.
 */

#ifndef MENUMODULE_H
#define MENUMODULE_H

#ifndef UKUI_THEME_GSETTING_PATH
#define UKUI_THEME_GSETTING_PATH "org.ukui.style"
#endif

#include <QApplication>
#include <QObject>
#include <QWidget>
#include <QMenu>
#include <QPushButton>
#include <QKeyEvent>
#include <QToolButton>
#include <QDebug>
#include <QString>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDesktopServices>
#include <QRect>
#include <QUrl>
#include <QScreen>
#include <QGSettings>
#include <QMetaEnum>
#include <QScrollArea>

// 主题sdk关于
#include "kaboutdialog.h"

class menuModule : public QWidget
{
    Q_OBJECT
public:
    explicit menuModule(QWidget *);
    void themeUpdate();

signals:
    void menuModuleClose();
    void menuModuleChanged(QString);
    void pullupHelp();

    void menuModuleSetThemeStyle(QString);

public:
    QToolButton *m_menuButton = nullptr;

public:
    //    程序在实例化的时候需要传递的信息字段,打开debug开关后这些字段会被自动填充
    QString appName = "Messages";            //格式kylin-usb-creator
    QString appShowingName = tr("Messages"); //格式kylin usb creator ,用来在前端展示
//    QString appVersion = qApp->applicationVersion();
    QString confPath = "org.kylin-calculator-data.settings";

    kdk::KAboutDialog *m_aboutWindow = nullptr; // 关于界面

private:
    QMenu *m_menu = nullptr;
    QMenu *themeMenu = nullptr;
    QSize iconSize;
    QString appPath = "messages"; //拉起帮助菜单时使用appName字段

    // QGSettings *m_pGsettingThemeData = nullptr;
    // QGSettings *m_pGsettingThemeStatus = nullptr;
    enum typeThemeStatus : int { themeAuto = 0, themeBlackOnly = 1, themeLightOnly = 2 } themeStatus;
    QString appVersion     = nullptr;

public slots:
    void dealSystemGsettingChange(const QString);

private:
    void keyPressEvent(QKeyEvent *event);
    void init();

    QScrollArea *scrollArea;

    void initGsetting();
    void initAction();

    void setStyle();
    void triggerMenu(QAction *act);      //主菜单动作4
    void triggerThemeMenu(QAction *act); //主题动作

    void initAbout(); //关于窗口初始化
    void helpAction();
    void setupAction();

    QString getfontviewerVersion();

    void setThemeFromLocalThemeSetting(QList<QAction *>); //获取本地主题配置
    void setStyleByThemeGsetting();                       //通过外部主题配置设置主题
    void setThemeStyle();
    void setThemeLight();
    void setThemeDark();
    //    void updateTheme(); //点击菜单中的主题设置后更新一次主题

    void refreshThemeBySystemConf(); //通过系统配置更改主题
};

#endif // MENUMODULE_H
