#ifndef VIEWFILTERFILES_H
#define VIEWFILTERFILES_H

#include "src/model/filefiltermodel.h"
#include "src/view/windowtitle.h"

#include <QWidget>
#include <QObject>
#include <QDialog>
#include <QMutex>
#include <QPoint>
#include <QHeaderView>
#include <kwidget.h>
#include <kdialog.h>
#include <kpushbutton.h>

class QLabel;
class QComboBox;
class QVBoxLayout;
class QHBoxLayout;
class QSpacerItem;
class QTreeWidget;
class QTreeView;
class QTreeWidgetItem;

using namespace kdk;

class ViewFilterFiles : public QDialog
{
    Q_OBJECT
Q_SIGNALS:
    void delNode(int);
    void allFilesRestored(QList<void *> hiddens, QList<void *> brokens, QList<void *> replaces);
public:
    static ViewFilterFiles *instance();
public:
    void init() {}
    void updatePosition(QPoint);
public:
    ViewFilterFiles(const ViewFilterFiles*)=delete;
    ViewFilterFiles *operator =(const ViewFilterFiles *)=delete;
public:
    bool filtered();
    int currentIndex();
    QList<void *> recoveryHiddenData(int, int);
    QList<void *> recoveryBrokenData(int, int);
    QList<void *> recoveryRepleaceData(int, int);
public slots:
    void show();
    void newFilterRoot(void *);
    void filterHidden(int, void *);
    void filterBroken(int, void *);
    void repleace(int, void *);
    void updateIndex(int);
    void deleteNode(int);
private slots:
    void slotRestoreFiles();
public slots:
    void slotsChangeComboDiskIndex(void*);

    void slotChangeUIFontSize(int fontSize);

protected:
    void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
    explicit ViewFilterFiles(QWidget *parent = nullptr);
    ~ViewFilterFiles();

    void initDialog();
    void initMember();
    void initRootLayout();
    void initTitleLayout();
    void initSignalConnect();

    /**
     * @brief 设置TreeWidget的样式
     */
    void initTreeWidget();


private:
    static ViewFilterFiles *m_oInstance;
    static QMutex           m_oMutex;
    bool                    m_bIsWayland;

    QPoint                  m_oPosition;    /* 调整界面位置居中 */
    QComboBox              *mComboBoxDisk;  /* 界面调整后沿用之前逻辑而特意保留但不在界面显示的下拉列表框 */
    QList<void*>            mCDROMList;

    WindowTitle            *mWindowTitle;
    /* 以下是界面控件及其布局 */
    QWidget                 *mMainWdiget;
    QVBoxLayout             *mMainLayout;
    QHBoxLayout             *mTitleLayout;
    QHBoxLayout             *mButtonLayout;
    QHBoxLayout             *mFileTreeLayout;

    //TitleLayout
    QLabel                  *mTitleLabel;

    //ButtonLayout
    int                      btn1Width;
    int                      btn2Width;
    KPushButton             *mFilterOptionBtn;
    QSpacerItem             *mButtonSpacer1;
    KPushButton             *mRecoverAllBtn;
    QSpacerItem             *mButtonSpacer2;

    //FileTreeLayout
    QTreeView               *mTreeView;
    QList<QTreeWidgetItem*>  mTreeWidgetItemList;
    FileFilterModel        *m_oModel;
};
#endif // VIEWFILTERFILES_H
