#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QActionGroup>
#include <QTranslator>
#include <QGraphicsDropShadowEffect>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QMediaPlayer>
#include <QAudioOutput>
#include <QRegularExpression>

class QLabel;
class QPushButton;
class QGridLayout;
class MagnifierWidget;

class AboutDialog;
class AstroRefractionDialog;
class PoleTrackingDialog;
class FavoriteDialog;

class CaptureThread;

namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
        Q_OBJECT

    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

        void createTipMsgTabWidget();

        void saveParamToIni();
        bool loadParamFromIni();

        void loadStarsData();
        void drawPoleOnTemplateImage();

        void setCurrentStepIndex(int index);
        void rotateTemplateImage(int angle);
        void setCurrentTemplateImg(float scale, QString curRegion);
        void scaledDirectionImg(float scaled);

        void changeTipMsgContent(QString region);

    private slots:
        void on_pushButton_head_region_toggled(bool checked);

        void on_pushButton_head_setting_toggled(bool checked);

        void on_pushButton_head_confirm_toggled(bool checked);

        void on_pushButton_head_rough_toggled(bool checked);

        void on_pushButton_head_precise_toggled(bool checked);

        //slot for tipMsg buttons
        void pushbuttonSettingDoneClicked();
        void pushbuttonConfirmDoneClicked();
        void pushbuttonRotateStar1ResetClicked();
        void pushbuttonRotateStar1DoneClicked();
        void pushbuttonGetStar2ResetClicked();
        void pushbuttonRotateStar2ResetClicked();
        void pushbuttonRotateStar2DoneClicked();
        void pushbuttonGetStar3ResetClicked();
        void pushbuttonValidateCenterResetClicked();
        void pushbuttonValidateCenterDoneClicked();
        void pushbuttonGetEptPolarisDoneClicked();
        void pushbuttonMovePolarisDoneClicked();
        void pushbuttonGetCurPolarisDoneClicked();
        void pushbuttonFinetunePoleResetClicked();
        void pushbuttonFinetunePoleDoneClicked();

        void showImages();
        void increaseAngleTimeout();
        void graphicsEffectTimeout();
        void updateFPS();

        void poleTracking(double degree);
        void languageChanged();
        void uiReset();

        void on_radioButton_north_toggled(bool checked);

        void on_radioButton_south_toggled(bool checked);

        void on_horizontalSlider_confirm_match_valueChanged(int value);

        void on_pushButton_confirm_minus_clicked();

        void on_pushButton_confirm_add_clicked();

        void on_horizontalSlider_rough_match_valueChanged(int value);

        void on_pushButton_rough_minus_clicked();

        void on_pushButton_rough_add_clicked();

        void on_pushButton_monitor_clicked();

        void on_actionSave_As_triggered();

        void on_actionExit_triggered();

        void on_actionConnect_triggered();

        void on_actionDisplay_Template_toggled(bool arg1);

        void on_actionMono_Style_toggled(bool arg1);

        void on_actionStretch_toggled(bool arg1);

        void on_actionAstronomical_Refraction_triggered();

        void on_actionManual_Trace_triggered();

        void on_action100_toggled(bool arg1);

        void on_action75_toggled(bool arg1);

        void on_action50_toggled(bool arg1);

        void on_actionPoleMaster_Manual_triggered();

        void on_actionAbout_triggered();

        void on_actionEnglish_toggled(bool arg1);

        void on_actionChinese_toggled(bool arg1);

        void on_actionJapanese_toggled(bool arg1);

        void on_actionRussian_toggled(bool arg1);

        void on_actionFrench_toggled(bool arg1);

        void on_actionGerman_toggled(bool arg1);

        void on_actionSpanish_toggled(bool arg1);

        void on_actionPortuguese_toggled(bool arg1);

        void on_actionItalian_toggled(bool arg1);

        void on_actionKorean_toggled(bool arg1);

        void on_sliderExpose_valueChanged(int value);

        void on_lineEditExpose_returnPressed();

        void on_sliderGain_valueChanged(int value);

        void on_lineEditGain_returnPressed();

        void on_sliderTraffic_valueChanged(int value);

        void on_lineEditTraffic_returnPressed();

        void on_sliderSpeed_valueChanged(int value);

        void on_lineEditSpeed_returnPressed();

        void on_actionFavorite_triggered();

        void on_actionPlay_Audio_toggled(bool arg1);

        void on_actionPlay_Audio_triggered(bool checked);

    signals:
        void initAstroRefraction();
        void changeLanguage();
        void resetUI();

    protected:
        void closeEvent(QCloseEvent * event);

        bool eventFilter(QObject *obj, QEvent *e);

    private:
        Ui::MainWindow *ui;

        QActionGroup *zoomGroup;
        QActionGroup *languageGroup;

        QGridLayout *showImgAreaLayout;

        QLabel *label_status_mousePos;
        QLabel *label_fps;
        //    QLabel *label_magnifier;
        QImage *img_magnifier;

        QLabel *label_directionImg;
        MagnifierWidget *widget_magnifier;

        QTabWidget *tabWidget_tipMsg;
        QWidget *tab_setting;
        QLabel *label_setting_tipMsg;
        QLabel *label_settiing_ask;
        QPushButton *pushButton_settingDone;
        QWidget *tab_confirm;
        QLabel *label_confirm_tipMsg;
        QLabel *label_confirm_ask;
        QPushButton *pushButton_confirmDone;
        QWidget *tab_getStar1;
        QLabel *label_getStar1_tipMsg;
        QWidget *tab_rotateStar1;
        QLabel *label_rotateStar1_tipMsg;
        QLabel *label_rotateStar1_ask;
        QPushButton *pushButton_rotateStar1_reset;
        QPushButton *pushButton_rotateStar1_done;
        QWidget *tab_getStar2;
        QLabel *label_getStar2_tipMsg;
        QPushButton *pushButton_getStar2_reset;
        QWidget *tab_rotateStar2;
        QLabel *label_rotateStar2_tipMsg;
        QLabel *label_rotateStar2_ask;
        QPushButton *pushButton_rotateStar2_reset;
        QPushButton *pushButton_rotateStar2_done;
        QWidget *tab_getStar3;
        QLabel *label_getStar3_tipMsg;
        QPushButton *pushButton_getStar3_reset;
        QWidget *tab_validateCenter;
        QLabel *label_validateCenter_tipMsg;
        QLabel *label_validateCenter_ask;
        QPushButton *pushButton_validateCenter_reset;
        QPushButton *pushButton_validateCenter_done;
        QWidget *tab_getEptPolaris;
        QLabel *label_getEptPolaris_tipMsg;
        QLabel *label_getEptPolaris_ask;
        QPushButton *pushButton_getEptPolaris_done;
        QWidget *tab_movePolaris;
        QLabel *label_movePolaris_tipMsg;
        QLabel *label_movePolaris_ask;
        QPushButton *pushButton_movePolaris_done;
        QWidget *tab_getCurPolaris;
        QLabel *label_getCurPolaris_tipMsg;
        QLabel *label_getCurPolaris_ask;
        QPushButton *pushButton_getCurPolaris_done;
        QWidget *tab_calcPole;
        QLabel *label_calcPole_tipMsg;
        QWidget *tab_finetunePole;
        QLabel *label_finetunePole_tipMsg;
        QPushButton *pushButton_finetunePole_reset;
        QPushButton *pushButton_finetunePole_done;

        AboutDialog *aboutDialog;
        AstroRefractionDialog *astroRefDialog;
        PoleTrackingDialog *poleTrackingDialog;
        FavoriteDialog *favoriteDialog;

        CaptureThread *captureFrameThread;

        QTimer *updateImgTimer;
        QTimer *increaseAngleTimer;
        QTimer *graphicsEffectTimer;
        QTimer *updateFPSTimer;

        QMediaPlayer *Music;//初始化音乐
        QAudioOutput *audioOutput;//音频输出

        QGraphicsDropShadowEffect *dropShowEffect_confirm;
        QGraphicsDropShadowEffect *dropShowEffect_rough;
        QTranslator *translator;

        QPoint templateImgCenter;   //center point of template image in current zoom image
        QPointF templateImgCenter_originalImg;  //center point of template image in original image
        QImage *northTemplateImg;
        QImage *southTemplateImg;

        QImage capImg;
        QImage roiEnlargeImg;

        QString lang;
        QString region;
        float scaledFactor;

        int stepIndex;  //current step

        int rotateAngle;

        double starPos1_x;
        double starPos1_y;
        double starPos2_x;
        double starPos2_y;
        double starPos3_x;
        double starPos3_y;

        double tempCenterX;
        double tempCenterY;
        int tempRadius;

        double posX_starN;    //current polaris position in image
        double posY_starN;

        double posX_starA_mask;   //star position in template image
        double posY_starA_mask;
        double posX_starB_mask;
        double posY_starB_mask;
        double posX_pole_mask;
        double posY_pole_mask;
        double angleA_mask;
        double angleB_mask;

        double originalStarAPosX; // 记录最初的A B区域位置，用于旋转追踪中计算旋转后坐标
        double originalStarAPosY;
        double originalStarBPosX;
        double originalStarBPosY;

        qreal devPixRatio;

};

#endif // MAINWINDOW_H
