#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QCalendarWidget>
#include <QDateEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QComboBox>
#include <QLineEdit>
#include <QGroupBox>
#include <QListWidget>
#include <QTabWidget>
#include <QRadioButton>
#include <QButtonGroup>
#include <QTableWidget>
#include <QProgressBar>
#include <QMenuBar>
#include <QSqlDatabase>
#include "stable.h"

class Widget : public QWidget
{
    enum E_COLUMN
    {
        E_COLUMN_DATABASE=0,
        E_COLUMN_NAME,
        E_COLUMN_DATE,
        E_COLUMN_COUNT,
    };

    enum E_LENGTH_COMP
    {
        E_LENGTH_COMP_GREATER = 0,
        E_LENGTH_COMP_LESS,
        E_LENGTH_COMP_EQUAL,
    };
    Q_OBJECT
public:
    Widget(QWidget *parent = 0);
    ~Widget();    
    QTabWidget *GetTabWidget()
    {
        return m_ptwData;
    }
    int getDatePosition()
    {
        return m_nColumn;
    }
    int getTitlePosition()
    {
        return m_nTitle;
    }
    int getBodyPosition()
    {
        return m_nBody;
    }

private:
    // Data
    QListWidget *m_plwData;
    // Date
    QCalendarWidget *m_pcw;
    QDateEdit *m_pdeStart;
    QDateEdit *m_pdeEnd;
    //QPushButton *m_ppbInsertCalc;
    //QComboBox *m_pcbDateCatalog;
    int m_nColumn;
    int m_nTitle;
    int m_nBody;
    // Keyword
    QComboBox *m_pcbCatalog;
    QComboBox *m_pcbKeyword;
    QComboBox *m_pcbMethod;
    QLineEdit *m_pleString;
    //QPushButton *m_ppbInsertSearch;
    // Length
    QComboBox *m_pcbLengthCatalog;
    QComboBox *m_pcbLengthComp;
    QComboBox *m_pcbLengthInsDel;
    QLineEdit *m_pleLength;
    // Filter
    QListWidget *m_plwFilterGroup;
    QListWidget *m_plwFilter;
    QLineEdit *m_pleFilterGroup;
    QGroupBox *m_pgbFilter;
    // Replace
    QComboBox *m_pcbReplaceCatalog;
    QComboBox *m_pcbReplaceFind;
    QLineEdit *m_pleReplaceFind;
    QLineEdit *m_pleReplace;

    // Count
    QComboBox *m_pcbCountCatalog;

    //
    QTabWidget *m_ptwData;
    //
    QProgressBar *m_pProgress;
    // Column
    QVector <QStringList> m_vecColumn;
private:
    QMenuBar *setMenuWidget();
    QGroupBox *setDataWidgets();
    QGroupBox *setDateWidgets();
    QGroupBox *setCountWidgets();
    QGroupBox *setSearchWidgets();
    QGroupBox *setLengthWidgets();
    QGroupBox *setFilterWidgets();
    QGroupBox *setReplaceWidgets();

    QTableWidget *AddTable(QString _str);
    void SetTableHead();
    void InsertCopyRow(int _nRow,QTableWidget *_pCurrent,QTableWidget *_pNew);
    void DataReload(QString _strTableName,int _nSelect);
    void InsertFilter(int _nType,QString _strJson,int _nGroup);
    void InsertTimeFilter(int _nTimeCategory ,QDate _dateStart ,QDate _dateEnd ,int _nGroup);
    void InsertSearchFilter(int _nArticle,int _nCategory,int _nMethod,int _nKeyword, QString _str,int _nGroup);
    void InsertLengthFilter(int _nArticle,int _nCategory,int _nComp,int _nInsDel,QString _str,int _nGroup);
    void InsertReplaceFilter(int _nArticle,int _nCategory,int _nFind,QString _strFind,QString _strReplace,int _nGroup);
    void RefreshFilter(int _nGroup);

    bool ReloadColumn();
    QString GetArticleType(int _nSelect);
public slots:
    void CloseTab(int index);
    void DoubleClickTab(int index);
    void SearchDate();
    void CountSave();
    void SearchKeyword();
    void DataGroupRefresh();
    void DataGroupItemChanged ( QListWidgetItem * item );
    void FilterGroupInsert();
    void FilterGroupDelete();
    void FilterGroupModify();
    void FilterGroupRefresh();
    void currentGroupItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0);
    void FilterDelete();
    void currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0);
    void SearchLengthInsert();
    void SearchReplaceInsert();
    void FileNew();
    void FileImport();
    void FileExport();
    void FileExit();
};

#endif // WIDGET_H
