#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "wangluo.h"
#include "canshupeizhi.h"
#include "xitongshezhi.h"
#include <QMainWindow>
#include <QLabel>
#include <QFile>
#include <QPushButton>
#include <QFrame>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QDebug>
#include <QMouseEvent>
#include "net_thread.h"
#include <QtSerialPort/QSerialPort>
#include <QAbstractItemView>//下拉框滑动条
#include <QStyleFactory>//设置将linux风格改为windows
#include <QSharedMemory>
#include "QHostInfo"
#include <QTableWidget>
#include <QTableWidgetItem>
#include "ui_mainwindow.h"
#include "ui_wangluo.h"
#include <QFileDialog>
#include <QPainter>
#include <QTextCodec>//中文乱码
#include <QTime>
#include <QThread>
#include <QSharedMemory>
#include <QBuffer>
#include <QProcess>
#include <uart.h>
#include <uart1.h>
#include <mcu_arm1.h>
#include <QTimer>
#include "MCU_ARM.h"
#include "QHostInfo"
#include "QNetworkConfigurationManager"
#include <QTableView>
#include <QHeaderView>
#include <QStandardItemModel>
#include <QProgressDialog>
#include <QProgressBar>
#include <QUdpSocket>
#include "modulewifi.h"
#include "modulesystime.h"
#include "module4g.h"
#include "ledcontrol.h"
#include "mainpage_a_v.h"
#include "mainpage_power.h"
#include "mainpage_quality.h"
#include "mainpage_data.h"
#include "mainpage_temp.h"
#include "mainpage_jfparameter.h"
#include "mainpage_rxy.h"
#include "modulepostdata.h"
#include "QsLog/include/QsLog.h"
#include <QElapsedTimer>

#define LINUX 1
#define BIT(N)   (1<<N)

extern bool cspz_flag,wlpz_flag,xtpz_flag,alarm_start;
extern bool kaiji_flag_ok;
extern bool KeyBoard_Code,KeyBoard_ABC_Code,keyBoard_flag;
extern int where_page;
extern wangluo *wangluo_thread;
extern canshupeizhi *canshupeizhi_thread;
extern xitongshezhi *xitongshezhi_thread;
extern ModuleWifi * wifi;
extern QString Wireless;
extern uint8_t error_record_int;//错误文件日期
extern QsLogging::Logger &logger;

extern QString wireless_name[60];
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow :  public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    QProgressBar *pProgressBar;

    bool eventFilter(QObject *watch, QEvent *evn);  //触摸事件监听函数
    void main_page(int a);//主界面显示页数

    void label_1_show(int a);//有功电量页面显示
    void label_3_show(int a);
    void label_4_show(int a);
    void label_5_show(int a);
    void label_6_show(int a);
    void label_7_show(int a);
    void label_8_show(int a);
    void label_9_show(int a);
    void fun_4G_start();//4G模块加载
    void dispFan(bool ctrl);
    void dispOverTemp(bool ctrl);
    void dispTrip(bool ctrl);
    void dispDoor(bool ctrl);
    void screenBright(bool ctrl);

    void Lowpower_state();

private slots:

    void onBuzzerClose();
    void onBuzzerCtrl(bool state);
    void timerTimeout();
    void timerTimeout3();//开机进度条
    void Sys_time(void);
    void timerTimeout_share();
    void Lowpower_mode(void);//低功耗模式息屏显示
    void usb_file_selcet(void);//usb文件选择
    void Thermal_imager_Alarm_fun(void);//热像仪报警函数
    void Thermal_imager_Alarm_fun1(void);//热像仪报警函数

    void WIFI_tubiao_disconnect();//WIFI图标断网
    void WIFI_tubiao_connect();//WIFI图标连网
    void onRtcUpdate(bool);
    void onWifiTuBiaoStateUpdate(bool);
    void onGgTuBiaoStateUpdate(bool);
    void onAlarmCheck(uint32_t);
    void onSelfTestCheck(uint32_t);
    void onLanTuBiaoStateUpdate(bool);

    void main_set_back_color();
    void on_pushButton_zhujiemian_clicked();//主界面按钮槽函数
    void on_pushButton_wangluoxinxi_clicked();//网络配置按钮槽函数
    void on_pushButton_canshushezhi_clicked();//参数修改按钮槽函数
    void on_pushButton_xitongshezhi_clicked();//系统设置按钮槽函数

    void Button_usb_file_clicked();//系统设置按钮槽函数
    void label_0_1_clicked();//点击切换页面槽函数
    void label_0_3_clicked();
    void label_0_4_clicked();
    void label_0_5_clicked();
    void label_0_6_clicked();
    void label_cspz_0_2_clicked();//局放页面跳转
    void label_cspz_0_4_clicked();//空负载损耗页面跳转
    void label_0_9_clicked();
    void button_buzzer_Clicked();

    void  Pop_alarm_door_Clicked();//门触点
    void  Pop_alarm_over_temperature_Clicked();//超温
    void  Pop_alarm_trip_Clicked();//跳闸
    void  Pop_alarm_chaosheng_Clicked();//超声波
    void  Pop_alarm_tev_Clicked();//tev
    void  Pop_alarm_communicate_Clicked();//通信故障
    void  Pop_alarm_Wireless_Temperature_Clicked();//无线测温故障
    void  Pop_alarm_rxy_disconnect_Clicked();//热像仪掉线
    void  Pop_alarm_fan_Clicked();//风机故障
    void  Pop_alarm_current_A_Clicked();//电流互感器A相序反
    void  Pop_alarm_current_B_Clicked();
    void  Pop_alarm_current_C_Clicked();
    void  Pop_alarm_voltage_A_Clicked();//电压互感器A相断路
    void  Pop_alarm_temp_A_Clicked();//温控线异常
    void  Pop_alarm_temp_B_Clicked();
    void  Pop_alarm_temp_C_Clicked();
    void  Pop_alarm_temp_T_Clicked();

    void first_statr_wifi();//开机连WIFI
    void Mainwindows_Init();//初始化界面配置
    void Mainwindows_File_Init();//初始化文件系统
    void Mainwindows_QTime_Init();//初始化定时器
    void Mainwindows_USBFile_Init();//初始化U盘读取
    void Mainwindows_Title_Init();//初始化U盘读取
    void Mainwindows_rxy_Init();//初始化热像仪
    void Mainwindows_temperature_Init();//初始化ABC相温度读取
    void Mainwindows_excel_Init();//初始化EXCEL表格（导入变压器参数）
    void OnSilencingKeyClick();
    void onDispByqAlarm(bool);
    void onPageThreeSend();
    void onPageFiveSend();
    void onDispWirelessAlarm(bool);
    void onCountSend(int);
    void onDispJuFangAlarm(bool);
    void onDispRxyAlarm(bool,bool);
    void onPageEightSend();
public:

    Ui::MainWindow *ui;

    bool disconncet_current=false;//电流互感器未选配
    bool disconncet_voltage=false;
    bool disconncet_jufang=false;
    bool disconncet_wuxian=false;
    bool disconncet_rxy1=false;
    bool disconncet_rxy2=false;

    QTimer* timer;//三项温度定时刷新
    QTimer* timer_jindutiao;

    QString sys_time;
    QString error_record;//错误文件日期

    int mian_page=1;

    bool alarm_back_flag=false;

    bool alarm_flag1=false,alarm_flag2=false,alarm_flag3=false,alarm_flag4=false,alarm_flag5=false,alarm_flag6=false,alarm_flag7=false,alarm_flag8=false,
        alarm_flag9=false,alarm_flag12=false,alarm_flag13=false,alarm_flag14=false,alarm_flag15=false,alarm_flag16=false,alarm_flag17=false,alarm_flag18=false,alarm_flag19=false;//弹窗报警状态
    bool alarm_battery_flag = false;

    int usb_file_first=1;//usb插入变量

    bool state_4G,net_ok;

    QLabel *rxy_alarm_picture;//热像仪报警图片
    QLabel *rxy_alarm_picture1;//热像仪报警图片
    int rxy_count=0;//热像仪变量计数

    QLabel *kaiji;
    QLabel *label_lowpower_mode_back;

    QLabel *label_A_temperature;
    QLabel *label_B_temperature;
    QLabel *label_C_temperature;
    QLabel *label_T_temperature;

    QLabel *label_sys_time;

    QLabel *label_0_1;//左右滑动切换页面label（有功电量）
    QLabel *label_0_3;
    QLabel *label_0_4;
    QLabel *label_0_5;
    QLabel *label_0_6;
    QLabel *label_0_7;
    QLabel *label_0_8;
    QLabel *label_0_9;

    QLabel *label_usb_file_title;
    QLabel *label_usb_file_back;
    QComboBox *combobox_usb_file;
    QPushButton *button_usb_file;

    QPushButton *button_buzzer;//消音按钮

    /*弹窗报警*/
    QLabel *label_alarm_back;//弹窗背景
    QPushButton *Pop_alarm_door;//门触点
    QPushButton *Pop_alarm_over_temperature;//超温
    QPushButton *Pop_alarm_trip;//跳闸
    QPushButton *Pop_alarm_chaosheng;//超声波
    QPushButton *Pop_alarm_tev;//tev
    QPushButton *Pop_alarm_communicate;//通信故障
    QPushButton *Pop_alarm_Wireless_Temperature;//无线测温故障
    QPushButton *Pop_alarm_rxy_disconnect;//热像仪掉线
    QPushButton *Pop_alarm_fan;//风机故障
    QPushButton *Pop_alarm_current_A;//电流互感器A相序反
    QPushButton *Pop_alarm_current_B;
    QPushButton *Pop_alarm_current_C;
    QPushButton *Pop_alarm_voltage_A;//电压互感器A相断路
    QPushButton *Pop_alarm_temp_A;//温控线异常
    QPushButton *Pop_alarm_temp_B;
    QPushButton *Pop_alarm_temp_C;
    QPushButton *Pop_alarm_temp_T;

    QLabel *label_cspz_0_2;
    QLabel *label_cspz_0_4;

    /* 创建表格视图 */
    QTableView *tableView;
    /* 创建excel表数据模型 */
    QStandardItemModel* model = new QStandardItemModel();
    bool Pop_alarm_T_err_flag;
private:
    QStandardItem *chan1 = nullptr;
    QStandardItem *chan2 = nullptr;
    QStandardItem *chan3 = nullptr;
    QStandardItem *chan4 = nullptr;
    QStandardItem *chan5 = nullptr;
    QStandardItem *chan6 = nullptr;
    QStandardItem *chan7 = nullptr;
    QStandardItem *chan8 = nullptr;
    QStandardItem *chan9 = nullptr;
    QStandardItem *chan10 = nullptr;
    QStandardItem *chan11 = nullptr;
    QStandardItem *chan12 = nullptr;
    QSharedMemory *sharememery_test;
    int share_num;

    ModuleSysTime * systime;
    QThread threadSystime;
    module4g *CCID_check;
    QThread thread4g;
    QThread threadWifi;
    modulePostData *postDataMod;
    QThread threadPostData;

    void dispAlarmBackground();
    void dispTemperature();
    void dispTempCtrlLine();
    void dispBuzzer();
    void dispMainPages();
    void dispPopWindwows();

    //变压器总电压，总电流，功率因数
    float A_vol2, B_vol3, C_vol3;
    float A_Current3, B_Current3, C_Current2;
    float A_PowerFactor3, B_PowerFactor3, C_PowerFactor2;
    int countrcv = 0;    
    bool screen_bflag= false;

    QWidget *widget_page = nullptr;
    QWidget *widget = nullptr;
    mainpage_A_V * mP_A_V;
    mainpage_Power * mP_Power;
    mainpage_Quality *mP_Quality;
    mainpage_Data *mP_Data;
    mainpage_Temp *mP_Temp;
    mainpage_JfParameter *mP_JfParameter;
    mainpage_Rxy *mP_Rxy;
signals:
    void sigWifiAutoConnect(QString name, QString passwd);
    void sigBuzzerCtrl(bool state);
    void sigPageOneDataUpdate(float,float,float);
    void sigPageOneDataLabelUpdate();
    void sigPageTwoDataUpdate(float,float,float);
    void sigPageThreeDataUpdate();
    void sigPageFourDataUpdate();
    void sigPageFiveDataUpdate();
    void sigWirelessStateCheck();
    void sigPageSevenDataUpdate();
    void sigJuFangStateCheck();
    void sigPageEightDataUpdate();
    void sigRxyLabelSet();
    void sigRxyButtonShow();
    void sigPostDigData();
};

#endif // MAINWINDOW_H
