#ifndef SLISTWIDGET_H
#define SLISTWIDGET_H

#include <QTableWidget>

#include <vector>
#include <map>
using namespace std;

#include "common.h"

#include "headertype1.h"

#include "sslidebar.h"



enum SINGLE_ENUM
{
    SINGLE_NONE = 0,
    SINGLE_UP = 1,
    SINGLE_DOWN = 2
};

class SListWidget : public QTableWidget
{
    Q_OBJECT
public:
    explicit SListWidget(QWidget *parent = nullptr);
    virtual ~SListWidget();

    virtual void Init();

    virtual void InitHeader();

    virtual void ChangeHeader();

    virtual void Clear();

    virtual void UpdateHistoryList();
    virtual void UpdateWorklist();

    virtual void SetData();

    virtual void SetMaximumVisibleRow(int nRow);

    void SetResizeEnableHeader(bool bResize);

    HeaderType1* GetHeaderType1();

    void keyPressEvent(QKeyEvent *event) override;

    void SetSlideBarVertical(SSlideBar* pSlideBar, QFrame* pFrame);

    void SetSlideBarHorizontal(SSlideBar* pSlideBar, QFrame* pFrame);

    virtual void wheelEvent(QWheelEvent *event);
    void resizeEvent(QResizeEvent *event) override;

    void CheckHorizontalScroll();

    void SetListType(int nType);

    void ChangeDateDisplayFormat(QString& strData);
    void ChangeTimeDisplayFormat(QString& strData);

    int GetSelectIndexWorklist(int nRow);



public slots:
    void Resort(int nIndex, int order);

    void SingleDown();
    void SingleUp();

    void valueChangedScrollBarVertical(int value);
    void valueChangedScrollBarHorizontal(int value);

    void sectionResizedHorizontal(int logicalIndex, int oldSize, int newSize);
    void sectionHandleDoubleClickedHorizontal(int logicalIndex);

    void ScrollUpdateHorizontal();

signals:
    void SetSlideValue(int nValue);

    void ListSingleDown();
    void ListSingleUp();


protected:
    int m_nRowHeight;
    QTimer m_TimerScrollHorizontal;
    map<int, RowData> m_ListData;

    HeaderType1* m_pHeaderType1;

    int m_nCurrentPos;
    int m_nTopDisplayIndex;

    SINGLE_ENUM m_CurrentSingle;

    SSlideBar* m_pSlideBarVertical;
    SSlideBar* m_pSlideBarHorizontal;
    QFrame* m_pSlideBarHorizontalWidget;
    QFrame* m_pSlideBarVerticalWidget;

    int m_nMaxItemShow;

    int m_nListType;

    vector<QTableWidgetItem*> m_ListItem;
};

#endif // SListWidget_H
