#ifndef CMAINWND_H
#define CMAINWND_H

#include <QObject>
#include <QWidget>
#include <QWebEngineView>
#include <QTextEdit>
#include <QLabel>
#include <QJsonParseError>
#include <QJsonObject>
#include <QDesktopWidget>
#include <QApplication>
#include <QMenuBar>
#include <QToolButton>
#include <QAction>
#include <QDebug>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QStackedWidget>
#include <QFileSystemWatcher>
#include <QGuiApplication>
#include <QScreen>
#include <QList>

#include <kysdk/applications/kwidget.h>
#include "msgpane.h"
#include "cpushbuttonex.h"
#include "setting/kasettingdialog.h"
#include "dbus/kadbusoperator.h"
#include "sidebarwidget.h"
#include "textselect/clipboard.h"
#include "textselect/selection.h"
#include "xeventmonitor.h"
#include "setting/kafloatingbarpage.h"

using namespace kdk;

#define SIDEBAR_WIDTH                    402

class CPushButtonEx;

enum MainWndViewType
{
    TABTITLE_MESSAGE = 0,       // 消息会话
    TABTITLE_VOICE = 1,      // 通讯录
};

class CMainWnd : public KWidget
{
    Q_OBJECT
public:
    enum WindowMode
    {
        WINDOW_MODE_NORMAL = 0,
        WINDOW_MODE_OCCUPIED
    };

    explicit CMainWnd(QWidget *parent = nullptr);
    ~CMainWnd();
private:
    void createAllChildWnd();
    void initCtrl();
    void initSolts();
    void relayout();
    void initTrayIcon();
    void showView();
    void hideView();
    void initScribeWords();
    void initPosition();
    void monitorDesktopFile();
    void initSideBarSize();
    void initXeventMonitor();
    void changeToOccupiedMode();
    void initScribeWordsSetting();
    void changeToNormalMode();

public slots:
    void slotToTop();

    void onConfActionTriggered();

    void onShotCutActionTriggled();
    void onAboutActionTriggled();
    void onExitActionTriggled();
    void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
    void onAppRestarted();
    void onWndBtnClicked();
    void onPageChanged(const QUrl &url);
    void handleClicpText();
    void onDirectoryChanged();
    void onCreateDialog();
    void onX11GlobalMousePress(int x, int y);
    void onWindowModeButtonClicked();

signals:
private:
    void closeEvent(QCloseEvent *e) override;

private:
    bool m_isTop = false;
    quint64 m_window_id = 0;
    int m_nScreen_x; // 主屏的起始坐标X
    int m_nScreen_y; // 主屏的起始坐标Y
    int m_nScreenWidth; // 屏幕分辨率的宽
    int m_nScreenHeight; // 屏幕分辨率的高

    SideBarWidget *m_sideBar = nullptr;
    CPushButtonEx *m_btnWnd = nullptr;
    QPushButton *m_btnBack = nullptr;
    QPushButton *m_btnStick = nullptr;
    QPushButton *m_btnOccupiedMode = nullptr;
    QAction *confAction = nullptr;
    KASettingDialog *m_addModelDialog = nullptr;
    KADBusOperator *m_dbusOperator = nullptr;
    QAction *m_shotcutAction = nullptr;
    QAction *m_aboutAction = nullptr;
    QAction *m_exitAction = nullptr;
    QMenu *m_trayIconMenu = nullptr;
    QSystemTrayIcon *m_trayIcon = nullptr;
    CMsgPane *m_msgPane = nullptr;
    Clipboard *m_selectclip = nullptr;
    SelectWidget *m_selectwid = nullptr;
    QFileSystemWatcher *m_fileWatcher = nullptr;
    ChannelMessage *m_channelMsg = nullptr;
    QString clipText;
    xEventMonitor* m_xeventMonitor = nullptr;
    KAFloatingBarPage *floatingBarPage = nullptr;
};

#endif // CMAINWND_H
