#ifndef DASHBOARDFRAME_H
#define DASHBOARDFRAME_H

#include <QWidget>
#include "global.h"
#include "dataPanel/dpGlobals.h"

QT_BEGIN_NAMESPACE
namespace Ui {
class dashboardFrame;
}
QT_END_NAMESPACE

class QTimer;
class TransparentMask;
class MessageDialog;
class CustomTabBar;
class Dashboard;
class DashboardNamingDialog;
class PanelSelectionDialog;
class DateTimeWidget;
class TimeLineWidget;
class DataPanel;
class dpConfigurationDialog;
class AlarmEventRealTimeDock;
class AlarmEventMainDialog;
class AlarmEventConfigDialog;

namespace dashboardFrame {
    enum frameType
    {
        ft_main = 0,
        ft_secondary
    };
}

class DashboardFrame : public QWidget
{
    Q_OBJECT

public:
    explicit DashboardFrame(const QString&, dashboardFrame::frameType, QWidget *parent = nullptr);
    ~DashboardFrame();

    void showMessageDialog(MessageDialogType,const QString&,const QString&);
    void addDashboard(Dashboard*);
    void insertDashboard(int, Dashboard*);
    int dashboardCount();
    Dashboard* getDashboard(const QString&);
    Dashboard* takeDashboard(const QString&);
    DashboardFrame* getDashboardFrame(const QString&);
    void setDashboardAreaHighlight(bool);
    void moveDashboardToNewDVIEWindow(const QString&, QPoint);
    void openPanelConfigurationDialog(DataPanel*);

protected:
    bool eventFilter(QObject*, QEvent*) override;
    void resizeEvent(QResizeEvent*) override;
    void moveEvent(QMoveEvent*) override;
    void dragEnterEvent(QDragEnterEvent* event) override;
    //void dragMoveEvent(QDragMoveEvent* event) override;
    void dragLeaveEvent(QDragLeaveEvent* event) override;
    void dropEvent(QDropEvent* event) override;

private:
    void showTransparentMask();
    void hideTransparentMask();

    void addDashboard(const QString&);
    void removeDashboard(const QString&, bool);
    void setCurrentDashboard(const QString&);

public slots:
    void onSignal_showMask();
    void onSignal_hideMask();

    void onBtnClicked_addDashboard();
    void onBtnClicked_addDataPanel();
    void onBtnClicked_dashboardList();
    void onBtnClicked_dashboardTab();
    void onBtnClicked_showRealtimeEvents();
    void onBtnClicked_showHistoricalEvents();

    void onMenuAction_dashboardList();

    void onTimeout_realTime();

    void onSignal_subDialogClose();
    void onSignal_renameDashboard();
    void onSignal_removeDashboard();
    void onSignal_dashboardNaming(const QString&, const QString&);
    void onSignal_dashboardTabMoved(int, int); //拖动tab引发了位置变化
    void onSignal_panelSelectResult(DataPanelType);

    void onSignal_timeRangeChanged(TimeUnit);
    void onSignal_viewRealTimeData();
    void onSignal_viewHistoricalData(QDateTime);

    void onSignal_viewAllRealTimeEvents();
    void onSignal_openAlarmEventCfgDialog();

private:
    Ui::dashboardFrame*       ui;
    QString                   m_strName;
    dashboardFrame::frameType m_type;
    QWidget*                  m_pParentWindow;
    TransparentMask*          m_pTransparentMask;
    QWidget*                  m_pDashboardHighlight;
    MessageDialog*            m_pMessageDialog;
    CustomTabBar*             m_pDashboardTabBar;

    QList<Dashboard*>         m_listDashboard;
    Dashboard*                m_curActiveDashboard;
    Dashboard*                m_curOperationDashboard;

    DashboardNamingDialog*    m_pDashboardNamingDialog;
    PanelSelectionDialog*     m_pPanelSelectionDialog;
    DateTimeWidget*           m_pDateTimeWidget;
    TimeLineWidget*           m_pTimeLineWidget;

    dpConfigurationDialog*    m_pPanelConfigurationDialog;
    AlarmEventRealTimeDock*   m_pAlarmEventRealTimeDock;
    AlarmEventMainDialog*     m_pAlarmEventMainDialog;
    AlarmEventConfigDialog*   m_pAlarmEventConfigDialog;

    QTimer*                   m_pTimer_RealTime;
};

#endif
