#include "mainwidget.h"
#include "ui_mainwidget.h"

#ifdef Q_OS_WIN
#include <Windows.h>
#endif
MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget),
    m_pPatternSelectWi(NULL),
    m_pParameterSetDlg(NULL),
    m_pPatternManageWi(NULL),
    m_pSensorInputWi(NULL),
    m_pControlActionWi(NULL),
    m_pColorOrderSetWi(NULL),
    m_pNeedleBarSetWi(NULL),
    m_pMainWidgetFunction(NULL),
    m_pSheetWi(NULL),
    m_pSetWorkAreaWi(NULL),
    m_initflag(0),
    m_timoutflag(0),
    m_pTimer(NULL),
    m_pConTimer(NULL),
    m_conFlag(0),
    m_linkSta(0)
{
    ui->setupUi(this);

    setWindowFlags (Qt::Widget |
                    Qt::Window |
                    Qt::FramelessWindowHint  |  // 无边框窗口
                    //    Qt::WindowStaysOnTopHint |  // 顶层窗口
                    Qt::Widget);

    setFocusPolicy(Qt::NoFocus);

#if(0)
    //版本显示
    QString verStr;
    verStr.sprintf("XPlatForm-RP-HMI-L1910-V%d%02d%02d",
                   VER_CODE_Y,
                   VER_CODE_M,
                   VER_CODE_D);

    ui->labelHMIVersion->setText(tr("Version:") + " " + verStr);//版本:
#endif

    m_mousePressX = 0;
    m_mousePressY = 0;
    m_mouseReleaseX = 0;
    m_mouseReleaseY = 0;
    g_mainWidgetPos.setX(0);
    g_mainWidgetPos.setY(0);

    this->move(g_mainWidgetPos.x(), g_mainWidgetPos.y());
    initialize();

    ui->lcdNumberSpeed->display("1200");
    //ui->labelParaType2->setWordWrap(true);
}

MainWidget::~MainWidget()
{
    if(m_pTimer != NULL)
    {
        delete m_pTimer;
    }

    if(m_pConTimer != NULL)
    {
        delete m_pConTimer;
    }

    if(m_pMinTimer != NULL)
    {
        delete m_pMinTimer;
    }

    if(m_pWifiConTimer != NULL)
    {
        delete m_pWifiConTimer;
    }

    if(m_pRefreshVer != NULL)
    {
        delete m_pRefreshVer;
    }
    
    if(m_pPatternSelectWi != NULL)
    {
        delete m_pPatternSelectWi;
    }

    if(m_pParameterSetDlg != NULL)
    {
        delete m_pParameterSetDlg;
    }

    if(m_pSensorInputWi != NULL)
    {
        delete m_pSensorInputWi;
    }

    if(m_pSetWorkAreaWi != NULL)
    {
        delete m_pSetWorkAreaWi;
    }

    if(m_pControlActionWi != NULL)
    {
        delete m_pControlActionWi;
    }

    if(m_pColorOrderSetWi != NULL)
    {
        delete m_pColorOrderSetWi;
    }

    if(m_pNeedleBarSetWi != NULL)
    {
        delete m_pNeedleBarSetWi;
    }

    if(m_pMainWidgetFunction != NULL)
    {
        delete m_pMainWidgetFunction;
    }

    if(m_pSheetWi != NULL)
    {
        delete m_pSheetWi;
    }

    delete ui;
}

void MainWidget::initialize()
{
    memset(&m_expara,0,sizeof(FileExecPara));
    m_setControlStyle.setUiName(this->objectName());

    ui->frameMateEmb->setVisible(false);//匹绣显示区域隐藏
    ui->frameOpenLineEmb->setVisible(false);//匹绣显示区域隐藏

    ui->labelPatternPreView->setVisible(false);//预览模式显示图形的label初始化时隐藏
    ui->labelNoseHead->setVisible(false);//隐藏

    hideMenuFrame();
    //主界面按钮选中
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);

    ui->frameForwardBack->setVisible(false);
    if(g_emMacType == QUIMACHINE_EMB)
    {
         ui->frameShortcutBtn->setVisible(false);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
          ui->frameShortcutBtn->setVisible(true);
    }

    setZoomMoveBtnVisible(false);
    clearFileInfo();//清除文件信息

    ui->labelWorkState->setVisible(false); //正常工作/模拟工作
    ui->labelEnableWorkState->setVisible(false);//允许工作/禁止工作

    memset(&m_mcStatus,0,sizeof(MCStatus));
    //定时器
    m_pTimer = new QTimer(this);
    m_pTimer->setInterval(1000);    // 设置定时间隔1秒
    connect(m_pTimer, SIGNAL(timeout()), this, SLOT(onOneSecondTimer()));

    //定时器
    m_pConTimer = new QTimer(this);
    m_pConTimer->setInterval(5000);    // 设置定时间隔5秒
    connect(m_pConTimer, SIGNAL(timeout()), this, SLOT(onFiveSecondTimer()));

    //定时器
    m_pWifiConTimer = new QTimer(this);
    m_pWifiConTimer->setInterval(100000);    // 设置定时间隔10分钟
    connect(m_pWifiConTimer, SIGNAL(timeout()), this, SLOT(onTenMiniteTimer()));

    //测试花样刷新的定时器
    m_pRefreshPatternTimer = new QTimer(this);
    m_pRefreshPatternTimer->setInterval(30);    // 设置时间
    connect(m_pRefreshPatternTimer, SIGNAL(timeout()), this, SLOT(onRefreshPatternTimer()));

    //一分钟定时任务,记录当前系统时间,用于上电时计算关机时间
    m_pMinTimer = new QTimer(this);
    m_pMinTimer->setInterval(60000);    // 设置定时间隔60秒
    connect(m_pMinTimer, SIGNAL(timeout()), this, SLOT(onOneMinTimer()));

    m_pRefreshVer = new QTimer(this);
    m_pRefreshVer->setInterval(1000);
    connect(m_pRefreshVer, SIGNAL(timeout()), this, SLOT(onRefreshVer()));
    m_pRefreshVer->start();

    m_borderEmb = 0;
    m_curFilePath.clear();
    m_preFilePath.clear();
    m_imageZoom = 0;//花样图片缩放值
    m_imageMoveX = 0;//花样图片平移值X
    m_imageMoveY = 0;//花样图片平移值Y
    m_curDatIdx = 0;//当前针数索引
    m_curRpm = -1;
    m_curColorIdx = 0;//当前色序
    m_workStatus = 0;
    m_forwardBackNeedleIdx = 0;//前进回退时的针数索引
    m_forwardBackColorIdx = 0;//前进回退时的颜色索引
    m_ifHMIDecrypt = 1;
    m_connectMode = USE_TCP_COMM;
    m_workNoseHead = 0;// 当前工作机头(从主控中读到的/界面下方显示的当前机头)
    m_curPages = 1; // 当前页
    memset(&m_fileHead,0,sizeof(DataFileHead));
    m_itemPerPage = 28;//快捷功能和辅助功能界面各28个按钮

    m_speedLevel = 2;//速度默认等于2
    m_showColorIdxBegin = 0;
    m_errorCode = 0;//错误代码

    m_stepDrive = 0;
    m_stepDrive = g_pSettings->readFromInHMIiFile("HMI/stepDrive").toInt();//步进驱动

    m_towelHeightTable.resize(TOWELHIGHBUF);
    memset(m_towelHeightTable.data(),0,m_towelHeightTable.length());

    //开位线节点列表
    m_nodeIdx = 0;
    m_nodeList.clear();
    for(int i = 0; i < NODENUMBER; i++)
    {
        int nodeX = g_pSettings->readFromIniFile("OpenLine/nodeX"+QString::number(i+1)).toInt();
        int nodeY = g_pSettings->readFromIniFile("OpenLine/nodeY"+QString::number(i+1)).toInt();

        OpenLineNode node;
        node.nodeX = nodeX;
        node.nodeY = nodeY;

        m_nodeList.append(node);
    }

    ui->labelCoorXValue->setText("0");
    ui->labelCoorYValue->setText("0");
    ui->labelCurNodeValue->setText("1");

    int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾
    int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有毛巾
    if(g_emMacType == MACHINE_EMB)
    {
        if(towel ==1 || coil == 1)
        {
            ui->labelNoseHead->setVisible(true);//绣花有毛巾的时候显示
        }
    }
    else if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->labelNoseHead->setVisible(true);
        ui->labelNoseHead->setText(tr("Production statistics:")+tr(" ")+ tr("cm"));//产量统计:单位cm
    }
}

//设置阿拉伯语时控件对齐方式
void MainWidget::initArabControlPos()
{
    int language = g_pSettings->readFromInHMIiFile("HMI/language").toInt();
    if(language != arabic)
    {
        return;
    }

    //标题
    ui->labelTitle->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    //花样显示区域
    ui->labelFilename->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    //ui->labelX->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelY->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelW->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelH->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelC->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelN->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    //开位线绣显示区域
    ui->labelOpenLineShow->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelCoorXYValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelCurNode->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    //ui->labelCoorX->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelCoorY->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    //下方状态栏
    ui->labelState->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelNoseHead->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    ui->labelAssistPage->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelShortCutPage->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
}

//初始化窗体
void MainWidget::initAllWindows(s16 ifHMIDecrypt,s16 connectMode)
{
    m_connectMode = connectMode;
    m_ifHMIDecrypt = ifHMIDecrypt;

    m_gradientFlag = g_pSettings->readFromInHMIiFile("HMI/gradient").toInt();  //是否使用3D显示模式,0:3D,!0=2D

    if (m_initflag <= 1)
    {
        connect(g_pCurEmbData,SIGNAL(siDrawNeedleIdx(int)),this,SLOT(slotChangeProgressBar(int)));
        m_initflag = 2;
        sendInitString(QString(tr("Init windows...")));//初始化窗体...
        initControl();//初始化界面控件
        initQuickFunBtn();//初始化快捷功能中的快捷按钮
        initAssisitBtn();//初始化辅助功能中的辅助功能按钮
        initPatternSetBtn();//初始化花样设置功能中的功能按钮
        initParaSetBtn();//初始化参数设置功能中的功能按钮
        initEmbFunctionBtn();//初始化刺绣功能中的功能按钮

        m_pMainWidgetFunction = new MainWidgetFunction();//主界面功能函数对象
        m_pMainWidgetFunction->setErrorCodeAndStateList(m_errorCodeAndStateItemList);
        connect(m_pMainWidgetFunction, SIGNAL(siSetButtonUserLogo(int)), this, SLOT(slotSetButtonRootLogo(int)));
        connect(m_pMainWidgetFunction, SIGNAL(siClearPatternBreakLineNum()),this,SLOT(slotClearPatternBreakLineNum()));
        connect(m_pMainWidgetFunction, SIGNAL(siDebugState()),this,SLOT(slotDebugState())); //调试模式改变字体颜色
        connect(m_pMainWidgetFunction, SIGNAL(siCloseRootPara()),this,SLOT(slotCloseRootPara()));
        connect(m_pMainWidgetFunction, SIGNAL(siClearPattern()), this, SLOT(slotIfFileExist()));//花样总清后，清除当前所选花版路径//两个信号用一个槽
        connect(m_pMainWidgetFunction, SIGNAL(siClearPatternFcg()), this, SLOT(slotClearPatternFcg()));//花样fcg总清后，清除当前所选花版路径
        connect(m_pMainWidgetFunction,SIGNAL(siShowPercentage(int)),this,SLOT(slotShowPercentage(int)));
        connect(m_pMainWidgetFunction,SIGNAL(siWifiState(bool)),this,SLOT(slotRefreshWifiIcon(bool)));
        connect(this,SIGNAL(siCounterPrompt(s16)),m_pMainWidgetFunction,SLOT(slotCounterPrompt(s16)));
        //connect(m_pMainWidgetFunction, SIGNAL(siRecieveLotDat()),this,SLOT(slotLotDat()));//测试物联网用

        m_pPatternSelectWi = new PatternSelectWidget(this);
        m_pPatternSelectWi->hide();
        connect(m_pPatternSelectWi, SIGNAL(siSelectPattern(QString,s16)), this, SLOT(slotShowPatternPara(QString,s16)));

        m_pPatternManageWi = new PatternManageWidget(this);
        connect(m_pPatternManageWi, SIGNAL(siDeletePattern()), this, SLOT(slotIfFileExist()));
        connect(m_pPatternManageWi, SIGNAL(siReplacePattrn(QString)), this, SLOT(slotReplacePattrn(QString)));

        m_pColorOrderSetWi = new ColorOrderSetWidget(this);
        connect(m_pMainWidgetFunction,SIGNAL(siHeadBuf(u8*)),m_pColorOrderSetWi,SLOT(slotResetHeadBuf(u8*)));//重置隔头绣数据

        m_pNeedleBarSetWi = new NeedleBarSetWidget(this);
        connect(m_pNeedleBarSetWi,SIGNAL(siNeedlebarSet()),this,SLOT(slotRefreshPattern()));//针杆颜色设置后重新刷图，否则图形颜色不对
        connect(m_pNeedleBarSetWi,SIGNAL(siNeedlebarSet()),m_pColorOrderSetWi,SLOT(slotSetEmbDatNeedleTable()));//针杆颜色设置后重新设置，否则图形颜色不对

        m_pParameterSetDlg->hide();
        connect(m_pParameterSetDlg,SIGNAL(siUserLogin(s16)),m_pMainWidgetFunction,SLOT(slotUserLogin(s16)));
        connect(m_pParameterSetDlg,SIGNAL(siFrameAngleSet()),this,SLOT(slotShowFrameAngleWi()));
        connect(m_pParameterSetDlg,SIGNAL(siEmbWorkArea()),this,SLOT(slotEmbWorkArea()));//设置平绣可工作区域
        connect(m_pParameterSetDlg,SIGNAL(siChenWorkArea()),this,SLOT(slotChenWorkArea()));//设置毛巾可工作区域
        connect(m_pParameterSetDlg,SIGNAL(siCoilWorkArea()),this,SLOT(slotCoilWorkArea()));//设置缠绕可工作区域
        connect(m_pParameterSetDlg,SIGNAL(siTraverseSet(s16,s16)),m_pMainWidgetFunction,SLOT(slotCalMachineProgress(s16,s16)));//设置缠绕可工作区域

        connect(g_pMachine, SIGNAL(siParaChange(int, int)),
                m_pParameterSetDlg, SLOT(paraChange(int, int)));// 参数改变
        connect(g_pMachine, SIGNAL(siEXBParaChange()),
                m_pParameterSetDlg, SLOT(EXBParaChange()));// 外围板参数改变
        connect(g_pMachine, SIGNAL(siDataFilePos(DataFilePos)),
                this, SLOT(slotResetStartPos(DataFilePos)));// 起绣点改变

        connect(m_pParameterSetDlg,SIGNAL(siHMIDecrypt(QString)),m_pMainWidgetFunction,SLOT(slotHMIDecrypt(QString)));
        connect(m_pParameterSetDlg,SIGNAL(siAutoSetSoftLimit()),m_pMainWidgetFunction,SLOT(slotAutoSetSoftLimit()));
        connect(m_pParameterSetDlg,SIGNAL(siEMBSpindleTest()),m_pMainWidgetFunction,SLOT(slotEMBSpindleTest()));
        connect(m_pParameterSetDlg,SIGNAL(siChenSpindleTest()),m_pMainWidgetFunction,SLOT(slotChenSpindleTest()));
        connect(m_pParameterSetDlg,SIGNAL(siFootTest()),m_pMainWidgetFunction,SLOT(slotFootTest()));
        connect(m_pParameterSetDlg,SIGNAL(siEcdWidthTest()),m_pMainWidgetFunction,SLOT(slotEcdWidthTest()));

        connect(m_pParameterSetDlg,SIGNAL(siFrameParaImport()),m_pMainWidgetFunction,SLOT(slotFrameParaImport()));//动框参数导入
        connect(m_pParameterSetDlg,SIGNAL(siFrameParaExport()),m_pMainWidgetFunction,SLOT(slotFrameParaExport()));//动框参数导出

        connect(m_pParameterSetDlg,SIGNAL(siHeadBoardBusDetect()),m_pMainWidgetFunction,SLOT(slotHeadBoardBusDetect()));
        connect(m_pParameterSetDlg,SIGNAL(siHookTest()),m_pMainWidgetFunction,SLOT(slotHookTest()));
        connect(m_pParameterSetDlg,SIGNAL(siEXBBoardUpgrade(u8,u8,u8)),this,SLOT(slotEXBUpgrade(u8,u8,u8)));
        connect(m_pParameterSetDlg,SIGNAL(siExit()),m_pMainWidgetFunction,SLOT(slotExitApp()));//超级用户退出程序
        //connect(m_pParameterSetDlg,SIGNAL(siVerRecovery()),m_pMainWidgetFunction,SLOT(slotVerRecovery()));//超级用户版本恢复
        connect(m_pParameterSetDlg,SIGNAL(siChangePassword()),m_pMainWidgetFunction,SLOT(slotChangePassword()));//超级用户修改一级密码
        connect(m_pParameterSetDlg,SIGNAL(siDeleteIni()),m_pMainWidgetFunction,SLOT(slotDeleteIni()));//删除执行目录下的config.ini文件
        connect(m_pParameterSetDlg,SIGNAL(siImportCSV()),m_pMainWidgetFunction,SLOT(slotImportCSV()));
        connect(m_pParameterSetDlg,SIGNAL(siDeleteCSV()),m_pMainWidgetFunction,SLOT(slotDeleteCSV()));
        connect(m_pParameterSetDlg,SIGNAL(siResetCSV()),m_pMainWidgetFunction,SLOT(slotResetCSV()));

        connect(m_pParameterSetDlg,SIGNAL(siPatternClear()),m_pMainWidgetFunction,SLOT(slotPatternClear()));//超级用户花样总清
        connect(m_pParameterSetDlg,SIGNAL(siPatternFcgClear()),m_pMainWidgetFunction,SLOT(slotPatternFcgClear()));//超级用户删除花样fcg
        connect(m_pParameterSetDlg,SIGNAL(siPatternFcgClearFileid()),m_pMainWidgetFunction,SLOT(slotPatternFcgClearFileid()));//超级用户删除花样fcg影响fileid的数据

        connect(m_pMainWidgetFunction,SIGNAL(siAfterDeleteFileid()),this,SLOT(slotClearPatternFcg()));//超级用户删除花样fcg影响fileid的数据之后

        connect(m_pParameterSetDlg,SIGNAL(siDebugMode()),m_pMainWidgetFunction,SLOT(slotDebugMode()));//超级用户界面调试模式
        connect(m_pParameterSetDlg,SIGNAL(siLiftMotor()),m_pMainWidgetFunction,SLOT(slotLiftMotor()));//提升电机控制
        connect(m_pParameterSetDlg,SIGNAL(siElasticCtrl()),m_pMainWidgetFunction,SLOT(slotLElasticCtrl()));//松紧线控制
        connect(m_pParameterSetDlg,SIGNAL(siChenilleColorDebug()),m_pMainWidgetFunction,SLOT(slotChenilleColorDebug()));//毛巾换色调试显示当前针杆
        connect(m_pParameterSetDlg,SIGNAL(siHeadParaImport(QString,int)),m_pMainWidgetFunction,SLOT(slotHeadParaImport(QString,int)));
        connect(m_pParameterSetDlg,SIGNAL(siHeadParaExport(int)),m_pMainWidgetFunction,SLOT(slotHeadParaExport(int)));
        connect(m_pMainWidgetFunction,SIGNAL(siHeadParaImportFinish(int)),m_pParameterSetDlg,SLOT(slotRefreshHeadPara(int)));

        m_pPatternManageWi->hide();

        m_pColorOrderSetWi->hide();
        connect(m_pColorOrderSetWi,SIGNAL(siChangeColorTable(int,int)),this,SLOT(slotChangeColorTable(int,int)));
        connect(m_pColorOrderSetWi,SIGNAL(siChangeTowelHighTable(int,int)),this,SLOT(slotChangeTowelHighTable(int,int)));
        connect(m_pColorOrderSetWi,SIGNAL(siBackHome(s16,s16)),this,SLOT(slotColorOrderChange(s16,s16)));
        connect(m_pColorOrderSetWi,SIGNAL(siTowelHighBackHome()),this,SLOT(slotTowelHighChange()));
        connect(m_pColorOrderSetWi,SIGNAL(siCancelChangeColor(QByteArray)),this,SLOT(slotReSetEmbData(QByteArray)));
        connect(m_pColorOrderSetWi,SIGNAL(siCancelChangeTowelHigh(QByteArray)),this,SLOT(slotReSetTowelHigh(QByteArray)));
        connect(m_pColorOrderSetWi,SIGNAL(siHeadEmb()),this,SLOT(slotHeadEmb()));//隔头绣
        connect(m_pColorOrderSetWi,SIGNAL(siSetHeadEmbBtnEnable(bool)),this,SLOT(slotSetHeadEmbBtnEnable(bool)));//设置隔头绣按钮是否可按
        //connect(this,SIGNAL(siNeedleNum(int)),m_pMainWidgetFunction,SLOT(slotChenilleColorDebug(int)));//毛巾换色调试
        m_pSheetWi = new SheetWidget(this);
        m_pSheetWi->hide();
        connect(g_pMachine, SIGNAL(siParaChange(int, int)),
                m_pSheetWi, SLOT(slotFrameAngleParaChange(int, int)));// 动框角度参数改变

        m_pSetWorkAreaWi = new SetWorkArea(this);
        m_pSetWorkAreaWi->hide();

        m_pNeedleBarSetWi->hide();
        m_pSensorInputWi->hide();
        m_pControlActionWi->hide();
        connect(this, SIGNAL(siSpeed(int)),m_pControlActionWi,SLOT(slotSpeed(int))); //手动换挡
        connect(m_pControlActionWi, SIGNAL(siTowelMZero(s16,s16)),m_pMainWidgetFunction,SLOT(slotCalMachineProgress(s16,s16)));
        connect(m_pControlActionWi, SIGNAL(siTowelRZero(s16,s16)),m_pMainWidgetFunction,SLOT(slotCalMachineProgress(s16,s16)));
        connect(m_pControlActionWi, SIGNAL(siCoilCFZero(s16,s16)),m_pMainWidgetFunction,SLOT(slotCalMachineProgress(s16,s16)));
        connect(m_pControlActionWi, SIGNAL(siCoilCZZero(s16,s16)),m_pMainWidgetFunction,SLOT(slotCalMachineProgress(s16,s16)));

        QTimer timer;
        connect(&timer, SIGNAL(timeout()), this, SLOT(slotWaitTimout()));
        timer.start(1000);

        m_timoutflag = 0;
        do
        {
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }while(m_timoutflag == 0);
        timer.stop();

        sendInitString(QString(tr("Init communication...")));//初始化通讯...

        connect(g_pMachine, SIGNAL(siSensorEnBitmap(SensorsBitmap)),
                m_pSensorInputWi, SLOT(slotRefSensorBitmap(SensorsBitmap)));//传感信号有效位图更新信号
        connect(g_pMachine, SIGNAL(siSensorChange(SensorsBitmap)),
                m_pSensorInputWi , SLOT(slotRefSensorsDat(SensorsBitmap)));//传感信号更新

        //显示报错信息
        connect(g_pMachine, SIGNAL(siStatusChange(int)), this, SLOT(slotMachineStatus(int)));

        // 等待通讯结束....
        timer.start(1000);
        m_timoutflag = 0;
        do
        {
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }while(m_timoutflag == 0);
        timer.stop();

        refConnectUi(-1);//刷新连接

        m_pTimer->start();//1秒检查一次连接状态
        m_pConTimer->start();//5秒检查一次连接是否断开，若不需要检测与下位机的心跳包时注释掉此行代码
        //m_pMinTimer->start();//1分钟记录一次当前系统时间
        //m_pMainWidgetFunction->setShutDownTime();//开启计算关机时间

        //窗体初始化完成后自动加载文件并显示、发送
        m_curFilePath = g_pSettings->readFromInHMIiFile("Pattern/name").toString();
        slotShowPatternPara(m_curFilePath,-1);//不显示花样设置窗体，直接加载花样参数

        s16 wifi = g_pSettings->readFromInHMIiFile("HMI/wifi").toInt();//是否有wifi
        if(wifi == 1)
        {
            onTenMiniteTimer();
            ui->buttonWifi->setVisible(true);
            m_pWifiConTimer->start();
        }
        else
        {
            ui->buttonWifi->setVisible(false);
        }
    }
    connect(g_pMachine, SIGNAL(siDebugInfo()), this, SLOT(slotDebugInfo()));
    initArabControlPos();
}

//不同机型不同的窗体设置
void MainWidget::initMcTypeWindows()
{
    m_pParameterSetDlg = new ParameterSetDialog(this);
    m_pControlActionWi = new ControlActionWidget(this);
    m_pSensorInputWi = new SensorInputWidget(this);

    m_quickItemList.clear();
    m_assistItemList.clear();
    m_patternSetItemList.clear();
    m_paraSetItemList.clear();
    m_embFunctionItemList.clear();

    MachineTypeFun * curMachineType = NULL;
    int waterMark = g_pSettings->readFromInHMIiFile("HMI/waterMark").toInt();//是否带水印
    //等于绣花机
    if(g_emMacType == MACHINE_EMB)
    {
        curMachineType = new FlatEmbroidery;
        if(waterMark==1)//带logo
        {
            ui->labelTitle->setText(tr("Richpeace Embroidery Control System"));//富怡绣花控制系统
        }
        else
        {
            ui->labelTitle->setText(tr("Embroidery Control System"));//绣花控制系统
        }
    }
    //等于绗绣机
    else if(g_emMacType == QUIMACHINE_EMB)
    {
        curMachineType = new Quiembroidery;
        if(waterMark==1)//带logo
        {
            ui->labelTitle->setText(tr("Richpeace QuiEmbroidery Control System"));//富怡绗绣控制系统
        }
        else
        {
            ui->labelTitle->setText(tr("QuiEmbroidery Control System"));//绗绣控制系统
        }
    }

    //初始化快捷按钮列表要在初始化控件前
    m_quickItemList = curMachineType->getShortCutListByFilter();
    m_assistItemList = curMachineType->getAssistListByFilter();
    m_patternSetItemList = curMachineType->getPatternSetListByFilter();
    m_paraSetItemList = curMachineType->getParaSetListByFilter();
    m_embFunctionItemList = curMachineType->getEmbFunctionListByFilter();
    m_pControlActionWi->addItemList(curMachineType->getOutCtrlListByFilter());
    //添加机器参数和工作参数
    m_pParameterSetDlg->addParaItem(curMachineType->getParasListByMcSel());
    m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK);
    m_pSensorInputWi->addSensorItems(curMachineType->getSensorList());

    m_errorCodeAndStateItemList.clear();
    m_errorCodeAndStateItemList = curMachineType->getErrorCodeAndStateList();

    if(curMachineType != NULL)
    {
        delete curMachineType;
    }
}

//初始化快捷功能中的快捷按钮
void MainWidget::initQuickFunBtn()
{
    for(int i = 0; i < m_quickBtnList.size(); i++)
    {
        if(i < m_quickItemList.size())
        {
            m_quickBtnList[i]->setVisible(true);
            m_quickLabelList[i]->setVisible(true);

            QString name = m_quickItemList[i].m_name;
            m_quickLabelList[i]->setText(name);

            QString topImageName = m_quickItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_quickBtnList[i]->setTopImage(btnStyle);

            int enumFun = m_quickItemList[i].m_enumFunction;
            if(enumFun == FUN_FORWARDORBACK ||//快进快退
                    enumFun == FUN_SETSTARTEMBPOINT ||//定起绣点
                    enumFun == FUN_BACKSTARTEMBPOINT ||//回起绣点
                    enumFun == FUN_CHECKFRAME ||//边框检查
                    enumFun == FUN_BACKWORKPOINT //回工作点
                    )
            {
                if(m_curFilePath.length() <= 0)//未选择文件时快进快退等按钮不可用
                {
                    m_quickBtnList[i]->setEnabled(false);
                }
            }
        }
        else
        {
            m_quickBtnList[i]->setVisible(false);
            m_quickLabelList[i]->setVisible(false);
        }
    }
}

//初始化辅助功能中的辅助按钮
void MainWidget::initAssisitBtn()
{
    for(int i = 0; i < m_assistBtnList.size(); i++)
    {
        if(i < m_assistItemList.size())
        {
            m_assistBtnList[i]->setVisible(true);
            m_assistLabelList[i]->setVisible(true);

            QString name = m_assistItemList[i].m_name;
            m_assistLabelList[i]->setText(name);

            QString topImageName = m_assistItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_assistBtnList[i]->setTopImage(btnStyle);
        }
        else
        {
            m_assistBtnList[i]->setVisible(false);
            m_assistLabelList[i]->setVisible(false);
        }
    }
}

//初始化花样设置功能中的花样设置按钮
void MainWidget::initPatternSetBtn()
{
    for(int i = 0; i < m_patternSetBtnList.size(); i++)
    {
        if(i < m_patternSetItemList.size())
        {
            m_patternSetBtnList[i]->setVisible(true);
            m_patternSetLabelList[i]->setVisible(true);

            QString name = m_patternSetItemList[i].m_name;
            m_patternSetLabelList[i]->setText(name);

            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_patternSetBtnList[i]->setTopImage(btnStyle);

            //无花样时花样参数、花样色序
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                    m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
            {
                m_patternSetBtnList[i]->setEnabled(false);
            }
        }
        else
        {
            m_patternSetBtnList[i]->setVisible(false);
            m_patternSetLabelList[i]->setVisible(false);
        }
    }
}

//初始化参数设置功能中的参数设置按钮
void MainWidget::initParaSetBtn()
{
    for(int i = 0; i < m_paraSetBtnList.size(); i++)
    {
        if(i < m_paraSetItemList.size())
        {
            m_paraSetBtnList[i]->setVisible(true);
            m_paraSetLabelList[i]->setVisible(true);

            QString name = m_paraSetItemList[i].m_name;
            m_paraSetLabelList[i]->setText(name);

            //m_paraSetLabelList[i]->setWordWrap(true);
            QString topImageName = m_paraSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_paraSetBtnList[i]->setTopImage(btnStyle);
        }
        else
        {
            m_paraSetBtnList[i]->setVisible(false);
            m_paraSetLabelList[i]->setVisible(false);
        }
    }
}

//初始化刺绣功能中的刺绣功能按钮
void MainWidget::initEmbFunctionBtn()
{
    for(int i = 0; i < m_embFunctionBtnList.size(); i++)
    {
        if(i < m_embFunctionItemList.size())
        {
            m_embFunctionBtnList[i]->setVisible(true);
            m_embFunctionLabelList[i]->setVisible(true);

            QString name = m_embFunctionItemList[i].m_name;
            m_embFunctionLabelList[i]->setText(name);

            QString topImageName = m_embFunctionItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_embFunctionBtnList[i]->setTopImage(btnStyle);

            //无花样时隔头绣、贴布绣、边框刺绣等不可按
            if(m_embFunctionItemList[i].m_enumFunction == EMBFUN_HEADEMB ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_PATCHEMB ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_BORDEREMB ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINE ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINECHECK ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_LINEOFFSET ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_REPEATED )
            {
                m_embFunctionBtnList[i]->setEnabled(false);
            }
        }
        else
        {
            m_embFunctionBtnList[i]->setVisible(false);
            m_embFunctionLabelList[i]->setVisible(false);
        }
    }
}

void MainWidget::setFrameNineBtnStyle()
{
    switch (m_speedLevel)
    {
    case 1:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_1"));
        break;
    case 2:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_2"));
        break;
    case 3:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_3"));
        break;
    default:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle1"));
        break;
    }
}

//清除文件信息
void MainWidget::clearFileInfo()
{
    ui->labelXValue->setText("0");
    ui->labelYValue->setText("0");
    ui->labelWValue->setText("0");
    ui->labelHValue->setText("0");
    ui->labelCValue->setText("0");
    ui->labelNValue->setText("0");

    ui->labelWorkingTime->setText("0:0");
    ui->labelNeedleNum->setText("0");
    QTextCodec *cod = QTextCodec::codecForLocale();
    ui->labelSpindleAngle->setText(cod->toUnicode("0°"));
    ui->labelColorOrder->setText("0");
    ui->labelNeedleIdx->setText("0");
    ui->progressBarProgress->setValue(0);
    ui->labelCoorXY->setText("(0, 0)");
    ui->labelCoorXYValue->setText("(0, 0)");
    ui->labelRelativeCoorXY->setText("(0, 0)");

    ui->labelNeedleCurAndTotal->setText("0/0");
    ui->labelColorCurAndTotal->setText("0/0");
}

//初始化窗体控件，包括位置、尺寸、样式
void MainWidget::initControl()
{
    ui->buttonShortCutPgDn->setVisible(false);
    ui->buttonShortCutPgUp->setVisible(false);
    ui->labelShortCutPage->setVisible(false);

    ui->buttonAssistPgDn->setVisible(false);
    ui->buttonAssistPgUp->setVisible(false);
    ui->labelAssistPage->setVisible(false);

    m_quickBtnList.clear();
    m_quickBtnList.append(ui->buttonQuick1);
    m_quickBtnList.append(ui->buttonQuick2);
    m_quickBtnList.append(ui->buttonQuick3);
    m_quickBtnList.append(ui->buttonQuick4);
    m_quickBtnList.append(ui->buttonQuick5);
    m_quickBtnList.append(ui->buttonQuick6);
    m_quickBtnList.append(ui->buttonQuick7);
    m_quickBtnList.append(ui->buttonQuick8);
    m_quickBtnList.append(ui->buttonQuick9);
    m_quickBtnList.append(ui->buttonQuick10);
    m_quickBtnList.append(ui->buttonQuick11);
    m_quickBtnList.append(ui->buttonQuick12);
    m_quickBtnList.append(ui->buttonQuick13);
    m_quickBtnList.append(ui->buttonQuick14);
    m_quickBtnList.append(ui->buttonQuick15);
    m_quickBtnList.append(ui->buttonQuick16);
    m_quickBtnList.append(ui->buttonQuick17);
    m_quickBtnList.append(ui->buttonQuick18);
    m_quickBtnList.append(ui->buttonQuick19);
    m_quickBtnList.append(ui->buttonQuick20);
    m_quickBtnList.append(ui->buttonQuick21);
    m_quickBtnList.append(ui->buttonQuick22);
    m_quickBtnList.append(ui->buttonQuick23);
    m_quickBtnList.append(ui->buttonQuick24);
    m_quickBtnList.append(ui->buttonQuick25);
    m_quickBtnList.append(ui->buttonQuick26);
    m_quickBtnList.append(ui->buttonQuick27);
    m_quickBtnList.append(ui->buttonQuick28);

    for(int i = 0; i < m_quickBtnList.size(); i++)
    {
        connect(m_quickBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotQuickBtnClick())
                );
    }


    m_quickLabelList.clear();
    m_quickLabelList.append(ui->labelQuick1);
    m_quickLabelList.append(ui->labelQuick2);
    m_quickLabelList.append(ui->labelQuick3);
    m_quickLabelList.append(ui->labelQuick4);
    m_quickLabelList.append(ui->labelQuick5);
    m_quickLabelList.append(ui->labelQuick6);
    m_quickLabelList.append(ui->labelQuick7);
    m_quickLabelList.append(ui->labelQuick8);
    m_quickLabelList.append(ui->labelQuick9);
    m_quickLabelList.append(ui->labelQuick10);
    m_quickLabelList.append(ui->labelQuick11);
    m_quickLabelList.append(ui->labelQuick12);
    m_quickLabelList.append(ui->labelQuick13);
    m_quickLabelList.append(ui->labelQuick14);
    m_quickLabelList.append(ui->labelQuick15);
    m_quickLabelList.append(ui->labelQuick16);
    m_quickLabelList.append(ui->labelQuick17);
    m_quickLabelList.append(ui->labelQuick18);
    m_quickLabelList.append(ui->labelQuick19);
    m_quickLabelList.append(ui->labelQuick20);
    m_quickLabelList.append(ui->labelQuick21);
    m_quickLabelList.append(ui->labelQuick22);
    m_quickLabelList.append(ui->labelQuick23);
    m_quickLabelList.append(ui->labelQuick24);
    m_quickLabelList.append(ui->labelQuick25);
    m_quickLabelList.append(ui->labelQuick26);
    m_quickLabelList.append(ui->labelQuick27);
    m_quickLabelList.append(ui->labelQuick28);

    m_shortCutBtnList.clear();
    m_shortCutBtnList.append(ui->buttonShortcut1);
    m_shortCutBtnList.append(ui->buttonShortcut2);
    m_shortCutBtnList.append(ui->buttonShortcut3);
    m_shortCutBtnList.append(ui->buttonShortcut4);
    m_shortCutBtnList.append(ui->buttonShortcut5);
    m_shortCutBtnList.append(ui->buttonShortcut6);
    m_shortCutBtnList.append(ui->buttonShortcut7);
    m_shortCutBtnList.append(ui->buttonShortcut8);
    m_shortCutBtnList.append(ui->buttonShortcut9);
    m_shortCutBtnList.append(ui->buttonShortcut10);

    for(int i = 0; i < m_shortCutBtnList.size(); i++)
    {
        connect(m_shortCutBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotShortCutBtnClick())
                );
    }

    m_assistBtnList.clear();
    m_assistBtnList.append(ui->buttonAssist1);
    m_assistBtnList.append(ui->buttonAssist2);
    m_assistBtnList.append(ui->buttonAssist3);
    m_assistBtnList.append(ui->buttonAssist4);
    m_assistBtnList.append(ui->buttonAssist5);
    m_assistBtnList.append(ui->buttonAssist6);
    m_assistBtnList.append(ui->buttonAssist7);
    m_assistBtnList.append(ui->buttonAssist8);
    m_assistBtnList.append(ui->buttonAssist9);
    m_assistBtnList.append(ui->buttonAssist10);
    m_assistBtnList.append(ui->buttonAssist11);
    m_assistBtnList.append(ui->buttonAssist12);
    m_assistBtnList.append(ui->buttonAssist13);
    m_assistBtnList.append(ui->buttonAssist14);
    m_assistBtnList.append(ui->buttonAssist15);
    m_assistBtnList.append(ui->buttonAssist16);
    m_assistBtnList.append(ui->buttonAssist17);
    m_assistBtnList.append(ui->buttonAssist18);
    m_assistBtnList.append(ui->buttonAssist19);
    m_assistBtnList.append(ui->buttonAssist20);
    m_assistBtnList.append(ui->buttonAssist21);
    m_assistBtnList.append(ui->buttonAssist22);
    m_assistBtnList.append(ui->buttonAssist23);
    m_assistBtnList.append(ui->buttonAssist24);
    m_assistBtnList.append(ui->buttonAssist25);
    m_assistBtnList.append(ui->buttonAssist26);
    m_assistBtnList.append(ui->buttonAssist27);
    m_assistBtnList.append(ui->buttonAssist28);

    for(int i = 0; i < m_assistBtnList.size(); i++)
    {
        connect(m_assistBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotAssistBtnClick())
                );
    }


    m_assistLabelList.clear();
    m_assistLabelList.append(ui->labelAssist1);
    m_assistLabelList.append(ui->labelAssist2);
    m_assistLabelList.append(ui->labelAssist3);
    m_assistLabelList.append(ui->labelAssist4);
    m_assistLabelList.append(ui->labelAssist5);
    m_assistLabelList.append(ui->labelAssist6);
    m_assistLabelList.append(ui->labelAssist7);
    m_assistLabelList.append(ui->labelAssist8);
    m_assistLabelList.append(ui->labelAssist9);
    m_assistLabelList.append(ui->labelAssist10);
    m_assistLabelList.append(ui->labelAssist11);
    m_assistLabelList.append(ui->labelAssist12);
    m_assistLabelList.append(ui->labelAssist13);
    m_assistLabelList.append(ui->labelAssist14);
    m_assistLabelList.append(ui->labelAssist15);
    m_assistLabelList.append(ui->labelAssist16);
    m_assistLabelList.append(ui->labelAssist17);
    m_assistLabelList.append(ui->labelAssist18);
    m_assistLabelList.append(ui->labelAssist19);
    m_assistLabelList.append(ui->labelAssist20);
    m_assistLabelList.append(ui->labelAssist21);
    m_assistLabelList.append(ui->labelAssist22);
    m_assistLabelList.append(ui->labelAssist23);
    m_assistLabelList.append(ui->labelAssist24);
    m_assistLabelList.append(ui->labelAssist25);
    m_assistLabelList.append(ui->labelAssist26);
    m_assistLabelList.append(ui->labelAssist27);
    m_assistLabelList.append(ui->labelAssist28);

    m_patternSetBtnList.clear();
    m_patternSetBtnList.append(ui->buttonPatternSet1);
    m_patternSetBtnList.append(ui->buttonPatternSet2);
    m_patternSetBtnList.append(ui->buttonPatternSet3);
    m_patternSetBtnList.append(ui->buttonPatternSet4);
    m_patternSetBtnList.append(ui->buttonPatternSet5);
    m_patternSetBtnList.append(ui->buttonPatternSet6);
    m_patternSetBtnList.append(ui->buttonPatternSet7);
    m_patternSetBtnList.append(ui->buttonPatternSet8);
    m_patternSetBtnList.append(ui->buttonPatternSet9);
    m_patternSetBtnList.append(ui->buttonPatternSet10);
    m_patternSetBtnList.append(ui->buttonPatternSet11);
    m_patternSetBtnList.append(ui->buttonPatternSet12);
    m_patternSetBtnList.append(ui->buttonPatternSet13);
    m_patternSetBtnList.append(ui->buttonPatternSet14);

    for(int i = 0; i < m_patternSetBtnList.size(); i++)
    {
        connect(m_patternSetBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotPatternSetBtnClick())
                );
    }

    m_patternSetLabelList.append(ui->labelPatternSet1);
    m_patternSetLabelList.append(ui->labelPatternSet2);
    m_patternSetLabelList.append(ui->labelPatternSet3);
    m_patternSetLabelList.append(ui->labelPatternSet4);
    m_patternSetLabelList.append(ui->labelPatternSet5);
    m_patternSetLabelList.append(ui->labelPatternSet6);
    m_patternSetLabelList.append(ui->labelPatternSet7);
    m_patternSetLabelList.append(ui->labelPatternSet8);
    m_patternSetLabelList.append(ui->labelPatternSet9);
    m_patternSetLabelList.append(ui->labelPatternSet10);
    m_patternSetLabelList.append(ui->labelPatternSet11);
    m_patternSetLabelList.append(ui->labelPatternSet12);
    m_patternSetLabelList.append(ui->labelPatternSet13);
    m_patternSetLabelList.append(ui->labelPatternSet14);

    m_paraSetBtnList.clear();
    m_paraSetBtnList.append(ui->buttonParaType1);
    m_paraSetBtnList.append(ui->buttonParaType2);
    m_paraSetBtnList.append(ui->buttonParaType3);
    m_paraSetBtnList.append(ui->buttonParaType4);
    m_paraSetBtnList.append(ui->buttonParaType5);
    m_paraSetBtnList.append(ui->buttonParaType6);
    m_paraSetBtnList.append(ui->buttonParaType7);
    m_paraSetBtnList.append(ui->buttonParaType8);
    m_paraSetBtnList.append(ui->buttonParaType9);
    m_paraSetBtnList.append(ui->buttonParaType10);
    m_paraSetBtnList.append(ui->buttonParaType11);
    m_paraSetBtnList.append(ui->buttonParaType12);
    m_paraSetBtnList.append(ui->buttonParaType13);
    m_paraSetBtnList.append(ui->buttonParaType14);

    for(int i = 0; i < m_paraSetBtnList.size(); i++)
    {
        connect(m_paraSetBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotParaTypeBtnClick())
                );
    }

    m_paraSetLabelList.append(ui->labelParaType1);
    m_paraSetLabelList.append(ui->labelParaType2);
    m_paraSetLabelList.append(ui->labelParaType3);
    m_paraSetLabelList.append(ui->labelParaType4);
    m_paraSetLabelList.append(ui->labelParaType5);
    m_paraSetLabelList.append(ui->labelParaType6);
    m_paraSetLabelList.append(ui->labelParaType7);
    m_paraSetLabelList.append(ui->labelParaType8);
    m_paraSetLabelList.append(ui->labelParaType9);
    m_paraSetLabelList.append(ui->labelParaType10);
    m_paraSetLabelList.append(ui->labelParaType11);
    m_paraSetLabelList.append(ui->labelParaType12);
    m_paraSetLabelList.append(ui->labelParaType13);
    m_paraSetLabelList.append(ui->labelParaType14);

    m_embFunctionBtnList.clear();
    m_embFunctionBtnList.append(ui->buttonEmbFunction1);
    m_embFunctionBtnList.append(ui->buttonEmbFunction2);
    m_embFunctionBtnList.append(ui->buttonEmbFunction3);
    m_embFunctionBtnList.append(ui->buttonEmbFunction4);
    m_embFunctionBtnList.append(ui->buttonEmbFunction5);
    m_embFunctionBtnList.append(ui->buttonEmbFunction6);
    m_embFunctionBtnList.append(ui->buttonEmbFunction7);
    m_embFunctionBtnList.append(ui->buttonEmbFunction8);
    m_embFunctionBtnList.append(ui->buttonEmbFunction9);
    m_embFunctionBtnList.append(ui->buttonEmbFunction10);
    m_embFunctionBtnList.append(ui->buttonEmbFunction11);
    m_embFunctionBtnList.append(ui->buttonEmbFunction12);
    m_embFunctionBtnList.append(ui->buttonEmbFunction13);
    m_embFunctionBtnList.append(ui->buttonEmbFunction14);

    for(int i = 0; i < m_embFunctionBtnList.size(); i++)
    {
        connect(m_embFunctionBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotEmbFunctionBtnClick())
                );
    }

    m_embFunctionLabelList.append(ui->labelEmbFunction1);
    m_embFunctionLabelList.append(ui->labelEmbFunction2);
    m_embFunctionLabelList.append(ui->labelEmbFunction3);
    m_embFunctionLabelList.append(ui->labelEmbFunction4);
    m_embFunctionLabelList.append(ui->labelEmbFunction5);
    m_embFunctionLabelList.append(ui->labelEmbFunction6);
    m_embFunctionLabelList.append(ui->labelEmbFunction7);
    m_embFunctionLabelList.append(ui->labelEmbFunction8);
    m_embFunctionLabelList.append(ui->labelEmbFunction9);
    m_embFunctionLabelList.append(ui->labelEmbFunction10);
    m_embFunctionLabelList.append(ui->labelEmbFunction11);
    m_embFunctionLabelList.append(ui->labelEmbFunction12);
    m_embFunctionLabelList.append(ui->labelEmbFunction13);
    m_embFunctionLabelList.append(ui->labelEmbFunction14);

    m_colorBtnList.clear();
    m_colorBtnList.append(ui->buttonColor1);
    m_colorBtnList.append(ui->buttonColor2);
    m_colorBtnList.append(ui->buttonColor3);
    m_colorBtnList.append(ui->buttonColor4);
    m_colorBtnList.append(ui->buttonColor5);
    m_colorBtnList.append(ui->buttonColor6);
    m_colorBtnList.append(ui->buttonColor7);
    m_colorBtnList.append(ui->buttonColor8);
    //    m_colorBtnList.append(ui->buttonColor9);
    //    m_colorBtnList.append(ui->buttonColor10);

    //根据不同分辨率设置控件的位置和尺寸
    switch (g_emResolut)
    {
    case resolution1910:
        initResolution1910();
        break;
    case resolution1006:
        initResolution1006();
        break;
    default:
        this->resize(1920,1080);
        break;
    }

    initControlStyle();//初始化窗体控件样式
    setCommonBtn();//设置常用按钮样式
}

//初始化窗体控件为1920x1080分辨率
void MainWidget::initResolution1910()
{
    //上状态栏
    this->resize(1920,1080);
    ui->frameBack->setGeometry(0,0,1920,1080);
    ui->frameUp->setGeometry(0,0,1920,64);
    ui->buttonMove->setGeometry(0,0,1920,64);
    ui->labelTitle->setGeometry(26,0,1200,64);
    ui->labelHMIVersion->setGeometry(1000,0,855,64);
    ui->buttonWifi->setGeometry(1870,16,32,32);

    //左侧主按钮
    ui->frameMainFunction->setGeometry(0,65,188,938);
    ui->buttonPatternSet->setGeometry(26,0,106,106);
    ui->buttonParaSet->setGeometry(26,160,106,106);
    ui->buttonEmbFunction->setGeometry(26,320,106,106);
    ui->buttonShortcutFunction->setGeometry(26,480,106,106);
    ui->buttonAccessFunction->setGeometry(26,640,106,106);
    ui->buttonMainMenu->setGeometry(26,800,106,106);
    ui->labelPatternSet->setGeometry(0,106,160,32);
    ui->labelParaSet->setGeometry(0,266,160,32);
    ui->labelEmbFunction->setGeometry(0,426,160,32);
    ui->labelShortcutFunction->setGeometry(0,586,160,32);
    ui->labelAccessFunction->setGeometry(0,746,160,32);
    ui->labelMainMenu->setGeometry(0,906,160,32);

    //下方的10个快捷按钮
    ui->frameShortcutBtn->setGeometry(190,895,1322,106);
    for(int i = 0; i < m_shortCutBtnList.size(); i++)
    {
        m_shortCutBtnList[i]->setGeometry(16+132*i,0,106,106);
    }

    //花样显示区域
    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->labelPatternPreView->setGeometry(0,0,1323,915);//带颜色的花样预览图
        ui->labelPatternView->setGeometry(80,58,1130,852);//灰色图
        ui->progressBarProgress->setGeometry(1132,598,166,40);
        ui->framePatternView->setGeometry(195,66,1317,915);//
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->labelPatternPreView->setGeometry(0,0,1323,815);
        ui->labelPatternView->setGeometry(0,48,1130,752);
        ui->progressBarProgress->setGeometry(1132,498,166,40);
        ui->framePatternView->setGeometry(195,66,1317,815);
    }

    ui->labelFilename->setGeometry(14,8,300,32);
    ui->frameColor->setGeometry(1208,20,98,510);
    QRect rectImage(18,6,24,62);
    QRect rectName(50,10,30,58);
    ui->buttonNeedle->setGeometry(10,9,82,73);
    ui->buttonNeedle->initLeftImageRightName(rectImage,rectName);
    for(int i = 0; i < m_colorBtnList.size(); i++)
    {
        m_colorBtnList.at(i)->setGeometry(10,90+i*40,82,36);
    }
    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->framePatternInfo->setGeometry(1132,650,166,254);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->framePatternInfo->setGeometry(1132,540,166,254);
    }
    ui->framePatternInfoImage->setGeometry(0,0,166,254);//右下角花版信息的背景
    ui->buttonPatternInfo->setGeometry(0,0,166,254);
    ui->labelX->setGeometry(10,10,32,32);
    ui->labelXValue->setGeometry(44,10,116,32);
    ui->labelY->setGeometry(10,50,32,32);
    ui->labelYValue->setGeometry(44,50,116,32);
    ui->labelW->setGeometry(10,90,32,32);
    ui->labelWValue->setGeometry(44,90,116,32);
    ui->labelH->setGeometry(10,130,32,32);
    ui->labelHValue->setGeometry(44,130,116,32);
    ui->labelC->setGeometry(10,170,32,32);
    ui->labelCValue->setGeometry(44,170,116,32);
    ui->labelN->setGeometry(10,210,32,32);
    ui->labelNValue->setGeometry(44,210,116,32);

    ui->buttonUp->setGeometry(624,25,69,50);
    ui->buttonLeft->setGeometry(26,396,50,69);
    ui->buttonRight->setGeometry(1243,396,50,69);
    ui->buttonMiddle->setGeometry(258,158,800,500);

    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->buttonDown->setGeometry(624,842,69,50);
        ui->buttonAuto->setGeometry(27,780,115,112);
        ui->buttonZoom->setGeometry(1165,776,125,118);
        ui->buttonNarrow->setGeometry(1030,775,125,123);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->buttonDown->setGeometry(624,742,69,50);
        ui->buttonAuto->setGeometry(27,680,115,112);
        ui->buttonZoom->setGeometry(1165,676,125,118);
        ui->buttonNarrow->setGeometry(1030,675,125,123);
    }

    //右上方花样信息
    ui->frameEmbInfo->setGeometry(1544,64,344,456);
    ui->buttonWorkingTime->setGeometry(24,20,32,32);
    ui->labelWorkingTime->setGeometry(70,20,220,32);
    ui->buttonNeedleNum->setGeometry(24,80,32,32);
    ui->labelNeedleNum->setGeometry(70,78,220,32);
    ui->buttonSpindleAngle->setGeometry(24,140,32,32);
    ui->labelSpindleAngle->setGeometry(70,134,220,44);
    ui->buttonColorOrder->setGeometry(27,196,24,32);
    ui->labelColorOrder->setGeometry(70,190,220,44);
    ui->buttonNeedleIdx->setGeometry(33,254,16,43);
    ui->labelNeedleIdx->setGeometry(70,248,220,44);
    ui->buttonCoorXY->setGeometry(24,312,32,32);
    ui->labelCoorXY->setGeometry(70,306,250,44);
    ui->buttonRelativeCoorXY->setGeometry(24,376,32,32);
    ui->labelRelativeCoorXY->setGeometry(70,370,250,44);

    //匹绣显示区域
    ui->frameMateEmb->setGeometry(1528,51,366,596);
    ui->frameMateEmbBack->setGeometry(0,0,366,596);
    ui->labelMateEmbShow->setGeometry(0,30,366,32);
    ui->buttonNeedleDown->setGeometry(56,92,257,68);
    ui->buttonNeedleUp->setGeometry(56,202,257,68);
    ui->buttonExitMateEmb->setGeometry(56,312,257,68);

    //开位线绣显示区域
    ui->frameOpenLineEmb->setGeometry(1528,51,366,596);
    ui->frameOpenLineEmbBack->setGeometry(0,0,366,596);
    ui->labelOpenLineShow->setGeometry(0,30,366,32);
    ui->buttonCurCoorXY->setGeometry(40,100,32,32);
    ui->labelCoorXYValue->setGeometry(88,96,250,44);
    ui->labelCurNode->setGeometry(40,170,200,32);
    ui->labelCurNodeValue->setGeometry(250,170,140,32);
    ui->labelCoorX->setGeometry(40,210,32,32);
    ui->labelCoorXValue->setGeometry(80,210,200,32);
    ui->labelCoorY->setGeometry(40,250,200,32);
    ui->labelCoorYValue->setGeometry(80,250,200,32);
    ui->buttonPreNode->setGeometry(27,300,98,68);
    ui->buttonNextNode->setGeometry(135,300,98,68);
    ui->buttonSetNode->setGeometry(243,300,98,68);
    ui->buttonNodeDelete->setGeometry(27,390,98,68);
    ui->buttonOpenLineOk->setGeometry(135,390,98,68);
    ui->buttonOpenLineClose->setGeometry(243,390,98,68);

    //九宫格
    ui->frameFunctionBtn->setGeometry(1544,534,344,468);
    ui->frameSpeed->setGeometry(0,0,344,102);
    ui->buttonSpeedAdd->setGeometry(228,-8,128,128);
    ui->lcdNumberSpeed->setGeometry(106,14,128,88);
    ui->buttonSpeedDec->setGeometry(-8,-8,128,128);
    ui->frameNineBtn->setGeometry(0,122,344,344);
    ui->buttonNineBtn1->setGeometry(0,0,106,106);
    ui->buttonNineBtnUp->setGeometry(122,0,106,106);
    ui->buttonNineBtn2->setGeometry(238,0,106,106);
    ui->buttonNineBtnLeft->setGeometry(0,118,106,106);
    ui->buttonNineBtnMiddle->setGeometry(117,118,106,106);
    ui->buttonNineBtnRight->setGeometry(238,118,106,106);
    ui->buttonNineBtn3->setGeometry(0,238,106,106);
    ui->buttonNineBtnDown->setGeometry(122,236,106,106);
    ui->buttonNineBtn4->setGeometry(238,238,106,106);

    //下方状态栏
    ui->frameDown->setGeometry(0,1016,1920,64);
    ui->progressBar->setGeometry(4,62,1912,2);
    ui->labelScreenshot->setGeometry(0,0,1920,65);//截屏
    ui->labelState->setGeometry(32,0,600,64);
    ui->labelNoseHead->setGeometry(640,0,600,64);
    ui->labelWorkState->setGeometry(1396,15,32,34);//模拟工作
    ui->labelEnableWorkState->setGeometry(1436,16,32,32);//显示工作状态
    ui->frameMenuBack->setGeometry(192,65,1323,935);
    ui->buttonConnect->setGeometry(1476,16,32,32);//链接状态
    ui->buttonUser->setGeometry(1516,16,32,31);//用户
    ui->labelTime->setGeometry(1556,16,340,32);//时间

    //辅助功能
    ui->frameAccessFunction->setGeometry(190,65,1320,934);
    u16 hNum = 7;//每行7个
    u16 vNum = 4;//总共4行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_assistBtnList[i*hNum+j]->setGeometry(59+183*j,48+202*i,106,106);
            m_assistLabelList[i*hNum+j]->setGeometry(29+183*j,154+202*i,165,66);
        }
    }
    ui->buttonAssistPgUp->setGeometry(956,836,164,64);
    ui->buttonAssistPgDn->setGeometry(1136,836,164,64);
    ui->labelAssistPage->setGeometry(790,836,150,64);

    //花样设置
    ui->framePatternSet->setGeometry(190,65,1320,934);
    hNum = 7;//每行7个
    vNum = 2;//总共2行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_patternSetBtnList[i*hNum+j]->setGeometry(59+183*j,48+202*i,106,106);
            m_patternSetLabelList[i*hNum+j]->setGeometry(29+183*j,154+202*i,165,66);//1920x1080 英文显示不全 -rq
        }
    }

    //参数设置
    ui->frameParaSet->setGeometry(190,65,1320,934);
    hNum = 7;//每行7个
    vNum = 2;//总共2行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_paraSetBtnList[i*hNum+j]->setGeometry(59+183*j,48+202*i,106,106);
            m_paraSetLabelList[i*hNum+j]->setGeometry(29+183*j,154+202*i,165,66);
        }
    }

    //刺绣功能
    ui->frameEmbFunction->setGeometry(190,65,1320,934);
    hNum = 7;//每行7个
    vNum = 2;//总共2行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_embFunctionBtnList[i*hNum+j]->setGeometry(59+183*j,48+202*i,106,106);
            m_embFunctionLabelList[i*hNum+j]->setGeometry(29+183*j,154+202*i,165,66);
        }
    }

    //快捷功能
    ui->frameShortcutFunction->setGeometry(190,65,1320,934);
    hNum = 7;//每行7个
    vNum = 4;//总共4行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_quickBtnList[i*hNum+j]->setGeometry(59+183*j,48+202*i,106,106);
            m_quickLabelList[i*hNum+j]->setGeometry(29+183*j,154+202*i,165,66);
        }
    }
    ui->buttonShortCutPgUp->setGeometry(956,836,164,64);
    ui->buttonShortCutPgDn->setGeometry(1136,836,164,64);
    ui->labelShortCutPage->setGeometry(790,836,150,64);

    //快进回退
    ui->frameForwardBack->setGeometry(1534,55,368,951);
    ui->frameForwardBackBack->setGeometry(0,0,368,951);
    ui->labelForwardBackTitle->setGeometry(0,20,368,40);
    ui->buttonNeedleIdxImage->setGeometry(38,80,16,40);
    ui->labelNeedleCurAndTotal->setGeometry(80,80,220,32);
    ui->buttonColorIdxImage->setGeometry(34,140,24,32);
    ui->labelColorCurAndTotal->setGeometry(80,140,220,32);
    ui->buttonNeedleBegin->setGeometry(34,240,132,66);
    ui->buttonNeedleDec1->setGeometry(34,320,132,66);
    ui->buttonNeedleDec10->setGeometry(34,400,132,66);
    ui->buttonNeedleDec100->setGeometry(34,480,132,66);
    ui->buttonNeedleDec1000->setGeometry(34,560,132,66);
    ui->buttonNeedleDec10000->setGeometry(34,640,132,66);
    ui->buttonColorDec->setGeometry(34,720,132,66);
    ui->buttonForwardBackOk->setGeometry(34,860,132,66);
    ui->buttonNeedleEnd->setGeometry(202,240,132,66);
    ui->buttonNeedleAdd1->setGeometry(202,320,132,66);
    ui->buttonNeedleAdd10->setGeometry(202,400,132,66);
    ui->buttonNeedleAdd100->setGeometry(202,480,132,66);
    ui->buttonNeedleAdd1000->setGeometry(202,560,132,66);
    ui->buttonNeedleAdd10000->setGeometry(202,640,132,66);
    ui->buttonColorAdd->setGeometry(202,720,132,66);
    ui->buttonForwardBackCancel->setGeometry(202,860,132,66);
}

//初始化窗体控件为1024x600分辨率
void MainWidget::initResolution1006()
{
    this->resize(1024,600);
    ui->frameBack->setGeometry(0,0,1024,600);
    ui->frameUp->setGeometry(0,0,1024,30);
    ui->buttonMove->setGeometry(0,0,1024,30);
    ui->labelTitle->setGeometry(15,2,360,30);
    ui->labelHMIVersion->setGeometry(555,2,440,30);
    ui->buttonWifi->setGeometry(1000,11,15,15);

    //左侧主按钮
    ui->frameMainFunction->setGeometry(0,36,98,532);// x坐标 y坐标  宽高
    ui->buttonPatternSet->setGeometry(13,0,58,58);
    ui->buttonParaSet->setGeometry(13,90,58,58);
    ui->buttonEmbFunction->setGeometry(13,180,58,58);
    ui->buttonShortcutFunction->setGeometry(13,270,58,58);
    ui->buttonAccessFunction->setGeometry(13,360,58,58);
    ui->buttonMainMenu->setGeometry(13,450,58,58);
    ui->labelPatternSet->setGeometry(8,59,70,20);
    ui->labelParaSet->setGeometry(8,149,70,20);
    ui->labelEmbFunction->setGeometry(8,239,70,20);
    ui->labelShortcutFunction->setGeometry(8,329,70,20);
    ui->labelAccessFunction->setGeometry(8,419,70,20);
    ui->labelMainMenu->setGeometry(8,509,70,20);

    //下方的10个快捷按钮
    ui->frameShortcutBtn->setGeometry(102,490,709,71);
    for(int i = 0; i < m_shortCutBtnList.size(); i++)
    {
        m_shortCutBtnList[i]->setGeometry(10+70*i,9,58,58);
    }

    //匹绣显示区域
    ui->frameMateEmb->setGeometry(816,29,194,333);
    ui->frameMateEmbBack->setGeometry(0,0,194,333);
    ui->labelMateEmbShow->setGeometry(52,17,100,21);
    ui->buttonNeedleDown->setGeometry(30,52,138,40);
    ui->buttonNeedleUp->setGeometry(30,110,138,40);
    ui->buttonExitMateEmb->setGeometry(30,170,138,40);

    //开位线绣显示区域
    ui->frameOpenLineEmb->setGeometry(816,29,194,333);
    ui->frameOpenLineEmbBack->setGeometry(0,0,194,333);
    ui->labelOpenLineShow->setGeometry(52,17,91,21);
    ui->buttonCurCoorXY->setGeometry(17,50,20,20);
    ui->labelCoorXYValue->setGeometry(50,43,180,31);
    ui->labelCurNode->setGeometry(17,75,200,32);//当前节点
    ui->labelCurNodeValue->setGeometry(120,81,91,21);
    ui->labelCoorX->setGeometry(17,110,91,21);
    ui->labelCoorXValue->setGeometry(60,110,51,21);
    ui->labelCoorY->setGeometry(17,140,91,21);
    ui->labelCoorYValue->setGeometry(60,140,51,21);
    ui->buttonPreNode->setGeometry(15,180,51,40);
    ui->buttonNextNode->setGeometry(71,180,51,40);
    ui->buttonSetNode->setGeometry(128,180,51,40);
    ui->buttonNodeDelete->setGeometry(15,240,51,40);
    ui->buttonOpenLineOk->setGeometry(71,240,51,40);
    ui->buttonOpenLineClose->setGeometry(128,240,51,40);

    //九宫格
    ui->frameFunctionBtn->setGeometry(820,292,200,268);// x y w h
    ui->frameSpeed->setGeometry(0,0,185,200);
    ui->buttonSpeedAdd->setGeometry(123,0,70,71);
    ui->lcdNumberSpeed->setGeometry(64,14,60,44);
    ui->buttonSpeedDec->setGeometry(0,0,70,71);
    ui->frameNineBtn->setGeometry(5,75,184,185);
    ui->buttonNineBtn1->setGeometry(0,0,58,58);
    ui->buttonNineBtnUp->setGeometry(60,0,58,58);
    ui->buttonNineBtn2->setGeometry(126,0,58,58);
    ui->buttonNineBtnLeft->setGeometry(0,56,58,58);
    ui->buttonNineBtnMiddle->setGeometry(61,65,58,58);
    ui->buttonNineBtnRight->setGeometry(120,56,58,58);
    ui->buttonNineBtn3->setGeometry(0,126,58,58);
    ui->buttonNineBtnDown->setGeometry(60,115,58,58);
    ui->buttonNineBtn4->setGeometry(126,126,58,58);

    //下方状态栏
    ui->frameDown->setGeometry(0,564,1024,36);
    ui->progressBar->setGeometry(4,28,1016,2);
    ui->labelState->setGeometry(15,0,200,36);
    ui->labelNoseHead->setGeometry(210,0,200,36);
    ui->labelWorkState->setGeometry(748,10,16,17);//模拟工作
    ui->labelEnableWorkState->setGeometry(772,11,15,15);//显示工作状态
    ui->buttonConnect->setGeometry(800,11,15,15);//链接状态
    ui->buttonUser->setGeometry(822,11,15,15);//用户
    ui->frameMenuBack->setGeometry(101,36,707,513);//二级菜单的白色背景显示不齐  -rq
    ui->labelScreenshot->setGeometry(0,0,1024,36);//截屏
    ui->labelTime->setGeometry(842,0,200,36);//时间

    //右上方花样信息
    ui->frameEmbInfo->setGeometry(819,30,188,280);
    ui->buttonWorkingTime->setGeometry(18,20,20,20);
    ui->labelWorkingTime->setGeometry(45,15,110,28);
    ui->buttonNeedleNum->setGeometry(18,55,18,18);
    ui->labelNeedleNum->setGeometry(45,50,120,28);
    ui->buttonSpindleAngle->setGeometry(18,90,19,19);
    ui->labelSpindleAngle->setGeometry(45,85,110,28);
    ui->buttonColorOrder->setGeometry(18,125,15,20);
    ui->labelColorOrder->setGeometry(45,120,110,28);
    ui->buttonNeedleIdx->setGeometry(23,160,8,25);
    ui->labelNeedleIdx->setGeometry(45,155,110,28);
    ui->buttonCoorXY->setGeometry(18,195,20,20);
    ui->labelCoorXY->setGeometry(45,190,170,28);
    ui->buttonRelativeCoorXY->setGeometry(19,230,20,20);
    ui->labelRelativeCoorXY->setGeometry(45,225,170,28);

    //花样显示区域
    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->labelPatternPreView->setGeometry(48,30,600,461);//带颜色花样图
        ui->labelPatternView->setGeometry(58,30,541,461);//灰色花样图
        ui->progressBarProgress->setGeometry(600,332,88,26);
        ui->framePatternView->setGeometry(108,36,707,502);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->labelPatternPreView->setGeometry(48,30,600,411);//带颜色花样图
        ui->labelPatternView->setGeometry(58,30,541,411);//灰色花样图
        ui->progressBarProgress->setGeometry(600,282,88,26);
        ui->framePatternView->setGeometry(108,36,707,452);
    }

    ui->labelFilename->setGeometry(6,5,500,24);
    ui->frameColor->setGeometry(620,0,68,311);
    QRect rectImage(9,3,12,31);
    QRect rectName(26,10,20,29);
    ui->buttonNeedle->setGeometry(16,14,52,40);
    ui->buttonNeedle->initLeftImageRightName(rectImage,rectName);
    for(int i = 0; i < m_colorBtnList.size(); i++)
    {
        m_colorBtnList.at(i)->setGeometry(16,58+i*24,52,22);//两位数字显示不全   -rq
    }

    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->framePatternInfo->setGeometry(600,360,88,134);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->framePatternInfo->setGeometry(600,310,88,134);
    }

    ui->framePatternInfoImage->setGeometry(0,0,88,134);
    ui->buttonPatternInfo->setGeometry(0,0,88,134);
    ui->labelX->setGeometry(8,10,20,16);
    ui->labelXValue->setGeometry(10,10,72,16);
    ui->labelY->setGeometry(8,30,20,16);
    ui->labelYValue->setGeometry(10,30,72,16);
    ui->labelW->setGeometry(8,50,20,16);
    ui->labelWValue->setGeometry(10,50,72,16);
    ui->labelH->setGeometry(8,70,20,16);
    ui->labelHValue->setGeometry(10,70,72,16);
    ui->labelC->setGeometry(8,90,20,16);
    ui->labelCValue->setGeometry(10,90,72,16);
    ui->labelN->setGeometry(8,110,20,16);
    ui->labelNValue->setGeometry(10,110,72,16);

    ui->buttonUp->setGeometry(340,5,37,27);

    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->buttonDown->setGeometry(340,473,37,27);
        ui->buttonAuto->setGeometry(1,438,61,62);
        ui->buttonZoom->setGeometry(565,436,66,65);
        ui->buttonNarrow->setGeometry(630,436,66,65);
        ui->buttonLeft->setGeometry(1,240,26,38);
        ui->buttonRight->setGeometry(669,240,26,38);
        ui->buttonMiddle->setGeometry(234,110,240,250);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->buttonDown->setGeometry(340,423,37,27);
        ui->buttonAuto->setGeometry(1,388,61,62);
        ui->buttonZoom->setGeometry(565,386,66,65);
        ui->buttonNarrow->setGeometry(630,386,66,65);
        ui->buttonLeft->setGeometry(1,190,26,38);
        ui->buttonRight->setGeometry(669,190,26,38);
        ui->buttonMiddle->setGeometry(234,110,240,200);
    }


    //辅助功能
    ui->frameAccessFunction->setGeometry(108,36,707,513);
    u16 hNum = 7;//每行7个
    u16 vNum = 4;//总共4行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_assistBtnList[i*hNum+j]->setGeometry(24+98*j,24+106*i,58,58);
            m_assistLabelList[i*hNum+j]->setGeometry(6+98*j,84+106*i,95,40);//字体显示不全  -rq
        }
    }
    ui->buttonAssistPgUp->setGeometry(476,460,100,40);
    ui->buttonAssistPgDn->setGeometry(586,460,100,40);
    ui->labelAssistPage->setGeometry(376,460,100,40);

    //花样设置
    ui->framePatternSet->setGeometry(108,36,707,513);
    hNum = 7;//每行7个
    vNum = 2;//总共2行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_patternSetBtnList[i*hNum+j]->setGeometry(24+98*j,24+106*i,58,58);
            m_patternSetLabelList[i*hNum+j]->setGeometry(14+98*j,84+106*i,81,40);
        }
    }

    //参数设置
    ui->frameParaSet->setGeometry(108,36,707,513);
    hNum = 7;//每行7个
    vNum = 2;//总共2行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_paraSetBtnList[i*hNum+j]->setGeometry(24+98*j,24+106*i,58,58);
            m_paraSetLabelList[i*hNum+j]->setGeometry(14+98*j,84+106*i,81,40);
        }
    }

    //刺绣功能
    ui->frameEmbFunction->setGeometry(108,36,707,513);
    hNum = 7;//每行7个
    vNum = 2;//总共2行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_embFunctionBtnList[i*hNum+j]->setGeometry(24+98*j,24+106*i,58,58);
            m_embFunctionLabelList[i*hNum+j]->setGeometry(14+98*j,84+106*i,81,40);
        }
    }

    //快进回退
    ui->frameForwardBack->setGeometry(816,30,194,530);
    ui->frameForwardBackBack->setGeometry(0,0,194,530);
    ui->labelForwardBackTitle->setGeometry(48,13,110,28);
    ui->buttonNeedleIdxImage->setGeometry(23,45,8,25);
    ui->labelNeedleCurAndTotal->setGeometry(50,45,105,28);
    ui->buttonColorIdxImage->setGeometry(20,80,15,20);
    ui->labelColorCurAndTotal->setGeometry(50,75,110,28);
    ui->buttonNeedleBegin->setGeometry(15,120,80,36);
    ui->buttonNeedleDec1->setGeometry(15,170,80,36);
    ui->buttonNeedleDec10->setGeometry(15,220,80,36);
    ui->buttonNeedleDec100->setGeometry(15,270,80,36);
    ui->buttonNeedleDec1000->setGeometry(15,320,80,36);
    ui->buttonNeedleDec10000->setGeometry(15,370,80,36);
    ui->buttonColorDec->setGeometry(15,420,80,36);
    ui->buttonForwardBackOk->setGeometry(16,480,80,36);
    ui->buttonNeedleEnd->setGeometry(102,120,80,36);
    ui->buttonNeedleAdd1->setGeometry(102,170,80,36);
    ui->buttonNeedleAdd10->setGeometry(102,220,80,36);
    ui->buttonNeedleAdd100->setGeometry(102,270,80,36);
    ui->buttonNeedleAdd1000->setGeometry(102,320,80,36);
    ui->buttonNeedleAdd10000->setGeometry(102,370,80,36);
    ui->buttonColorAdd->setGeometry(102,420,80,36);
    ui->buttonForwardBackCancel->setGeometry(102,480,80,36);

    //快捷功能
    ui->frameShortcutFunction->setGeometry(108,36,707,513);
    hNum = 7;//每行7个
    vNum = 4;//总共4行
    for(int i = 0; i < vNum; i++)
    {
        for(int j = 0; j < hNum; j++)
        {
            m_quickBtnList[i*hNum+j]->setGeometry(24+98*j,24+106*i,58,58);
            m_quickLabelList[i*hNum+j]->setGeometry(6+98*j,84+106*i,95,40);//字体显示不全  -rq
        }
    }
    ui->buttonShortCutPgUp->setGeometry(476,460,100,40);
    ui->buttonShortCutPgDn->setGeometry(586,460,100,40);
    ui->labelShortCutPage->setGeometry(376,460,100,40);
}

//初始化窗体控件样式
void MainWidget::initControlStyle()
{
    //上状态栏时间
    ui->labelTime->setFont(fontNormal_6);
    ui->labelTime->setStyleSheet(LABELWHITESTYLE);
    ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Unconnect"));

    //背景透明
    ui->frameUp->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameMainFunction->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameAccessFunction->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameEmbFunction->setStyleSheet(TRANSPARENTSTYLE);
    ui->framePatternSet->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameShortcutFunction->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameParaSet->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameDown->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameEmbInfo->setStyleSheet(TRANSPARENTSTYLE);

    ui->framePatternView->setStyleSheet(TRANSPARENTSTYLE);
    ui->frameFunctionBtn->setStyleSheet(TRANSPARENTSTYLE);
    QString style = "background-color: rgb(246, 242, 239);outline:none;border:0px;border-radius:10px;";
    ui->frameMenuBack->setStyleSheet(style);

    //设置控件图标
    //背景图
    int waterMark = g_pSettings->readFromInHMIiFile("HMI/waterMark").toInt();//是否带水印
    QString backGroundImgPath;
    if(g_emMacType == QUIMACHINE_EMB)
    {
        if(waterMark == 1)
        {
            backGroundImgPath = m_setControlStyle.getBorderImageStyleSheet(this->objectName()+ "_QUI");
        }
        else if(waterMark == 0)
        {
            backGroundImgPath = m_setControlStyle.getBorderImageStyleSheet(this->objectName() + "_NoWaterMarkQUI");
        }
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        if(waterMark == 1)
        {
            backGroundImgPath = m_setControlStyle.getBorderImageStyleSheet(this->objectName());
        }
        else if(waterMark == 0)
        {
            backGroundImgPath = m_setControlStyle.getBorderImageStyleSheet(this->objectName() + "_NoWaterMark");
        }
    }

    ui->frameBack->setStyleSheet(backGroundImgPath);
    if(g_emDebugMode == debugMode)
    {
        ui->labelTitle->setStyleSheet(LABELREDSTYLE);
    }
    else
    {
        ui->labelTitle->setStyleSheet(LABELWHITESTYLE);
    }
    ui->labelTitle->setFont(fontBold_1);

    //主界面灰色花版图
    //获得绘制区域的背景图，用于embdata绘制刷新图形时的背景
    int x = ui->labelPatternView->x() + ui->framePatternView->x();
    int y = ui->labelPatternView->y() + ui->framePatternView->y();
    QImage MainWidgetPix;
    MainWidgetPix.load(getBackImagePath(waterMark));//主界面背景图

    //从主界面背景图截取等于labelPatternView的背景图
    m_embBackPix = QPixmap(ui->labelPatternView->width(),ui->labelPatternView->height());
    m_embBackPix = QPixmap::fromImage(MainWidgetPix.copy(x,y,m_embBackPix.width(),m_embBackPix.height()));

    //状态图标
    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Unconnected"));
    ui->buttonUser->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonUser->objectName()));

    //主功能键图标
    ui->labelMainMenu->setFont(fontNormal_6);
    ui->labelMainMenu->setStyleSheet(LABELWHITESTYLE);
    ui->labelPatternSet->setFont(fontNormal_6);
    ui->labelPatternSet->setStyleSheet(LABELWHITESTYLE);
    ui->labelEmbFunction->setFont(fontNormal_6);
    ui->labelEmbFunction->setStyleSheet(LABELWHITESTYLE);
    ui->labelAccessFunction->setFont(fontNormal_6);
    ui->labelAccessFunction->setStyleSheet(LABELWHITESTYLE);
    ui->labelParaSet->setFont(fontNormal_6);
    ui->labelParaSet->setStyleSheet(LABELWHITESTYLE);
    ui->labelShortcutFunction->setFont(fontNormal_6);
    ui->labelShortcutFunction->setStyleSheet(LABELWHITESTYLE);
    //ui->buttonMainMenu->setCheckedBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonMainMenu->parent()->objectName()));
    ui->buttonMainMenu->setMainBtnBottomStyle();
    ui->buttonMainMenu->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonMainMenu->objectName()));
    ui->buttonPatternSet->setMainBtnBottomStyle();
    ui->buttonPatternSet->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonPatternSet->objectName()));
    ui->buttonEmbFunction->setMainBtnBottomStyle();
    ui->buttonEmbFunction->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonEmbFunction->objectName()));
    ui->buttonAccessFunction->setMainBtnBottomStyle();
    ui->buttonAccessFunction->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonAccessFunction->objectName()));
    ui->buttonParaSet->setMainBtnBottomStyle();
    ui->buttonParaSet->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonParaSet->objectName()));
    ui->buttonShortcutFunction->setMainBtnBottomStyle();
    ui->buttonShortcutFunction->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonShortcutFunction->objectName()));

    //速度加减图标
    ui->lcdNumberSpeed->setFont(fontBold_1);
    ui->lcdNumberSpeed->setStyleSheet(LABELWHITESTYLE);
    ui->buttonSpeedAdd->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonSpeedAdd->objectName()));
    ui->buttonSpeedDec->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonSpeedDec->objectName()));

    //针杆图标
    ui->buttonNeedle->setLabelImage(m_setControlStyle.getStyleSheet(ui->buttonNeedle->objectName()));
    ui->buttonNeedle->setLabelNameFont(fontNormal_6);
    for(int i = 0; i < m_colorBtnList.size(); i++)
    {
        m_colorBtnList.at(i)->setFont(fontNormal_6);
        m_colorBtnList.at(i)->setEnabled(false);
    }
    ui->labelFilename->setFont(fontNormal_6);
    ui->labelFilename->setStyleSheet(LABELGREYSTYLE);
    ui->framePatternInfoImage->setStyleSheet(m_setControlStyle.getStyleSheet(ui->framePatternInfoImage->objectName()));
    ui->buttonPatternInfo->setStyleSheet(TRANSPARENTSTYLE);
    ui->labelX->setFont(fontNormal_6);
    ui->labelX->setStyleSheet(LABELWHITESTYLE);
    ui->labelXValue->setFont(fontNormal_6);
    ui->labelXValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelY->setFont(fontNormal_6);
    ui->labelY->setStyleSheet(LABELWHITESTYLE);
    ui->labelYValue->setFont(fontNormal_6);
    ui->labelYValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelW->setFont(fontNormal_6);
    ui->labelW->setStyleSheet(LABELWHITESTYLE);
    ui->labelWValue->setFont(fontNormal_6);
    ui->labelWValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelH->setFont(fontNormal_6);
    ui->labelH->setStyleSheet(LABELWHITESTYLE);
    ui->labelHValue->setFont(fontNormal_6);
    ui->labelHValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelC->setFont(fontNormal_6);
    ui->labelC->setStyleSheet(LABELWHITESTYLE);
    ui->labelCValue->setFont(fontNormal_6);
    ui->labelCValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelN->setFont(fontNormal_6);
    ui->labelN->setStyleSheet(LABELWHITESTYLE);
    ui->labelNValue->setFont(fontNormal_6);
    ui->labelNValue->setStyleSheet(LABELWHITESTYLE);

    //图形缩放按钮
    //ui->buttonMiddle->setStyleSheet("background-color:rgba(0, 0, 0);border:0px;");
    ui->buttonMiddle->setStyleSheet(TRANSPARENTSTYLE);
    ui->buttonUp->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonUp->objectName()));
    ui->buttonDown->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonDown->objectName()));
    ui->buttonLeft->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonLeft->objectName()));
    ui->buttonRight->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonRight->objectName()));
    ui->buttonAuto->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonAuto->objectName()));
    ui->buttonZoom->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonZoom->objectName()));
    ui->buttonNarrow->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonNarrow->objectName()));

    //绣作信息图标
    ui->labelWorkingTime->setFont(fontNormal_6);
    ui->labelWorkingTime->setStyleSheet(LABELWHITESTYLE);
    ui->buttonWorkingTime->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWorkingTime->objectName()));
    ui->labelNeedleNum->setFont(fontNormal_6);
    ui->labelNeedleNum->setStyleSheet(LABELWHITESTYLE);
    ui->buttonNeedleNum->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonNeedleNum->objectName()));
    ui->labelSpindleAngle->setFont(fontNormal_6);
    ui->labelSpindleAngle->setStyleSheet(LABELWHITESTYLE);
    ui->buttonSpindleAngle->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonSpindleAngle->objectName()));
    ui->labelColorOrder->setFont(fontNormal_6);
    ui->labelColorOrder->setStyleSheet(LABELWHITESTYLE);
    ui->buttonColorOrder->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonColorOrder->objectName()));
    ui->labelNeedleIdx->setFont(fontNormal_6);
    ui->labelNeedleIdx->setStyleSheet(LABELWHITESTYLE);
    ui->progressBarProgress->setAlignment(Qt::AlignCenter);
    ui->progressBarProgress->setStyleSheet(PROGRESSBARSTYLE2);
    ui->progressBarProgress->setFont(fontNormal_6);
    ui->buttonNeedleIdx->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonNeedleIdx->objectName()));
    ui->labelCoorXY->setFont(fontNormal_6);
    ui->labelCoorXY->setStyleSheet(LABELWHITESTYLE);
    ui->labelRelativeCoorXY->setFont(fontNormal_6);
    ui->labelRelativeCoorXY->setStyleSheet(LABELWHITESTYLE);
    ui->buttonCoorXY->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonCoorXY->objectName()));
    ui->buttonRelativeCoorXY->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonRelativeCoorXY->objectName()));

    //匹绣显示区域
    ui->frameMateEmb->setStyleSheet(TRANSPARENTSTYLE);
    QString frameMateEmbBackImgPath = m_setControlStyle.getStyleSheet(ui->frameMateEmbBack->objectName());

    ui->frameMateEmbBack->setStyleSheet(frameMateEmbBackImgPath);
    ui->labelMateEmbShow->setStyleSheet(LABELWHITESTYLE);
    ui->labelMateEmbShow->setFont(fontNormal_6);
    ui->buttonNeedleDown->setWhiteBlueBottomStyle();
    ui->buttonNeedleDown->setFont(fontNormal_6);
    ui->buttonNeedleUp->setWhiteBlueBottomStyle();
    ui->buttonNeedleUp->setFont(fontNormal_6);
    ui->buttonExitMateEmb->setWhiteBlueBottomStyle();
    ui->buttonExitMateEmb->setFont(fontNormal_6);

    //开位线绣显示区域
    ui->frameOpenLineEmb->setStyleSheet(TRANSPARENTSTYLE);
    QString frameOpenLineEmbBackImgPath = m_setControlStyle.getStyleSheet(ui->frameMateEmbBack->objectName());
    ui->frameOpenLineEmbBack->setStyleSheet(frameOpenLineEmbBackImgPath);
    ui->labelOpenLineShow->setStyleSheet(LABELWHITESTYLE);
    ui->labelOpenLineShow->setFont(fontNormal_6);
    ui->labelCoorXYValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelCoorXYValue->setFont(fontNormal_6);
    ui->labelCurNode->setStyleSheet(LABELWHITESTYLE);
    ui->labelCurNode->setFont(fontNormal_6);
    ui->labelCurNodeValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelCurNodeValue->setFont(fontNormal_6);
    ui->labelCoorX->setStyleSheet(LABELWHITESTYLE);
    ui->labelCoorX->setFont(fontNormal_6);
    ui->labelCoorXValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelCoorXValue->setFont(fontNormal_6);
    ui->labelCoorY->setStyleSheet(LABELWHITESTYLE);
    ui->labelCoorY->setFont(fontNormal_6);
    ui->labelCoorYValue->setStyleSheet(LABELWHITESTYLE);
    ui->labelCoorYValue->setFont(fontNormal_6);
    ui->buttonCurCoorXY->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonCoorXY->objectName()));
    ui->buttonPreNode->setWhiteBlueBottomStyle();
    ui->buttonPreNode->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonPreNode->objectName()),4);
    ui->buttonNextNode->setWhiteBlueBottomStyle();
    ui->buttonNextNode->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNextNode->objectName()),4);
    ui->buttonSetNode->setWhiteBlueBottomStyle();
    ui->buttonSetNode->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonSetNode->objectName()),4);
    ui->buttonNodeDelete->setWhiteBlueBottomStyle();
    ui->buttonNodeDelete->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNodeDelete->objectName()),4);
    ui->buttonOpenLineOk->setWhiteBlueBottomStyle();
    ui->buttonOpenLineOk->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonOpenLineOk->objectName()),4);
    ui->buttonOpenLineClose->setWhiteBlueBottomStyle();
    ui->buttonOpenLineClose->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonOpenLineClose->objectName()),4);

    //10个常用快捷按钮
    ui->frameShortcutBtn->setStyleSheet(TRANSPARENTSTYLE);
    for(int i = 0; i < m_shortCutBtnList.size(); i++)
    {
        //界面下方快捷按钮的底图设置，底图和九宫格按钮的底图相同
        m_shortCutBtnList[i]->setBlueBorderBottomStyle();
    }

    //九宫格图标
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_2"));//默认速度等级为2
    if(g_emMacType == MACHINE_EMB)
    {
        ui->buttonNineBtn1->setBlueBorderBottomStyle();
        ui->buttonNineBtn1->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn1->objectName()));
        ui->buttonNineBtn2->setBlueBorderBottomStyle();
        ui->buttonNineBtn2->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn2->objectName()));
        ui->buttonNineBtn3->setBlueBorderBottomStyle();
        ui->buttonNineBtn3->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn3->objectName()));
        ui->buttonNineBtn4->setBlueBorderBottomStyle();
        ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn4->objectName()));
    }
    else if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->buttonNineBtn1->setBlueBorderBottomStyle();
        ui->buttonNineBtn1->setTopImage(m_setControlStyle.getTopStyleSheet("buttonSetStartPoint"));
        ui->buttonNineBtn2->setBlueBorderBottomStyle();
        ui->buttonNineBtn2->setTopImage(m_setControlStyle.getTopStyleSheet("buttonSpindleJog"));//默认主轴点动
        ui->buttonNineBtn3->setBlueBorderBottomStyle();
        ui->buttonNineBtn3->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn3->objectName()));
        ui->buttonNineBtn4->setBlueBorderBottomStyle();
        ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet("buttonBorderCheck"));
    }
    //快进快退
    ui->frameForwardBack->setStyleSheet(TRANSPARENTSTYLE);
    QString frameForwardBackBackImgPath = m_setControlStyle.getStyleSheet(ui->frameForwardBackBack->objectName());

    ui->frameForwardBackBack->setStyleSheet(frameForwardBackBackImgPath);
    ui->labelForwardBackTitle->setFont(fontNormal_6);
    ui->labelForwardBackTitle->setStyleSheet(LABELWHITESTYLE);
    ui->labelColorCurAndTotal->setFont(fontNormal_6);
    ui->labelColorCurAndTotal->setStyleSheet(LABELWHITESTYLE);
    ui->buttonColorIdxImage->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonColorOrder->objectName()));
    ui->labelNeedleCurAndTotal->setFont(fontNormal_6);
    ui->labelNeedleCurAndTotal->setStyleSheet(LABELWHITESTYLE);
    ui->buttonNeedleIdxImage->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonNeedleIdx->objectName()));
    ui->buttonNeedleBegin->setWhiteBlueBottomStyle();
    ui->buttonNeedleBegin->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleBegin->objectName()),4);
    ui->buttonNeedleEnd->setWhiteBlueBottomStyle();
    ui->buttonNeedleEnd->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleEnd->objectName()),4);
    ui->buttonNeedleAdd1->setWhiteBlueBottomStyle();
    ui->buttonNeedleAdd1->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd1->objectName()),4);
    ui->buttonNeedleAdd10->setWhiteBlueBottomStyle();
    ui->buttonNeedleAdd10->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd10->objectName()),4);
    ui->buttonNeedleAdd100->setWhiteBlueBottomStyle();
    ui->buttonNeedleAdd100->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd100->objectName()),4);
    ui->buttonNeedleAdd1000->setWhiteBlueBottomStyle();
    ui->buttonNeedleAdd1000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd1000->objectName()),4);
    ui->buttonNeedleAdd10000->setWhiteBlueBottomStyle();
    ui->buttonNeedleAdd10000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd10000->objectName()),4);
    ui->buttonColorAdd->setWhiteBlueBottomStyle();
    ui->buttonColorAdd->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonColorAdd->objectName()),4);
    ui->buttonNeedleDec1->setWhiteBlueBottomStyle();
    ui->buttonNeedleDec1->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec1->objectName()),4);
    ui->buttonNeedleDec10->setWhiteBlueBottomStyle();
    ui->buttonNeedleDec10->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec10->objectName()),4);
    ui->buttonNeedleDec100->setWhiteBlueBottomStyle();
    ui->buttonNeedleDec100->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec100->objectName()),4);
    ui->buttonNeedleDec1000->setWhiteBlueBottomStyle();
    ui->buttonNeedleDec1000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec1000->objectName()),4);
    ui->buttonNeedleDec10000->setWhiteBlueBottomStyle();
    ui->buttonNeedleDec10000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec10000->objectName()),4);
    ui->buttonColorDec->setWhiteBlueBottomStyle();
    ui->buttonColorDec->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonColorDec->objectName()),4);
    ui->buttonForwardBackOk->setWhiteBlueBottomStyle();
    ui->buttonForwardBackOk->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonForwardBackOk->objectName()),4);
    ui->buttonForwardBackCancel->setWhiteBlueBottomStyle();
    ui->buttonForwardBackCancel->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonForwardBackCancel->objectName()),4);

    //快捷功能图标
    for(int i = 0; i < m_quickLabelList.size(); i++)
    {
        m_quickLabelList[i]->setFont(fontNormal_6);
        //28个快捷按钮的底图相同
        m_quickBtnList[i]->setOrangeGradientBottomStyle(BORDER_RADIUS1);
    }
    ui->buttonShortCutPgUp->setBlueBorderBottomStyle();
    ui->buttonShortCutPgDn->setBlueBorderBottomStyle();
    ui->buttonShortCutPgUp->setFont(fontNormal_6);
    ui->buttonShortCutPgDn->setFont(fontNormal_6);
    ui->labelShortCutPage->setFont(fontNormal_6);
    ui->labelShortCutPage->setStyleSheet(LABELBLACKSTYLE);

    //辅助功能图标
    for(int i = 0; i < m_assistLabelList.size(); i++)
    {
        m_assistLabelList[i]->setFont(fontNormal_6);
        //28个快捷按钮的底图相同
        m_assistBtnList[i]->setOrangeGradientBottomStyle(BORDER_RADIUS1);
    }
    ui->buttonAssistPgUp->setBlueBorderBottomStyle();
    ui->buttonAssistPgDn->setBlueBorderBottomStyle();
    ui->buttonAssistPgUp->setFont(fontNormal_6);
    ui->buttonAssistPgDn->setFont(fontNormal_6);
    ui->labelAssistPage->setFont(fontNormal_6);
    ui->labelAssistPage->setStyleSheet(LABELBLACKSTYLE);

    //花样设置功能图标
    for(int i = 0; i < m_patternSetLabelList.size(); i++)
    {
        m_patternSetLabelList[i]->setFont(fontNormal_6);
        //底图相同
        m_patternSetBtnList[i]->setOrangeGradientBottomStyle(BORDER_RADIUS1);
    }

    //参数设置功能图标
    for(int i = 0; i < m_paraSetLabelList.size(); i++)
    {
        m_paraSetLabelList[i]->setFont(fontNormal_6);
        //底图相同
        m_paraSetBtnList[i]->setOrangeGradientBottomStyle(BORDER_RADIUS1);
    }

    //刺绣功能图标
    for(int i = 0; i < m_embFunctionLabelList.size(); i++)
    {
        m_embFunctionLabelList[i]->setFont(fontNormal_6);
        //底图相同
        m_embFunctionBtnList[i]->setOrangeGradientBottomStyle(BORDER_RADIUS1);
    }

    //下方状态及版本
    ui->progressBar->setStyleSheet(PROGRESSBARSTYLE);
    ui->progressBar->setValue(0);
    ui->labelState->setFont(fontNormal_6);
    ui->labelState->setStyleSheet(LABELREDSTYLE);
    ui->labelNoseHead->setFont(fontNormal_6);
    ui->labelNoseHead->setStyleSheet(LABELWHITESTYLE);
    ui->labelHMIVersion->setFont(fontNormal_6);
    ui->labelHMIVersion->setStyleSheet(LABELWHITESTYLE);
}

//获取背景图的加载路径
QString MainWidget::getBackImagePath(s16 waterMark)
{
    //<分辨率><主题><窗体名称><图片名称>
    QString path = ":/images/";

    //分辨率
    QString str;
    str.clear();
    switch (g_emResolut)
    {
    case resolution1910:
        str = "_1910_logo.png";
        break;
    case resolution1006:
        str = "_1006_logo.png";
        break;
    default:
        break;
    }

    path += this->objectName() + "/" + this->objectName();
    if(waterMark == 0)//无水印
    {
        if(g_emMacType == QUIMACHINE_EMB)
        {
            path += "_NoWaterMarkQUI" + str;
        }
        else if(g_emMacType == MACHINE_EMB)
        {
            path += "_NoWaterMark" + str;
        }

    }
    else
    {
        if(g_emMacType == QUIMACHINE_EMB)
        {
            path += "_QUI" + str;
        }
        else if(g_emMacType == MACHINE_EMB)
        {
           path += str;
        }

    }

    //qDebug()<<path;
    return path;
}

//发送初始化字符串
void MainWidget::sendInitString(QString str)
{
    Qt::Alignment alignment = Qt::AlignHCenter|Qt::AlignBottom; // 设置一个格式
    emit(siSendLoadingMessage(str, alignment, Qt::red));
}

//刷新连接状态(1秒)
void MainWidget::refConnectUi(int alive)
{
    alive = 0;
    refConnectUi(g_pMachine, m_linkSta, alive);
}

//刷新连接状态
void MainWidget::refConnectUi(Machine *pMachine, int &linkSta, int alive)
{
    if(m_ifHMIDecrypt == 0)
    {
        return;
    }

    if(m_connectMode == USE_SERIAL_COMM)//串口连接方式
    {
        if(linkSta != pMachine->isConnected())
        {
            linkSta = pMachine->isConnected();
            if(linkSta == Connected)
            {
                if (pMachine != NULL)
                {
                    //连接后获取机器信息，用于获得剩余可用时间，小于5天主动提示用户
                    //此条语句需放在前面
                    pMachine->getInfoFromMachine();

                    pMachine->getSensorEnBmpFromMachine();//读取传感器信号
                    pMachine->getParasFromMachine();//获取参数
                    m_pMinTimer->start();//1分钟记录一次当前系统时间 ,连接成功以后开启计时器，记录时间 -rq
                    m_pMainWidgetFunction->setShutDownTime();//计算关机时间

                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()));
                    ui->labelState->setText(tr("Connected"));//状态：已连接
                }
            }
            else
            {
                ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Unconnected"));
                ui->labelState->setText(tr("Not connected"));//状态：未连接
            }
        }
    }
    else
    {
        if (pMachine != NULL)
        {
            if (linkSta != pMachine->isConnected() ||
                    pMachine->isConnected() == Connectting ||
                    alive == -1)
            {
                if (alive == -1)
                {
                    linkSta = 0;
                }
                else
                {
                    linkSta = pMachine->isConnected();//获取连接状态
                }

                if (linkSta == Connectting)//连接中...
                {
                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Connecting"));
                    ui->labelState->setText(tr("Connnecting..."));//状态：连接中...
                }
                else if (linkSta == Connected)//已连接
                {
                    //连接后获取机器信息，用于获得剩余可用时间，小于5天主动提示用户
                    //此条语句需放在前面
                    pMachine->getInfoFromMachine();

                    pMachine->getSensorEnBmpFromMachine();//读取传感器信号
                    pMachine->getParasFromMachine();//获取参数
                    m_pMinTimer->start();//1分钟记录一次当前系统时间 ,连接成功以后开启计时器，记录时间 -rq
                    m_pMainWidgetFunction->setShutDownTime();//计算关机时间

                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()));
                    ui->labelState->setText(tr("Connected"));//状态：已连接

                    /***
                界面启动时也会发送最后绣作的花样文件，
                连接成功后也会发送，但连接速度快，此时ds数据可能还没转换完成，
                所以连接成功后发送文件可能不成功，只是界面加载时会发送文件，
                因此二者不会重复发送文件；若断开连接再连接时此段代码会发送文件，
                界面加载部分不会发送；
                ***/
                    QByteArray ds16dat = g_pCurEmbData->getDsDat();//获得ds16数据
                    //如果当前所选文件路径不为空与ds16数据不为空时
                    if(m_curFilePath.length() > 0 && ds16dat.size() > 0)
                    {
                        //m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
                        //设置为按进度执行模式
                        //g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度
                    }
                }
                else//未连接
                {
                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Unconnected"));
                    ui->labelState->setText(tr("Not connected"));//状态：未连接
                }
            }
        }
    }
}

//隐藏菜单栏(frame)
void MainWidget::hideMenuFrame()
{
    ui->frameMenuBack->setVisible(false);
    ui->framePatternView->setVisible(false);
    setZoomMoveBtnVisible(false);
    ui->frameShortcutBtn->setVisible(false);
    ui->framePatternSet->setVisible(false);
    ui->frameParaSet->setVisible(false);
    ui->frameEmbFunction->setVisible(false);
    ui->frameAccessFunction->setVisible(false);
    ui->frameShortcutFunction->setVisible(false);

    //设置按钮为非选中状态
    ui->buttonPatternSet->setChecked(false);
    ui->buttonPatternSet->setCheckable(false);
    ui->buttonEmbFunction->setChecked(false);
    ui->buttonEmbFunction->setCheckable(false);
    ui->buttonAccessFunction->setChecked(false);
    ui->buttonAccessFunction->setCheckable(false);
    ui->buttonParaSet->setChecked(false);
    ui->buttonParaSet->setCheckable(false);
    ui->buttonShortcutFunction->setChecked(false);
    ui->buttonShortcutFunction->setCheckable(false);
    ui->buttonMainMenu->setChecked(false);
    ui->buttonMainMenu->setCheckable(false);
}

void MainWidget::setZoomMoveBtnVisible(bool bVal)
{
    ui->buttonUp->setVisible(bVal);
    ui->buttonDown->setVisible(bVal);
    ui->buttonLeft->setVisible(bVal);
    ui->buttonRight->setVisible(bVal);
    ui->buttonAuto->setVisible(bVal);
    ui->buttonZoom->setVisible(bVal);
    ui->buttonNarrow->setVisible(bVal);

    if(bVal)
    {
        ui->labelFilename->setVisible(false);
        ui->frameColor->setVisible(false);
        ui->framePatternInfo->setVisible(false);
        ui->progressBarProgress->setVisible(false);
    }
    else
    {
        ui->labelFilename->setVisible(true);
        ui->frameColor->setVisible(true);
        ui->framePatternInfo->setVisible(true);
        ui->progressBarProgress->setVisible(true);
    }
}

bool MainWidget::resetAllData()
{
    //设置颜色
    //    m_colorTable = g_pCurEmbData.getColorTable();
    //    m_showColorIdxBegin = 0;
    //    m_curSelectColor = -1;
    //    refreshShowColor();

    m_forwardBackNeedleIdx = 0;
    m_forwardBackColorIdx = 0;
    setZoomMoveBtnVisible(false);
    ui->frameForwardBack->setVisible(false);

    g_pCurEmbData->getDsDat();

#if(1)
    //当为绗绣机时
    if(g_emMacType == QUIMACHINE_EMB)
    {
        bool bl = g_pCurEmbData->checkFirstEndNeedle();
        if(bl == false)//提示花版错误，不可绣作
        {
            PromptDialog promptDlg(this);
            promptDlg.initDialog(PromptDialog::BTN_OK);
            promptDlg.setTitleStr(tr("Prompt"));
            QString str;
            //花版X向错误，不可绣作，请改版！
            str = tr("Pattern X direction error, cannot be embroidered, please revise!");
            promptDlg.setContentStr(str);

            promptDlg.exec();
            m_curFilePath.clear();
            setPatternSetBtnEnable(false);

            return false;
        }
    }
#endif

    //qDebug()<<"setDs16ColorOfTable begin";
    //转换为ds16数据后设置色序表
    g_pCurEmbData->setDs16ColorOfTable(m_fileHead.switchTable);
    //qDebug()<<"setDs16ColorOfTable end";

    g_pCurEmbData->setEmbData();// ds16数据转换为画图数据

    //加载图片的进度条显示
    ui->progressBar->setVisible(true);
    int value = g_pCurEmbData->getStitchNums() / TENTHOUSANDNEEDLE;
    ui->progressBar->setRange(1,value);
    ui->progressBar->setValue(1);

    m_dispMode = EmbData::DISP_ALL_EXEC;
    g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 重新画图
    m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
    g_pCurEmbData->setDispMode(m_dispMode, 0,m_gradientFlag);    // 设置为按进度执行模式

    m_curColorIdx = 0;
    m_curDatIdx = 0;

    ui->buttonNeedle->setLabelName(QString("%1").arg(0));  // 当前色序显示置为0
    refreshShowColorUi();

    ui->framePatternView->setVisible(true);
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);

    //刷新花样信息
    double width = g_pCurEmbData->getDatWidth()*0.01;
    ui->labelWValue->setText(QString("%1").arg(width));

    double height = g_pCurEmbData->getDatHeight()*0.01;
    ui->labelHValue->setText(QString("%1").arg(height));

    //起始点
    double xPos = g_pCurEmbData->m_beginX*0.01;
    ui->labelXValue->setText(QString("%1").arg(xPos));

    double yPos = g_pCurEmbData->m_beginY*0.01;
    ui->labelYValue->setText(QString("%1").arg(yPos));

    ui->labelCValue->setText(QString::number(g_pCurEmbData->getColorNums()));
    ui->labelNValue->setText(QString::number(g_pCurEmbData->getStitchNums()));

    ui->labelWorkingTime->setText("0:0");
    QTextCodec *cod = QTextCodec::codecForLocale();
    ui->labelSpindleAngle->setText(cod->toUnicode("0°"));
    ui->labelColorOrder->setText(QString::number(m_curColorIdx+1));
    ui->labelNeedleIdx->setText(QString::number(m_curDatIdx));
    ui->progressBarProgress->setMaximum(g_pCurEmbData->getStitchNums());//进度条最大值
    ui->progressBarProgress->setMinimum(0);
    ui->progressBarProgress->setValue(m_curDatIdx);
    //qDebug()<<"m_curDatIdx"<<m_curDatIdx;
    ui->labelCoorXY->setText("(0,0)");
    ui->labelCoorXYValue->setText("(0,0)");
    ui->labelRelativeCoorXY->setText("(0,0)");

    ui->progressBar->setVisible(false);
    return true;
}

void MainWidget::refreshShowColorUi()
{
    QString btnStyle1 = "QPushButton{border:0px solid rgb(80,80,80);border-style:inset;border-radius:5px;";
    QString btnStyle2 = "QPushButton:checked{border:2px solid rgb(80,80,80);}";

    QString str;

    QRgb *pColorBuf;
    pColorBuf = (QRgb *)(g_pSettings->getColorRgbArray().data());

    QByteArray colorTable = g_pCurEmbData->getColorTable();//色序表 第一个色序用毛巾的第几个针杆
    int colorNum = colorTable.size();

    int colorIdx  = m_showColorIdxBegin;
    if(colorIdx < 0)
    {
        colorIdx = 0;
    }

    for (int i = 0; i < m_colorBtnList.size(); i++)
    {
        // 颜色显示
        if (colorIdx < colorNum)
        {
            int needleIdx = colorTable.at(colorIdx);//色序表里第几个
            QString idxStr;
            idxStr.clear();
            if(needleIdx > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM +RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM+SAWTOOTH_NEEDLE_NUM+REV3_NEEDLE_NUM)//激光针杆
            {
                needleIdx -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM+SAWTOOTH_NEEDLE_NUM+REV3_NEEDLE_NUM);
                idxStr = "LaserNeedle/"+QString::number(needleIdx)+"_coloridx";
            }
            else if(needleIdx > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM +RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM)//锯齿针杆
            {
                needleIdx -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM);
                idxStr = "SawtoothNeedle/"+QString::number(needleIdx)+"_coloridx";
            }
            else if(needleIdx > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM +RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM)//缠绕针杆
            {
                needleIdx -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM);
                idxStr = "CoilNeedle/"+QString::number(needleIdx)+"_coloridx";
            }
            else if(needleIdx > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM +RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM)//链式针杆
            {
                needleIdx -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM);
                idxStr = "TowelNeedle/"+QString::number(needleIdx)+"_coloridx";
            }
            else if(needleIdx > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM)//毛巾针杆
            {
                needleIdx -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM);
                idxStr = "TowelNeedle/"+QString::number(needleIdx)+"_coloridx";
            }
            else if(needleIdx > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM+SEW_NEEDLE_NUM)//盘带针杆
            {
                needleIdx -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM+SEW_NEEDLE_NUM);
                idxStr = "RibbonNeedle/"+QString::number(needleIdx)+"_coloridx";
            }
            else//绣花针杆
            {
                idxStr = "EmbNeedle/"+QString::number(needleIdx)+"_coloridx";
            }

            int colorInTab;
            if(g_pSettings->ifKeyExists(idxStr) == true)
            {
                colorInTab = g_pSettings->readFromIniFile(idxStr).toInt();
            }
            else
            {
                colorInTab = colorTable.at(colorIdx);
                if(colorInTab > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM+SAWTOOTH_NEEDLE_NUM+REV3_NEEDLE_NUM)//激光针杆
                {
                    colorInTab -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM +SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM+SAWTOOTH_NEEDLE_NUM+REV3_NEEDLE_NUM);
                }
                else if(colorInTab > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM)//锯齿针杆
                {
                    colorInTab -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM +SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM+COIL_NEEDLE_NUM+REV2_NEEDLE_NUM);
                }
                else if(colorInTab > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM)//缠绕针杆
                {
                    colorInTab -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM +SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM+CHAIN_NEEDLE_NUM);
                }
                else if(colorInTab > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM)//链式针杆
                {
                    colorInTab -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM +SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM+TOWEL_NEEDLE_NUM);
                }
                else if(colorInTab > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM)//毛巾针杆
                {
                    colorInTab -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM +SEW_NEEDLE_NUM+RIBBON_NEEDLE_NUM);
                }
                else if(colorInTab > EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM + SEW_NEEDLE_NUM)//盘带针杆
                {
                    colorInTab -= (EMB_NEEDLE_NUM + PUNCH_NEEDLE_NUM +SEW_NEEDLE_NUM);
                }
                colorInTab -= 1;
                if(colorInTab < 0){colorInTab = 0;}
            }

            // 文件中的色序
            QRgb rgb = pColorBuf[(colorInTab % EMB_BF_SW_ND)];
            rgb |= 0xff000000;
            QColor bkcolor(rgb);
            QColor tcolor = QColor(255-bkcolor.red(), 255-bkcolor.green(), 255-bkcolor.blue()).lighter(168);
            QString cstyle = btnStyle1 + "background-color:" + bkcolor.name() + ";"
                    + " color:" + tcolor.name() + ";}" + btnStyle2;

            m_colorBtnList.at(i)->setStyleSheet(cstyle);

            str.sprintf("%d", colorIdx+1);
            m_colorBtnList.at(i)->setText(str);
            m_colorBtnList.at(i)->show();

            //选择显示
            if (colorIdx == m_curColorIdx || colorIdx == 0)//等于当前正在绣作的颜色
            {
                QString buttonStyle = "background-color:" + bkcolor.name() + ";" + "border-radius:10px;";
                ui->buttonNeedle->setBtnBackColor(buttonStyle);
                QString labelStyle = "color:" + tcolor.name() + ";";
                ui->buttonNeedle->setLabelNameStyle(labelStyle);
                m_colorBtnList.at(i)->setCheckable(true);
                m_colorBtnList.at(i)->setChecked(true);
            }
        }
        else
        {
            m_colorBtnList.at(i)->hide();
        }

        colorIdx++;
    }
}

//刷新开位线绣节点信息
int MainWidget::refreshOpenLineInfo()
{
    if(m_nodeList.size() < m_nodeIdx+1)
    {
        return -1;
    }

    double nodeX = m_nodeList[m_nodeIdx].nodeX*0.01;
    double nodeY = m_nodeList[m_nodeIdx].nodeY*0.01;
    QString xStr = QString("%1").arg(nodeX);
    QString yStr = QString("%1").arg(nodeY);
    ui->labelCoorXValue->setText(xStr);
    ui->labelCoorYValue->setText(yStr);
    ui->labelCurNodeValue->setText(QString::number(m_nodeIdx+1));

    return 0;
}

//花样选择
void MainWidget::patternSelect()
{
    //m_pMainWidgetFunction->setShutDownTime();//计算关机时间
    //选择新花样前将上一花样的断线次数保存到参数配置文件中
    if(m_curFilePath.length() > 0)
    {
        m_pMainWidgetFunction->setPatternHeadConfig(m_curFilePath,m_fileHead);
    }

    //获得花样选择的图标字符
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNSELECT)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

            break;
        }
    }

    m_pPatternSelectWi->setTypeLogo(tStyle);
    m_pPatternSelectWi->setMainTitle(tr("Pattern selection"));
    m_pPatternSelectWi->setSubTitle(tr("Pattern setting > Pattern selection"));

    m_pPatternSelectWi->createCurDirPatterns();
    m_pPatternSelectWi->show();

    //showPatternPreview();
}

//色序设定
void MainWidget::patternColorSet()
{
    //获得花样色序设定的图标字符
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

            break;
        }
    }

    m_pColorOrderSetWi->setTypeLogo(tStyle);
    m_pColorOrderSetWi->setMainTitle(tr("Color order set"));//色序设定
    m_pColorOrderSetWi->setSubTitle(tr("Pattern setting > Color order set"));//花样设置 > 色序设定

    QByteArray colortab;
    colortab.clear();
    colortab.append((char*)(m_fileHead.switchTable),sizeof(m_fileHead.switchTable));//头文件的色序表

    m_pColorOrderSetWi->setColorTable(colortab,m_fileHead.combineMode);//双头组合，设置色序表
    m_pColorOrderSetWi->setThreeColorTable(colortab,m_fileHead.threeCombineMode);//三头组合，设置色序表
    m_pColorOrderSetWi->initHeadBuf(m_curFilePath);
    m_pColorOrderSetWi->show(m_curFilePath);
    //showPatternPreview();
}

//毛巾高度设定
void MainWidget::patternTowelHeightSet()
{
    //获得花样色序设定的图标字符
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_TOWELHEIGHT)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

            break;
        }
    }

    m_pColorOrderSetWi->setTypeLogo(tStyle);
    m_pColorOrderSetWi->setMainTitle(tr("Towel high set"));//毛巾高度设定
    m_pColorOrderSetWi->setSubTitle(tr("Pattern setting > Towel high set"));//花样设置 > 毛巾高度设定
    m_pColorOrderSetWi->setTowelHighTable(m_towelHeightTable);//设置高度表
    m_pColorOrderSetWi->showTowelHeight(m_curFilePath);
}

void MainWidget::patternRepeatEmbSet(QString style)
{
    m_pParameterSetDlg->setTypeLogo(style);
    m_pParameterSetDlg->setMainTitle(tr("Repeated emb setting"));//反复绣
    m_pParameterSetDlg->setSubTitle(tr("Repeated emb"));//反复绣参数
    //反复绣参数-用于下位机
    m_pParameterSetDlg->setItemList(operate,PARA_TYPE_REPEATEMBPARA);

    u32 para1 = 0;
    u32 para2 = 0;
    u32 val = 0;
    ParaStruct mcParaValues;
    if(g_pMachine != NULL)
    {
        mcParaValues = g_pMachine->getMcPara();
        val = mcParaValues.buf[15];
        para1 = val>>8 & 0x01;//反复启动方式 bit 8
        para2 = val>>12 & 0x01;//反复绣起绣点是否暂停 bit 12
    }
    m_pParameterSetDlg->setItemValue(SET_MC_REPETITIONPARA1,para1);           //反复启动方式
    m_pParameterSetDlg->setItemValue(SET_MC_REPETITIONPARA2,para2);           //反复绣起绣点是否暂停

    //得到花样参数
    DataFileHead fileHead;
    memset(&fileHead,0,sizeof(DataFileHead));
    m_pMainWidgetFunction->getPatternHeadConfig(m_curFilePath,fileHead);
    m_pParameterSetDlg->setItemValue(SET_MC_PRIORITY,fileHead.mcPriority);           //优先次序
    m_pParameterSetDlg->setItemValue(SET_MC_XREPEATNUM,fileHead.mcXRepeatNum);       //X向反复次数
    m_pParameterSetDlg->setItemValue(SET_MC_YREPEATNUM,fileHead.mcYRepeatNum);       //Y向反复次数
    m_pParameterSetDlg->setItemValue(SET_MC_XREPEATSPACE,fileHead.mcXRepeatSpace);   //X向反复间距
    m_pParameterSetDlg->setItemValue(SET_MC_YREPEATSPACE,fileHead.mcYRepeatSpace);   //Y向反复间距

    //读取参数,并刷新界面
    if(m_pParameterSetDlg->exec() == 1)
    {
        m_fileHead.mcPriority = m_pParameterSetDlg->getItemValue(SET_MC_PRIORITY);          //优先次序
        m_fileHead.mcXRepeatNum = m_pParameterSetDlg->getItemValue(SET_MC_XREPEATNUM);      //X向反复次数
        m_fileHead.mcYRepeatNum = m_pParameterSetDlg->getItemValue(SET_MC_YREPEATNUM);      //Y向反复次数
        m_fileHead.mcXRepeatSpace = m_pParameterSetDlg->getItemValue(SET_MC_XREPEATSPACE);  //X向反复间距
        m_fileHead.mcYRepeatSpace = m_pParameterSetDlg->getItemValue(SET_MC_YREPEATSPACE);  //Y向反复间距

        para1 = m_pParameterSetDlg->getItemValue(SET_MC_REPETITIONPARA1);
        para2 = m_pParameterSetDlg->getItemValue(SET_MC_REPETITIONPARA2);

        u32 bitval1 = 0x01;
        u32 bitval2 = 0x01;
        bitval1 <<= 8;//0001 0000 0000
        bitval2 <<= 12;//0001 0000 0000 0000
        if (para1 == 0)
        {
           val &= ~bitval1;
        }
        else
        {
            val |= bitval1;
        }
        if (para2 == 0)
        {
            val &= ~bitval2;
        }
        else
        {
           val |= bitval2;
        }
        u32 value = val;
        if(g_pMachine != NULL)
        {
            g_pMachine->setAMcPara(15+1, value);
        }

        //将反复绣设置写入文件头-用于下位机
        if(g_pCurEmbData != NULL)
        {
            g_pCurEmbData->setMcRepeatEmb(m_fileHead);
        }
        m_pMainWidgetFunction->setPatternHeadConfig(m_curFilePath,m_fileHead);//写入fcg
        m_pMainWidgetFunction->sendPatternHead(m_curFilePath);

        if(g_pMachine != NULL)
        {
            g_pMachine->getParasFromMachine();//获取参数
        }
    }
}

void MainWidget::reSetPatternData()
{
    g_pCurEmbData->setEmbData(0);
    m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
    g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 设置为按进度执行模式

#if(0)
    g_pCurEmbData->setEmbData(0);
    m_dispMode = EmbData::DISP_ALL_EXEC;
    g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 重新画图
    m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
    g_pCurEmbData->setDispMode(m_dispMode, 0,m_gradientFlag);    // 设置为按进度执行模式
#endif
}

//显示机器运行状态中的信息
void MainWidget::showExecInfo()
{
    // 速度
    if (m_curRpm != (int)m_mcStatus.runSpeed)        // 运行速度
    {
        m_curRpm = (int)m_mcStatus.runSpeed;
        QString str;
        str.sprintf("%d", m_curRpm);
        ui->lcdNumberSpeed->display(str);
    }

    // 色序
    if (m_curColorIdx != (int)m_mcStatus.colorIdx)    // 当前色序(从0开始)
    {
        m_curColorIdx = (int)m_mcStatus.colorIdx;	 // 色序编码
        ui->labelColorOrder->setText(QString("%1").arg(m_curColorIdx + 1));
        m_showColorIdxBegin = m_curColorIdx;
        refreshShowColorUi();
    }

    if(m_dispMode == EmbData::DISP_EXECING)//不是执行状态，重置
    {
        // 文件执行进度(当前针数) labelNeedleIdx
        if (m_curDatIdx != (int)m_mcStatus.dataIdx)
        {
            m_curDatIdx = (int)m_mcStatus.dataIdx;
            reSetDatIdx(m_curDatIdx);
            QPixmap patternPix = g_pCurEmbData->getPreviewImage();
            ui->labelPatternView->setPixmap(patternPix);
        }
    }

    // 当前xy绝对坐标
    double xPos = 0;
    double yPos = 0;
    double xRelPos = 0;
    double yRelPos = 0;
    QString xyStr;  // 当前xy绝对坐标
    QString xyRelStr; // 当前xy相对坐标
    if(m_stepDrive == 1)//有步进驱动
    {
        xPos = (s32)m_mcStatus.xPos*0.1;
        yPos = (s32)m_mcStatus.yPos*0.1;
        xyStr.sprintf("(%.1f, %.1f)", xPos, yPos);

        xRelPos = ((int)m_mcStatus.xPos - m_pMainWidgetFunction->getBeginX())*0.1;
        yRelPos = ((int)m_mcStatus.yPos - m_pMainWidgetFunction->getBeginY())*0.1;
        xyRelStr.sprintf("(%.1f, %.1f)", xRelPos, yRelPos);
    }
    else
    {
        xPos = (s32)m_mcStatus.xPos*0.01;
        yPos = (s32)m_mcStatus.yPos*0.01;
        xyStr.sprintf("(%.2f, %.2f)", xPos, yPos);

        xRelPos = ((int)m_mcStatus.xPos - m_pMainWidgetFunction->getBeginX())*0.01;
        yRelPos = ((int)m_mcStatus.yPos - m_pMainWidgetFunction->getBeginY())*0.01;
        xyRelStr.sprintf("(%.2f, %.2f)", xRelPos, yRelPos);
    }

    ui->labelCoorXY->setText(xyStr);// 当前xy绝对坐标
    ui->labelCoorXYValue->setText(xyStr);//开位线绣
    ui->labelRelativeCoorXY->setText(xyRelStr); // 当前xy相对坐标

    // 主轴角度
    QTextCodec *cod = QTextCodec::codecForLocale();
    QString angleStr;
    angleStr.sprintf("%.2f",(float)(m_mcStatus.embSpindleAngle*0.01));
    angleStr += cod->toUnicode("°");
    ui->labelSpindleAngle->setText(angleStr);

    // 机器运行总时长
    int totalTime = m_mcStatus.workTimer;
    int hour,min;
    if(totalTime > 60) //大于60分钟
    {
        hour = totalTime / 60;
        min = totalTime % 60;
    }
    else
    {
        hour = 0;
        min = totalTime;
    }
    ui->labelWorkingTime->setText(QString("%1:%2").arg(hour).arg(min));

    // 当前针杆
    //        if(m_mcStatus.needleIdx >= 0)
    //        {
    //            ui->labelNeedleNum->setText(QString("%1").arg(m_mcStatus.needleIdx));
    //            ui->buttonNeedle->setLabelName(QString("%1").arg(m_mcStatus.needleIdx));
    //        }
    //        else
    //        {
    //            ui->labelNeedleNum->setText("0");
    //        }

    ui->labelNeedleNum->setText(QString::number(m_mcStatus.needleIdx));
    if(m_mcStatus.needleIdx == 0)
    {
        ui->labelNeedleNum->setText("0");
    }
    if(m_mcStatus.needleIdx >0)
    {
        ui->buttonNeedle->setLabelName(QString("%1").arg(m_mcStatus.needleIdx));
    }

    //主轴角度
    if((m_mcStatus.showSta & 1) == 0)//在位
    {
        ui->buttonSpindleAngle->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonSpindleAngle->objectName()+"ZP"));
    }
    else//不在位
    {
        ui->buttonSpindleAngle->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonSpindleAngle->objectName()));
    }
    //当前工作机头
    if(m_mcStatus.workNoseHead > 0)
    {
        m_workNoseHead =m_mcStatus.workNoseHead;//m_workNoseHead从主控中读到的机头
        if(m_workNoseHead == 1)  //平绣机头
        {
            if(g_emMacType == QUIMACHINE_EMB)//绗绣机
            {
                double num = (m_mcStatus.outCounter)/10.0;
                ui->labelNoseHead->setText(tr("Production statistics:")+QString::number(num,'f',1)+tr("cm"));//产量统计:单位cm
            }
            else
            {
                ui->labelNoseHead->setText(tr("Work Nose Head:Emb shead"));
            }
        }
        else if(m_workNoseHead == 2) // 毛巾机头
        {
            ui->labelNoseHead->setText(tr("Work Nose Head:Chenille head"));
        }
        else if(m_workNoseHead == 3) // 缠绕机头
        {
            ui->labelNoseHead->setText(tr("Work Nose Head:Coil head"));
        }
    }
    else
    {
        ui->labelNoseHead->setText(tr("Work Nose Head:Unknown"));
    }
}

//void MainWidget::switchActiveFile(int newActive, int force)
//{

//}

void MainWidget::showPatternPreview()
{
    hideMenuFrame();
    QFile curfile(m_curFilePath);
    if(m_curFilePath.length() <= 0 ||
            (!curfile.exists()))//未选择文件时不显示颜色和花样信息
    {
        ui->framePatternView->setVisible(false);
    }
    else
    {
        ui->framePatternView->setVisible(true);
        ui->labelPatternView->setVisible(true);//非预览模式绘制区域
        ui->labelPatternPreView->setVisible(false);//预览模式绘制区域
    }
    if(g_emMacType == QUIMACHINE_EMB)
    {
         ui->frameShortcutBtn->setVisible(false);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
          ui->frameShortcutBtn->setVisible(true);
    }

    //主界面按钮选中
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

//设置常用按钮
void MainWidget::setCommonBtn()
{
    QPoint point;
    point.setX(0);
    point.setY(0);

    qDebug()<<"setCommonBtn";

    for(int i = 0; i < m_shortCutBtnList.size(); i++)//窗体下方的快捷按钮列表 10个
    {
        int commonBtnIdx = g_pSettings->readFromIniFile("HMI/commonbtn"+QString::number(i+1)).toInt();
        QString btnStyle;
        if(commonBtnIdx == FUN_NULL )
        {
            btnStyle = "buttonAddCommonFunctions";
        }
        else
        {
            btnStyle = getCommonBtnStyle(commonBtnIdx);//根据按钮索引找到对应按钮的图片名称
        }
        qDebug()<<"commonBtnIdx"<<commonBtnIdx;
        qDebug()<<"btnStyle"<<btnStyle;
        m_shortCutBtnList[i]->setShortCutTopImage(m_setControlStyle.getTopStyleSheet(btnStyle),point);

        //快进快退等功能不可用
        if(
                commonBtnIdx == FUN_FORWARDORBACK ||//快进快退
                commonBtnIdx == FUN_SETSTARTEMBPOINT ||//定起绣点
                commonBtnIdx == FUN_BACKSTARTEMBPOINT ||//回起绣点
                commonBtnIdx == FUN_CHECKFRAME ||//边框检查
                commonBtnIdx == FUN_BACKWORKPOINT //回工作点
                )
        {
            if(m_curFilePath.length() <= 0)//未选择文件快进快退等按钮不可用
            {
                m_shortCutBtnList[i]->setEnabled(false);
            }
        }
    }
}

//设置UI界面按钮的使能
void MainWidget::setUiBtnEnable(bool bValue)
{
    ui->frameMainFunction->setEnabled(bValue);

    ui->buttonNeedle->setEnabled(bValue);
    ui->buttonPatternInfo->setEnabled(bValue);
    ui->buttonMiddle->setEnabled(bValue);
    if(g_emMacType == QUIMACHINE_EMB)//因为绗绣机九宫格第一个变成全部归零，所以一直可以使用
    {
        ui->frameShortcutBtn->setEnabled(false);//下方快捷按钮
        ui->buttonNineBtn1->setEnabled(true);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
        ui->frameShortcutBtn->setEnabled(bValue);
        ui->buttonNineBtn1->setEnabled(bValue);
    }
    ui->buttonNineBtn2->setEnabled(bValue);
    ui->buttonNineBtn3->setEnabled(bValue);
    ui->buttonNineBtnUp->setEnabled(bValue);
    ui->buttonNineBtnDown->setEnabled(bValue);
    ui->buttonNineBtnLeft->setEnabled(bValue);
    ui->buttonNineBtnRight->setEnabled(bValue);
    //ui->buttonNineBtnMiddle->setEnabled(bValue);
}

//设置花样操作按钮的使能，如快进快退等
void MainWidget::setPatternSetBtnEnable(bool bValue)
{
    //花样参数、花样色序不可按
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
        {
            m_patternSetBtnList[i]->setEnabled(bValue);
        }
    }

    //隔头绣、贴布绣、边框刺绣等不可按
    for(int i = 0; i < m_embFunctionItemList.size(); i++)
    {
        if(m_embFunctionItemList[i].m_enumFunction == EMBFUN_HEADEMB ||
                m_embFunctionItemList[i].m_enumFunction == EMBFUN_PATCHEMB ||
                m_embFunctionItemList[i].m_enumFunction == EMBFUN_BORDEREMB ||
                m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINE ||
                m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINECHECK ||
                m_embFunctionItemList[i].m_enumFunction == EMBFUN_LINEOFFSET ||
                m_embFunctionItemList[i].m_enumFunction == EMBFUN_REPEATED )
        {
            m_embFunctionBtnList[i]->setEnabled(bValue);
        }
    }

    for(int i = 0; i < m_quickItemList.size(); i++)
    {
        int enumFun = m_quickItemList[i].m_enumFunction;
        if(enumFun == FUN_FORWARDORBACK ||//快进快退
                enumFun == FUN_SETSTARTEMBPOINT ||//定起绣点
                enumFun == FUN_BACKSTARTEMBPOINT ||//回起绣点
                enumFun == FUN_CHECKFRAME ||//边框检查
                enumFun == FUN_BACKWORKPOINT //回工作点
                )
        {
            m_quickBtnList[i]->setEnabled(bValue);
        }
    }

    for(int i = 0; i < m_shortCutBtnList.size(); i++)//窗体下方的快捷按钮列表 10个
    {
        int commonBtnIdx = g_pSettings->readFromIniFile("HMI/commonbtn"+QString::number(i+1)).toInt();
        //快进快退等功能不可用
        if(    commonBtnIdx == FUN_FORWARDORBACK ||//快进快退
               commonBtnIdx == FUN_SETSTARTEMBPOINT ||//定起绣点
               commonBtnIdx == FUN_BACKSTARTEMBPOINT ||//回起绣点
               commonBtnIdx == FUN_CHECKFRAME ||//边框检查
               commonBtnIdx == FUN_BACKWORKPOINT //回工作点
               )
        {
            m_shortCutBtnList[i]->setEnabled(bValue);
        }
    }

    if(g_emMacType == QUIMACHINE_EMB)
    {
        ui->buttonNineBtn1->setEnabled(true);
    }
    else if(g_emMacType == MACHINE_EMB)
    {
    	ui->buttonNineBtn1->setEnabled(bValue);
    }
}

void MainWidget::reSetDatIdx(int newidx)
{
    int totalStitchNum = g_pCurEmbData->getStitchNums();

    if (newidx <= 0)
    {
        m_curDatIdx = 0;         // 当前执行进度
    }
    else if (newidx >= totalStitchNum)
    {
        m_curDatIdx = m_curDatIdx - 1;         // 当前执行进度
    }

    // 文件idx信息
    QString str;
    str.sprintf("%d", m_curDatIdx);
    ui->labelNeedleIdx->setText(str);
    ui->progressBarProgress->setValue(m_curDatIdx+1);//最后一针是结束码

    // 更新进度显示
    g_pCurEmbData->setExecIndex(m_curDatIdx);
}

//前进回退
void MainWidget::funForwardOrBack()
{
    bool bl = ui->labelPatternPreView->isVisible();//显示灰度图的控件

    //显示主界面
    hideMenuFrame();
    setUiBtnEnable(false);
    showPatternPreview();
    m_forwardBackNeedleIdx = m_curDatIdx;
    addOrDecNeedleIdx(m_curDatIdx);
    m_forwardBackColorIdx = m_expara.newColorIdx;
//    m_forwardBackColorIdx = m_curColorIdx;

    if(bl == true || m_dispMode == EmbData::DISP_ALL_NORMAL)//预览区域显示时隐藏掉并重置绘图数据且此时预览功能不可用
    {
        setZoomMoveBtnVisible(false);
        g_pCurEmbData->setDrawMode(EmbData::DRAW_VIEW);//非预览模式
        g_pCurEmbData->setViewInfo(m_embBackPix);
        g_pCurEmbData->setEmbData();//ds16数据转换为画图数据

        m_dispMode = EmbData::DISP_ALL_EXEC;
        g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 重新画图

        m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
        g_pCurEmbData->setDispMode(m_dispMode, 0,m_gradientFlag);       // 设置为按进度执行模式
    }

    g_pCurEmbData->setExecIndex(m_forwardBackNeedleIdx);// 更新进度显示

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);

    int totalStitchNum = g_pCurEmbData->getStitchNums();
    QString strNeedle;
    strNeedle.sprintf("%d/%d",m_forwardBackNeedleIdx,totalStitchNum);
    ui->labelNeedleCurAndTotal->setText(strNeedle);

    int totalColorNum = g_pCurEmbData->getColorNums();
    QString strColor;
    if(m_forwardBackNeedleIdx == 0)
    {
        strColor.sprintf("%d/%d",0,totalColorNum);
    }
    else
    {
        strColor.sprintf("%d/%d",m_forwardBackColorIdx,totalColorNum);
    }
    ui->labelColorCurAndTotal->setText(strColor);

    ui->frameForwardBack->setVisible(true);
    ui->frameForwardBack->raise();
}

void MainWidget::addOrDecNeedleIdx(int &idx)
{
    if( g_pMachine == NULL || 0 )
    {
        return;
    }

    if(idx < 0)
    {
        idx = 0;
    }

    int totalColorNum = g_pCurEmbData->getColorNums();//总颜色数
    int totalStitchNum = g_pCurEmbData->getStitchNums();//总针数
    if(idx > totalStitchNum)
    {
        idx = totalStitchNum;
    }

    memset(&m_expara,0,sizeof(FileExecPara));

    int posx, posy, posr, cidx;
    g_pCurEmbData->getPosInfoFromNeedleIdx(idx, posx, posy, posr, cidx);

    m_expara.newIdx = idx;
    m_expara.newXPos = posx;
    m_expara.newYPos = posy;
    m_expara.newRPos = posr;
    m_expara.newColorIdx = cidx;

    m_forwardBackColorIdx = cidx;

    QString strNeedle;
    strNeedle.sprintf("%d/%d",idx,totalStitchNum);
    ui->labelNeedleCurAndTotal->setText(strNeedle);

    QString strColor;
    if(idx == 0)
    {
        strColor.sprintf("%d/%d",0,totalColorNum);
    }
    else
    {
        strColor.sprintf("%d/%d",cidx,totalColorNum);
    }

    ui->labelColorCurAndTotal->setText(strColor);

    //画执行进度图
    g_pCurEmbData->setExecIndex(idx);// 更新针数

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);
}

void MainWidget::addOrDecColorIdx(int &idx,s16 flag)
{
    if( g_pMachine == NULL || 0 )
    {
        return;
    }

    if(flag == 1)
    {
        if(idx < 1)
        {
            idx = 1;
        }
    }
    else if(flag == -1)
    {
        if(idx < 0)
        {
            idx = 0;
        }
    }

    int totalStitchNum = g_pCurEmbData->getStitchNums();//总针数
    int totalColorNum = g_pCurEmbData->getColorNums();//总颜色数

    if(idx > totalColorNum)
    {
        idx = totalColorNum;
        return;
    }

    memset(&m_expara,0,sizeof(FileExecPara));

    int posx, posy, posr, cidx;
    g_pCurEmbData->getPosInfoFromColorIdx(cidx, posx, posy, posr, idx);

    m_expara.newIdx = cidx;
    m_expara.newXPos = posx;
    m_expara.newYPos = posy;
    m_expara.newRPos = posr;
    m_expara.newColorIdx = idx;

    m_forwardBackNeedleIdx = cidx;

    QString strNeedle;
    strNeedle.sprintf("%d/%d",cidx,totalStitchNum);
    ui->labelNeedleCurAndTotal->setText(strNeedle);

    QString strColor;
    strColor.sprintf("%d/%d",idx,totalColorNum);//显示为颜色索引减1
    ui->labelColorCurAndTotal->setText(strColor);

    //画执行进度图
    g_pCurEmbData->setExecIndex(cidx);// 更新针数

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);
}

//获取常用按钮样式
QString MainWidget::getCommonBtnStyle(int idx)
{
    QString styleStr;
    //检测快捷按钮条目
    for(int i = 0; i < m_quickItemList.size(); i++)//快捷功能中的快捷条目列表
    {
        int enumFun = m_quickItemList[i].m_enumFunction;
        if(idx == enumFun)//功能索引等于快捷按钮功能索引
        {
            //获取顶层图标样式表
            styleStr = m_quickItemList[i].m_topImageName;
            break;
        }
    }

    if(idx == FUN_PATTERNSELECT)//功能索引等于花样选择
    {
        //获得花样选择的图标字符
        for(int i = 0; i < m_patternSetItemList.size(); i++)
        {
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNSELECT)
            {
                styleStr = m_patternSetItemList[i].m_topImageName;
                break;
            }
        }
    }

    if(idx == FUN_PRODUCTSTATIS)//功能索引等于生产统计
    {
        //获得生产统计的图标字符
        for(int i = 0; i < m_assistItemList.size(); i++)
        {
            if(m_assistItemList[i].m_enumFunction == ASSIST_PRODUCTSTATICS)
            {
                styleStr = m_assistItemList[i].m_topImageName;
                break;
            }
        }
    }

    return styleStr;
}

void MainWidget::runCommonBtnFunction(int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }

    switch (idx)
    {
    case FUN_ALLTOZERO://全部归零
        m_pMainWidgetFunction->funAllToZero();
        break;
    case FUN_FLATEMBHOOK://平绣勾线
        m_pMainWidgetFunction->funFlatEmbHook();
        break;
    case FUN_SPINDLEJOG://主轴点动（平绣，毛巾）
        m_pMainWidgetFunction->funSpindleJog();
        break;
    case FUN_SPINDLEROTATE://主轴旋转
        m_pMainWidgetFunction->funSpindleRotate();
        break;
    case FUN_BACKWORKPOINT://回工作点
        m_pMainWidgetFunction->funBackWorkPoint();
        break;
    case FUN_BACKTOORIGIN://回原点
        m_pMainWidgetFunction->funBackToOrigin();
        break;
    case FUN_SETOFFSETPOINT://定偏移点
        m_pMainWidgetFunction->funSetOffsetPoint();
        break;
    case FUN_BACKOFFSETPOINT://回偏移点
        m_pMainWidgetFunction->funBackOffsetPoint();
        break;
    case FUN_SETSTARTEMBPOINT://定起绣点
    {
        m_pMainWidgetFunction->funSetStartPoint(m_curFilePath);
        double xPos = g_pCurEmbData->m_beginX*0.01;
        ui->labelXValue->setText(QString("%1").arg(xPos));
        double yPos = g_pCurEmbData->m_beginY*0.01;
        ui->labelYValue->setText(QString("%1").arg(yPos));
    }
        break;
    case FUN_BACKSTARTEMBPOINT://回起绣点
        m_pMainWidgetFunction-> funBackStartPoint();
        break;
    case FUN_CHECKFRAME://边框检查
        m_pMainWidgetFunction->funBorderCheck();
        break;
    case FUN_MANUALTRIM://平绣，毛巾剪线
        m_pMainWidgetFunction->funManualTrim();
        break;
    case FUN_CUTOPENANDCLOSE://下剪线
        m_pMainWidgetFunction->funCutterOpenAndClose();
        break;
    case FUN_MANUALCHANGECOLOR://手动（平绣,毛巾）换色
        m_pMainWidgetFunction->funManualChangeColor();
        break;
    case FUN_SWITCHHEAD:   //切换机头
        m_pMainWidgetFunction->funSwitchHead();
        break;
    case FUN_MS_ROTATE:   //M轴旋转
        m_pMainWidgetFunction->funMSpindleRotate();
        break;
    case FUN_CHENWORKAREA:   // 毛巾设置可工作区域
    {
        if (m_pSetWorkAreaWi != NULL)
        {
            m_pSetWorkAreaWi->setTitleStr(tr("Chenille setting workable area"));
            m_pSetWorkAreaWi->setHead(TOWEL);
            m_pSetWorkAreaWi->show();
        }
    }
        break;
    case FUN_EMBWORKAREA:   //平绣设置可工作区域
    {
        if (m_pSetWorkAreaWi != NULL)
        {
            m_pSetWorkAreaWi->setTitleStr(tr("Flat embroidery setting workable area"));
            m_pSetWorkAreaWi->setHead(FLATEMB);
            m_pSetWorkAreaWi->show();
        }
    }
        break;
    case FUN_COILWORKAREA:   //缠绕设置可工作区域
    {
        if (m_pSetWorkAreaWi != NULL)
        {
            m_pSetWorkAreaWi->setTitleStr(tr("Coil embroidery setting workable area"));
            m_pSetWorkAreaWi->setHead(COIL);
            m_pSetWorkAreaWi->show();
        }
    }
        break;
    case FUN_ONOFF://缠绕下剪线
        m_pMainWidgetFunction->funCoilCutterOpenAndClose();
        break;
    case FUN_THREAD://缠绕剪线
        m_pMainWidgetFunction->funCoilManualTrim();
        break;
    case FUN_COIL_MS_JOG://缠绕主轴点动
        m_pMainWidgetFunction->funCoilSpindleJog();
        break;
    case FUN_SPINDLE_TO_ANGLE://缠绕主轴旋转
        m_pMainWidgetFunction->funCoilSpindleRotate();
        break;
    case FUN_LEFTSEQUINCHANGECOLOR://左亮片换色
        m_pMainWidgetFunction->funSequinChangeColor(0);
        break;
    case FUN_TOWELCHANGECOLOR://毛巾换色
        m_pMainWidgetFunction->funTowelChangeColor();
        break;
        //    case FUN_RIGHTSEQUINCHANGECOLOR://右亮片换色
        //        m_pMainWidgetFunction->funSequinChangeColor(1);
        //        break;
    case FUN_FORWARDORBACK://前进回退
        funForwardOrBack();
        break;
    case FUN_QUANTITYMOVEFRAME://定量移框
        m_pMainWidgetFunction->funQuantityMoveFrame();
        break;
    case FUN_NEEDLERODPOSITION://针杆定位
        m_pMainWidgetFunction->funNeedleRodPosition();
        break;
    case FUN_SIMULATEFRAME://空走边框
        m_pMainWidgetFunction->funSimulateFrame();
        break;
    case FUN_TOWELCABLE://毛巾拉线
        m_pMainWidgetFunction->funTowelCable();
        break;
    case FUN_PROCESSRESET://流程复位
        m_pMainWidgetFunction->funProcessReset();
        break;
    case FUN_SETFEEDINGPOINT://定上料点
        m_pMainWidgetFunction->funSetFeedPoint();
        break;
    case FUN_BACKFEEDINGPOINT://回上料点
        m_pMainWidgetFunction->funBackFeedPoint();
        break;
    case FUN_MANUALOIL://手动加油
        m_pMainWidgetFunction->funManualOil();
        break;

    case FUN_RESETREPEATNUM://重置反复次数
        m_pMainWidgetFunction->funResetRepeatNum();
        break;

    case FUN_SHUTTLECOUNT://梭盘计数复位
        m_pMainWidgetFunction->funShuttleChange();
        break;
    case FUN_PATTERNSELECT://花样选择
        patternSelect();
        break;
    case FUN_PRODUCTSTATIS://生产统计
    {
        s16 index = 0;
        for(int i = 0; i < m_assistItemList.size(); i++)
        {
            if(m_assistItemList[i].m_enumFunction == ASSIST_PRODUCTSTATICS)
            {
                index = i;
                break;
            }
        }
        QString topImageName = m_assistItemList[index].m_topImageName;
        //加载按钮顶图图标
        QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

        int patternBreakLineNum = m_fileHead.breakLineParkNum;//花样断线停车次数
        m_pMainWidgetFunction->funProductStatistics(tStyle,m_curFilePath,patternBreakLineNum);
    }
        break;
    default:
        break;
    }
}

//执行辅助按钮功能
void MainWidget::runAssistBtnFunction(int funEnum,int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }

    QString topImageName = m_assistItemList[idx].m_topImageName;
    //加载按钮顶图图标
    QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

    switch (funEnum)
    {
    case ASSIST_SENSOR://传感器信号
    {
        if (m_pSensorInputWi != NULL)
        {
            //注释掉此行代码，因为获取位图下位机会返回全on的状态，
            //会使传感器界面闪一下，在连接后读取了一下，这里不再读取
            //g_pMachine->getSensorEnBmpFromMachine();
            g_pMachine->entrySensorScan();

            m_pSensorInputWi->setTypeLogo(tStyle);
            m_pSensorInputWi->setMainTitle(tr("Sensor signal"));
            m_pSensorInputWi->setSubTitle(tr("Auxiliary function > Sensor signal"));
            m_pSensorInputWi->show();
        }
    }
        break;

    case ASSIST_CONTROLACTION://控制动作
    {
        if (m_pControlActionWi != NULL)
        {
            m_pControlActionWi->setTypeLogo(tStyle);
            m_pControlActionWi->setMainTitle(tr("Control action"));
            m_pControlActionWi->setSubTitle(tr("Auxiliary function > Control action"));

            m_pControlActionWi->refreshUi();
            m_pControlActionWi->show();
        }
    }
        break;

    case ASSIST_HMIUPGRADE://界面升级
    {
        if(g_emDebugMode == nodebugMode)
        {
            if(g_emUser != repair)//权限不够先登录
            {
                m_pMainWidgetFunction->slotUserLogin(repair);
                if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                    return;
            }
            if(m_pMainWidgetFunction != NULL)
            {
                m_pMainWidgetFunction->funHMIUpgrade(tStyle);
            }
        }
        else
        {
            if(m_pMainWidgetFunction != NULL)
            {
                m_pMainWidgetFunction->funHMIUpgrade(tStyle);
            }
        }
    }
        break;

    case ASSIST_MCUPGRADE://主控升级
    {
        if(g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                return;
        }

        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funMCUpgrade(tStyle);
        }
    }
        break;

    case ASSIST_EXBUPGRADE://外围板升级
    {
        if(g_emDebugMode == nodebugMode)
        {
            if(g_emUser != repair)//权限不够先登录
            {
                m_pMainWidgetFunction->slotUserLogin(repair);
                if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                    return;
            }
            m_pParameterSetDlg->setTypeLogo(tStyle);
            m_pParameterSetDlg->setMainTitle(tr("EXB Upgrade"));
            m_pParameterSetDlg->setSubTitle(tr("Accessibility > EXB Upgrade"));

            //外围板升级参数
            m_pParameterSetDlg->setItemList(factory,PARA_TYPE_EXBUPGRADE);
            m_pParameterSetDlg->exec();
        }
        else
        {
            m_pParameterSetDlg->setTypeLogo(tStyle);
            m_pParameterSetDlg->setMainTitle(tr("EXB Upgrade"));
            m_pParameterSetDlg->setSubTitle(tr("Accessibility > EXB Upgrade"));

            //外围板升级参数
            m_pParameterSetDlg->setItemList(factory,PARA_TYPE_EXBUPGRADE);
            m_pParameterSetDlg->exec();
        }
    }
        break;

    case ASSIST_PARAIMPORT://参数导入
    {
        if(g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;//就不执行下边的代码，不显示界面
            }
        }
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funImportParameter(tStyle);
        }
    }
        break;

    case ASSIST_PARAEXPORT://参数导出
    {
        if(g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        g_pMachine->getInfoFromMachine();
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funExportParameter();
        }
    }
        break;

    case ASSIST_SOFTWARESET://软件设置
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Accessibility"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Software setting"));
        //软件设置参数
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_SOFTWARESET);
        m_pParameterSetDlg->setItemValue(SET_THEME,g_emTheme);     //主题
        int language = g_pSettings->readFromInHMIiFile("HMI/language").toInt();
        m_pParameterSetDlg->setItemValue(SET_LANGUAGE,language);  //语言
        int fontsize=0;
        if(g_emMacType == QUIMACHINE_EMB)
        {
             fontsize=larger;
            //绗绣机只用10寸屏,强制使用大字体，不写入配置文件
        }
        else if(g_emMacType == MACHINE_EMB)
        {
            fontsize = g_pSettings->readFromInHMIiFile("HMI/fontsize").toInt();
        }
        m_pParameterSetDlg->setItemValue(SET_FONTSIZE,fontsize);  //字体大小

        //        int connectMode = g_pSettings->readFromIniFile("HMI/connectMode").toInt();
        //        m_pParameterSetDlg->setItemValue(SET_CONNECTMODE,connectMode);  //连接通讯方式

        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_AUTHORIZATION://软件授权
    {
        m_pMainWidgetFunction->funSoftwareAuthor();
    }
        break;

    case ASSIST_NETWORK://网络管理
    {
        if(g_emUser != factory)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(factory);
            if(g_emUser != factory && g_emUser != root)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Accessibility"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Network Manage"));

        //网络管理参数
        //添加相应主板数的IP参数
        m_pParameterSetDlg->setNetworkItemList(PARA_TYPE_NETWORKSET);
        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_WIFI:
    {
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funWIFI(tStyle);
        }
    }
        break;

    case ASSIST_NEEDLESET://针杆设置
    {
        if(g_emDebugMode == nodebugMode)
        {
            if(g_emUser != repair)//权限不够先登录
            {
                m_pMainWidgetFunction->slotUserLogin(repair);
                if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                {
                    return;
                }
            }
            m_pNeedleBarSetWi->setTypeLogo(tStyle);
            m_pNeedleBarSetWi->setMainTitle(tr("Needle setting"));
            m_pNeedleBarSetWi->setSubTitle(tr("Accessibility > Needle setting"));
            m_pNeedleBarSetWi->refreshTypeBtnShow();//刷新右上方按钮的显示,包括选中状态
            m_pNeedleBarSetWi->initNeedleBar();
            m_pNeedleBarSetWi->show();
        }
        else
        {
            m_pNeedleBarSetWi->setTypeLogo(tStyle);
            m_pNeedleBarSetWi->setMainTitle(tr("Needle setting"));
            m_pNeedleBarSetWi->setSubTitle(tr("Accessibility > Needle setting"));
            m_pNeedleBarSetWi->refreshTypeBtnShow();//刷新右上方按钮的显示,包括选中状态
            m_pNeedleBarSetWi->initNeedleBar();
            m_pNeedleBarSetWi->show();
        }
    }
        break;

    case ASSIST_TIMESET://时间设置
    {
        //得到当前时间
        QDateTime time;
        time = QDateTime::currentDateTime();//获取系统现在的时间

        QString yearStr = time.currentDateTime().toString("yyyy");
        QString monthStr = time.currentDateTime().toString("MM");
        QString dayStr = time.currentDateTime().toString("dd");
        QString hourStr = time.currentDateTime().toString("hh");
        QString minuteStr = time.currentDateTime().toString("mm");
        QString secondStr = time.currentDateTime().toString("ss");

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Time setting"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Time setting"));
        //时间设置参数
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_TIMESET);
        m_pParameterSetDlg->setItemValue(1,yearStr.toInt());   //年
        m_pParameterSetDlg->setItemValue(2,monthStr.toInt());   //月
        m_pParameterSetDlg->setItemValue(3,dayStr.toInt());   //日
        m_pParameterSetDlg->setItemValue(4,hourStr.toInt());   //时
        m_pParameterSetDlg->setItemValue(5,minuteStr.toInt());   //分
        m_pParameterSetDlg->setItemValue(6,secondStr.toInt());   //秒

        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_SHORTCUTSET://常用设置
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Common functions setting"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Common functions setting"));
        //常用功能设置
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_COMMONFUN);
        for(int i = 0; i < m_shortCutBtnList.size(); i++)//下方按钮
        {
            //读取配置文件获取功能索引
            int commonBtnIdx = g_pSettings->readFromIniFile("HMI/commonbtn"+QString::number(i+1)).toInt();
            m_pParameterSetDlg->setItemValue(i+1,commonBtnIdx);
        }

        if(m_pParameterSetDlg->exec() == 1)//点了 确认
        {
            g_pSettings->writeToIniFile("HMI/theme",theme1);
            for(int i = 0; i < m_shortCutBtnList.size(); i++)//窗体下方的快捷按钮列表
            {
                //将功能索引写入配置文件
                int commonBtnIdx = m_pParameterSetDlg->getItemValue(i+1);
                g_pSettings->writeToIniFile("HMI/commonbtn"+QString::number(i+1),commonBtnIdx);

                //1920x1080分辨率下设置图标居中
                QPoint point;
                point.setX(0);
                point.setY(0);

                if(g_emResolut == resolution1910)
                {
                    point.setX(5);
                    point.setY(5);
                }

                if(commonBtnIdx == FUN_NULL)//无功能
                {
                    QString btnStyle = "buttonAddCommonFunctions";
                    m_shortCutBtnList[i]->setShortCutTopImage(m_setControlStyle.getTopStyleSheet(btnStyle),point);
                    m_shortCutBtnList[i]->setVisible(true);
                }
                else
                {
                    //设置常用功能按钮顶图图标
                    QString btnStyle = getCommonBtnStyle(commonBtnIdx);
                    m_shortCutBtnList[i]->setShortCutTopImage(m_setControlStyle.getTopStyleSheet(btnStyle),point);
                    m_shortCutBtnList[i]->setVisible(true);
                }
            }
        }
    }
        break;

    case ASSIST_PRODUCTSTATICS://生产统计
    {
        int patternBreakLineNum = m_fileHead.breakLineParkNum;//花样断线停车次数
        m_pMainWidgetFunction->funProductStatistics(tStyle,m_curFilePath,patternBreakLineNum);
    }
        break;


    case ASSIST_ERRORLOG://错误日志
    {
        if(g_emDebugMode == nodebugMode)
        {
            if(g_emUser != repair)//权限不够先登录
            {
                m_pMainWidgetFunction->slotUserLogin(repair);
                if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                    return;
            }
            if(m_pMainWidgetFunction != NULL)
            {
                m_pMainWidgetFunction->funJournalError(tStyle);
            }
        }
        else
        {
            if(m_pMainWidgetFunction != NULL)
            {
                m_pMainWidgetFunction->funJournalError(tStyle);
            }
        }
    }
        break;

    case ASSIST_MCVERSION://N1版本信息
    {
        g_pMachine->getInfoFromMachine();
        m_pMainWidgetFunction->funGetMCVersionInfo();
    }
        break;

    case ASSIST_EXBVERSION://外围板信息
    {
        g_pMachine->getExboardInfoFromMachine();
        m_pMainWidgetFunction->funGetEXBVersionInfo(tStyle);
    }
        break;

    case ASSIST_BOTTOMLINEDETECT://底线检测(平绣)
    {
        m_pMainWidgetFunction->funBottomDetect(FLATEMB);
    }
        break;

    case ASSIST_FACELINEDETECT://面线检测(平绣)
    {
        m_pMainWidgetFunction->funFaceDetect(FLATEMB);
    }
        break;
    case ASSIST_COILBOTTOMLINEDETECT://底线检测(缠绕)
    {
        m_pMainWidgetFunction->funBottomDetect(COIL);
    }
        break;

    case ASSIST_COILFACELINEDETECT://面线检测(缠绕)
    {
        m_pMainWidgetFunction->funFaceDetect(COIL);
    }
        break;

    case ASSIST_SPINDLETEST://主轴研车(试机)
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Spindle test"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Spindle test"));

        //超级用户参数
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_SPINDLETEST);
        if(m_pParameterSetDlg->exec() == 1)
        {
            s32 para1 = m_pParameterSetDlg->getItemValue(1);
            s32 para2 = m_pParameterSetDlg->getItemValue(2);

            if(g_pMachine != NULL)
            {
                g_pMachine->embSpindleTest(para1,para2);
            }
        }
    }
        break;
    case ASSIST_TOWELDEBUG://毛巾调试
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Chenille Debug"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Chenille Debug"));

        //超级用户参数
        m_pParameterSetDlg->setItemList(factory,PARA_TYPE_TOWELDEBUG);
        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_CHANGEASHUTTLE:    //自动换一个梭
        m_pMainWidgetFunction->funChangeOneShuttle();
        break;

    case ASSIST_MSPINDLE_TO_ANGLE:    //缠绕M轴去指定角度
        m_pMainWidgetFunction->funCoilMSpindleRotate();
        break;

    case ASSIST_SEQUINDEBUG://亮片参数
        m_pParameterSetDlg->setTypeLogo(tStyle);//设置logo
        m_pParameterSetDlg->setMainTitle(tr("Sequin Parameters"));//亮片参数
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Sequin Parameters"));

        //机器参数和工作参数
        //加载参数列表(筛选出亮片的参数)
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK,MC_SORT_DOUBLE_SEQUIN);
        //读取参数,并刷新界面
        m_pParameterSetDlg->exec();
        break;

    case ASSIST_ROOT://超级用户
    {
        if(g_emDebugMode == nodebugMode)
        {
            if(g_emUser != factory && g_emUser != root)//超级用户
            {
                m_pMainWidgetFunction->slotUserLogin(factory);
            }
            if(g_emUser == factory)
            {
                m_pParameterSetDlg->setTypeLogo(tStyle);
                m_pParameterSetDlg->setMainTitle(tr("Root"));
                m_pParameterSetDlg->setSubTitle(tr("Accessibility > Root"));
                //超级用户参数
                m_pParameterSetDlg->setItemList(factory,PARA_TYPE_ROOT);
                m_pParameterSetDlg->exec();
            }
            else if (g_emUser == root)
            {
                m_pParameterSetDlg->setTypeLogo(tStyle);
                m_pParameterSetDlg->setMainTitle(tr("Root"));
                m_pParameterSetDlg->setSubTitle(tr("Accessibility > Root"));
                //超级用户参数
                m_pParameterSetDlg->setItemList(root,PARA_TYPE_ROOT);
                m_pParameterSetDlg->exec();
            }
        }
        else
        {
            m_pParameterSetDlg->setTypeLogo(tStyle);
            m_pParameterSetDlg->setMainTitle(tr("Root"));
            m_pParameterSetDlg->setSubTitle(tr("Accessibility > Root"));
            //超级用户参数
            m_pParameterSetDlg->setItemList(root,PARA_TYPE_ROOT);
            m_pParameterSetDlg->exec();
        }
    }
        break;

    case ASSIST_BOTTOMLINECOUNTRESET://底线计数复位                     lxs20220630添加,快捷功能放不下了
    {
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funBottomLineCountReset();
        }
    }
        break;

    case ASSIST_DEBUGINFO:    //调试信息
        m_pMainWidgetFunction->funDebugInfo();
        break;
    case ASSIST_SHUTDOWN:    //关机
        m_pMainWidgetFunction->funShutDown();
        break;

    default:
        break;
    }
}

//执行花样设置按钮功能
void MainWidget::runPatternSetBtnFunction(int funEnum, int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }

    QString topImageName = m_patternSetItemList[idx].m_topImageName;
    //加载按钮顶图图标
    QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);
    QString bStyle = m_setControlStyle.getBottomStyleSheet(ui->buttonAssist1->parent()->objectName());

    switch (funEnum)
    {
    case PATTERNSET_PATTERNSELECT://花样选择
        patternSelect();
        break;

    case PATTERNSET_PATTERNPARA://花样参数
        //showPatternPreview();
        slotShowPatternPara(m_curFilePath);
        break;

    case PATTERNSET_PATTERNCOLOR://花样色序
    {
        patternColorSet();
    }
        break;

    case PATTERNSET_TOWELHEIGHT://毛巾高度
    {
        patternTowelHeightSet();
    }
        break;

    case PATTERNSET_PATTERNIMPORT://花样导入
    {
        m_pPatternManageWi->setTypeLogo(tStyle);
        m_pPatternManageWi->setMainTitle(tr("Pattern import"));
        m_pPatternManageWi->setSubTitle(tr("Pattern setting > Pattern import"));

        PatternManageWidget::MANAGE_MODE mode = PatternManageWidget::MANAGE_IMPORT;

        QSize size = m_pPatternSelectWi->getImageSize();
        m_pPatternManageWi->setImportImageSize(size);
        m_pPatternManageWi->patternManage(mode);
    }
        break;

    case PATTERNSET_PATTERNEXPORT://花样导出
    {
        if(g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        m_pPatternManageWi->setTypeLogo(tStyle);
        m_pPatternManageWi->setMainTitle(tr("Pattern export"));
        m_pPatternManageWi->setSubTitle(tr("Pattern setting > Pattern export"));

        PatternManageWidget::MANAGE_MODE mode = PatternManageWidget::MANAGE_EXPORT;
        m_pPatternManageWi->patternManage(mode);
    }
        break;

    case PATTERNSET_PATTERNDELETE://花样删除
    {
        if(g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        m_pPatternManageWi->setTypeLogo(tStyle);
        m_pPatternManageWi->setMainTitle(tr("Pattern delete"));
        m_pPatternManageWi->setSubTitle(tr("Pattern setting > Pattern delete"));

        PatternManageWidget::MANAGE_MODE mode = PatternManageWidget::MANAGE_DELETE;
        m_pPatternManageWi->patternManage(mode);
    }
        break;

    default:
        break;
    }

}

//执行刺绣功能按钮功能
void MainWidget::runEmbFunctionBtnFunction(int funEnum, int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }

    QString topImageName = m_embFunctionItemList[idx].m_topImageName;
    //加载按钮顶图图标
    QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

    switch (funEnum)
    {
    case EMBFUN_BORDEREMB:
    {
        if(m_curFilePath.length() <= 0){return;}
        QFile file(m_curFilePath);
        if(!file.exists()){return;}//文件不存在

        PromptDialog promptDlg;
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Border embroidery"));//边框刺绣

        QString str;
        str = tr("Do you want to embroider borders?The machine will move after pulling the rod, please pay attention to safety!");//是否进行边框刺绣?拉杆后机器将运动，请注意安全!
        promptDlg.setContentStr(str);

        if(promptDlg.exec() == 1)
        {
            if(g_pCurEmbData == NULL)
            {
                return;
            }

            m_borderEmb = 1;
            QString filePath = g_pCurEmbData->createBorderEmbData(m_curFilePath); // 生成花样边框数据
            m_preFilePath = m_curFilePath;
            slotShowPatternPara(filePath,-1);
        }
    }
        break;

    case EMBFUN_MATEEMB:
        hideMenuFrame();
        showPatternPreview();

        ui->frameMateEmb->setVisible(true);
        ui->frameMateEmb->raise();//置于顶层

        setUiBtnEnable(false);
        ui->buttonNineBtn4->setEnabled(false);//锁界面不可用

        ui->buttonNineBtnUp->setEnabled(true);
        ui->buttonNineBtnDown->setEnabled(true);
        ui->buttonNineBtnLeft->setEnabled(true);
        ui->buttonNineBtnRight->setEnabled(true);
        ui->buttonNineBtnMiddle->setEnabled(true);
        m_pMainWidgetFunction->slotCalMachineProgress(CSV_00_CODE_7);
        break;

    case EMBFUN_HEADEMB:
    {
        if (g_emMacType == MACHINE_EMB )               //绣花机
        {
            m_pMainWidgetFunction->funHeadEmb(m_curFilePath);
        }
        else
        {
            m_pMainWidgetFunction->funQuiHeadEmb(m_curFilePath);
        }
    }
        break;

    case EMBFUN_PATCHEMB:
    {
        if(m_curFilePath.length() <= 0){return;}
        QFile file(m_curFilePath);
        if(!file.exists()){return;}//文件不存在

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Patch embroider setting"));//贴布绣设置
        m_pParameterSetDlg->setSubTitle(tr("Patch embroider setting < Embroidery function"));//贴布绣设置 < 贴布绣功能

        //贴布绣参数
        int colorNum = g_pCurEmbData->getColorNums();//获取颜色数
        int totalNeedle = g_pCurEmbData->getStitchNums();//总针数
        m_pParameterSetDlg->setPatchItemList(PARA_TYPE_PATTERNPATCH_COLOR|PARA_TYPE_PATTERNPATCH_NEEDLE,totalNeedle,colorNum,m_curFilePath);

        if( m_pParameterSetDlg->exec() == 1)
        {
            u16 patchColorBuf[PATCHCOLORBUF];
            memset(patchColorBuf,0,sizeof(patchColorBuf));
            memcpy(patchColorBuf,m_pParameterSetDlg->getPatchColorParaBuf(),sizeof(patchColorBuf));

            NeedlePatch patchNeedleBuf[PATCHNEEDLEBUF];
            memset(patchNeedleBuf,0,sizeof(patchNeedleBuf));
            memcpy(patchNeedleBuf,m_pParameterSetDlg->getPatchNeedleParaBuf(),sizeof(patchNeedleBuf));

            m_pMainWidgetFunction->funSendPatchEmb(m_curFilePath,patchColorBuf,patchNeedleBuf);
        }
    }
        break;

    case EMBFUN_OPENLINEEMB:
        hideMenuFrame();
        showPatternPreview();

        ui->frameOpenLineEmb->setVisible(true);
        ui->frameOpenLineEmb->raise();//置于顶层

        setUiBtnEnable(false);
        ui->buttonNineBtn4->setEnabled(false);//锁界面不可用

        ui->buttonNineBtnUp->setEnabled(true);
        ui->buttonNineBtnDown->setEnabled(true);
        ui->buttonNineBtnLeft->setEnabled(true);
        ui->buttonNineBtnRight->setEnabled(true);
        ui->buttonNineBtnMiddle->setEnabled(true);

        refreshOpenLineInfo();
        break;

    case EMBFUN_OUTLINE://花样轮廓
    {
        if(m_curFilePath.length() <= 0)
        {
            return;
        }

        QFile file(m_curFilePath);
        if(!file.exists()){return;}//文件不存在

        QString tStyle = m_setControlStyle.getTopStyleSheet(ui->buttonPatternSet->objectName());

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Pattern outline para"));//花样轮廓参数
        m_pParameterSetDlg->setSubTitle(tr("Pattern outline para < Pattern outline setting"));//花样轮廓参数 < 花样轮廓设置
        //绣花花样轮廓参数
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERNOUTLINE);

        if(m_pParameterSetDlg->exec() == 1)//花样轮廓参数设置确定
        {
            emit siCounterPrompt(0);

            //花样轮廓参数
            int outlineStep = m_pParameterSetDlg->getItemValue(SET_OUTLINESTEP);    //轮廓针步
            int outlineZoom = m_pParameterSetDlg->getItemValue(SET_OUTLINEZOOM);    //轮廓放大
            int outlineShape = m_pParameterSetDlg->getItemValue(SET_OUTLINESHAPE);  //轮廓形状
            g_pCurEmbData->createPatternOutlineFile(outlineStep,outlineZoom,outlineShape); // 生成花样轮廓

            emit siCounterPrompt(1);
        }
    }
        break;

    case EMBFUN_OUTLINECHECK:     //轮廓刺绣
    {
        if(m_curFilePath.length() <= 0)
        {
            return;
        }

        //g_pCurEmbData->createPatternOutlineFile(ui->labelPatternPreView->pixmap()->toImage(),m_curFilePath);

        PromptDialog promptDlg1;
        promptDlg1.initDialog(PromptDialog::BTN_OK);
        promptDlg1.setTitleStr(tr("Pattern outline"));//花样轮廓
        QString str1;
        str1 = tr("The pattern contour file has been generated!");//花样轮廓文件已生成!
        promptDlg1.setContentStr(str1);
        promptDlg1.exec();

        ///////////////////////////////////////////
        QString oldCurFilePath = m_curFilePath;   //.dst

        QDir apppath(qApp->applicationDirPath());
        QFileInfo fileInfo(m_curFilePath);
        QString fileName = fileInfo.fileName();
        fileName = fileName.mid(0,fileName.length()-4);//将后缀过滤掉
        //当前选择的花样轮廓路径
        QString  curOutLineFilePath = apppath.path() + apppath.separator() + "datafiles" + apppath.separator() + fileName + "-outLine.dsr";
        if(curOutLineFilePath.length() <= 0){return;}
        QFile file(curOutLineFilePath);
        if(!file.exists()){return;}//文件不存在

        m_curFilePath = curOutLineFilePath; //OutLine.dst

        PromptDialog promptDlg;
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("OutLine embroidery"));//轮廓刺绣

        QString str;
        str = tr("Do you want to outLine embroidery?The machine will move after pulling the rod, please pay attention to safety!");//是否进行轮廓刺绣?拉杆后机器将运动，请注意安全!
        promptDlg.setContentStr(str);

        if(promptDlg.exec() == 1)
        {
            if(g_pCurEmbData == NULL)
            {
                return;
            }

            QString str = ui->labelFilename->text() + " - " + tr("OutLineEmb");//轮廓刺绣
            ui->labelFilename->setText(str);

            //从aa.OutLine.dst  的花版转换成的OutLine.dst  的ds16
            slotSetPatternData();//设置花样数据并显示   //得到aa.OutLine的ds16数据还未发送

            //起绣点和机头用aa.dst的
            int st = 1;
            s32 oldX,oldY;
            u32 oldWorkNoseHead;
            oldX = oldY = 0;
            oldWorkNoseHead =0;
            if(g_pMachine != NULL)
            {
                m_mcStatus = g_pMachine->getMcStatus();
                oldX = m_mcStatus.xPos;
                oldY = m_mcStatus.yPos;
                oldWorkNoseHead = m_mcStatus.workNoseHead;
            }

            if(g_pCurEmbData != NULL)
            {
                g_pCurEmbData->setStartPosition(oldX,oldY,st,oldWorkNoseHead);
                //改变中间数据（ds16）的头文件
            }

            m_pMainWidgetFunction->sendPatternData(m_curFilePath,FILE_TYPE_FRAME);//发送轮廓刺绣数据
            //设置为按进度执行模式
            g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度

            m_curFilePath = oldCurFilePath;

            //轮廓刺绣模式色序和花样参数不可按
            //            ui->buttonNeedle->setEnabled(false);
            //            ui->buttonPatternInfo->setEnabled(false);
            //            for(int i = 0; i < m_patternSetItemList.size(); i++)
            //            {
            //                if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR ||
            //                        m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
            //                {
            //                    m_patternSetBtnList[i]->setEnabled(false);
            //                }
            //            }
        }
        //////////////////////////////////////////////////////////////
    }
        break;

    case EMBFUN_LINEOFFSET: //线迹偏移
    {
        m_pMainWidgetFunction->funTraceOffset();
    }
        break;
    case EMBFUN_WORKSUSPENSION: //工作暂停
    {
        m_pMainWidgetFunction->funWorkPause();
    }
        break;
    case EMBFUN_REPEATED: //反复绣
    {
        patternRepeatEmbSet(tStyle);
    }
        break;
    default:
        break;
    }
}

//等待超时
void MainWidget::slotWaitTimout()
{
    m_timoutflag = 1;
}

//机器状态
void MainWidget::slotMachineStatus(int toggle)
{
    memcpy(&m_mcStatus, &g_pMachine->getMcStatus(), sizeof(MCStatus));

    if(m_pMainWidgetFunction != NULL)
    {
        //收到主控发的机器状态改变的信号，进到这个槽函数里(在MainWidgetFunction.cpp里用于读取电位器值)
        m_pMainWidgetFunction->setMcStates(m_mcStatus);
    }
    m_conFlag = toggle;

    if(m_pParameterSetDlg != NULL)
    {
        //将机器状态发给参数设置界面(用于刷新遍历状态)
        m_pParameterSetDlg->setMcStates(m_mcStatus);
    }

    showExecInfo();//显示机器运行状态中的信息

    //工作状态，工作中按钮不可按，并显示大图
    if(m_workStatus != m_mcStatus.workStatus)
    {
        m_workStatus = m_mcStatus.workStatus;

        if ((m_workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
        {
            ui->labelWorkState->setStyleSheet(m_setControlStyle.getStyleSheet(ui->labelWorkState->objectName()));
            ui->buttonNineBtn3->setBlueBorderBottomStyle();
            ui->buttonNineBtn3->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn3->objectName()+"Simulate"));
            ui->labelWorkState->setVisible(true);
        }
        else //正常工作
        {
            ui->buttonNineBtn3->setBlueBorderBottomStyle();
            ui->buttonNineBtn3->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn3->objectName()));
            ui->labelWorkState->setVisible(false);
        }

        if ((m_workStatus & WORK_STA_ENSTATE) == WORK_STA_ENSTATE) //允许状态
        {
            if(g_emMacType == MACHINE_EMB)
            {
                ui->buttonNineBtn2->setBlueBorderBottomStyle();
                ui->buttonNineBtn2->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn2->objectName()));
                ui->labelEnableWorkState->setVisible(false);
            }
        }
        else //正常工作
        {
            //禁止工作
            if(g_emMacType == MACHINE_EMB)
            {
                ui->labelEnableWorkState->setStyleSheet(m_setControlStyle.getStyleSheet(ui->labelEnableWorkState->objectName()));
                ui->buttonNineBtn2->setBlueBorderBottomStyle();
                ui->buttonNineBtn2->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn2->objectName()+"NoAllow"));
                ui->labelEnableWorkState->setVisible(true);
            }
        }

        //正在工作,按钮不可按
        if((m_workStatus & WORK_STA_WORKING) == WORK_STA_WORKING)
        {
            ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn4->objectName()+"Unlock"));
            setZoomMoveBtnVisible(false);
            setUiBtnEnable(false);
            ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()+"Disable"));

            if(m_dispMode != EmbData::DISP_EXECING)//不是执行状态，重置
            {
                g_pCurEmbData->setViewInfo(m_embBackPix);//带背景图的背景
                g_pCurEmbData->setDrawMode(EmbData::DRAW_VIEW);//非预览模式
                g_pCurEmbData->setEmbData();//ds16数据转换为画图数据

                m_dispMode = EmbData::DISP_ALL_EXEC;
                g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 重新画图

                m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
                g_pCurEmbData->setDispMode(m_dispMode, 0,m_gradientFlag);       // 设置为按进度执行模式
                g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度

                QPixmap patternPix = g_pCurEmbData->getPreviewImage();
                ui->labelPatternView->setPixmap(patternPix);
            }

            ui->frameForwardBack->setVisible(false);
            ui->frameMateEmb->setVisible(false);
            ui->frameOpenLineEmb->setVisible(false);
            if(!ui->labelPatternView->isVisible())//不是主图灰图界面
            {
                hideMenuFrame();
                showPatternPreview();
                ui->buttonMainMenu->setCheckable(true);
                ui->buttonMainMenu->setChecked(true);
            }

            //如果工作中错误提示窗体显示，则自动消失
            m_pMainWidgetFunction->funSetPromptDlgVisibleFalse();
            m_pMainWidgetFunction->setLotDatStartPins(ui->labelNeedleIdx->text().toInt());
        }
        else
        {
            ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn4->objectName()));
            setUiBtnEnable(true);
            m_pMainWidgetFunction->setLotDatEndPins(ui->labelNeedleIdx->text().toInt());
            ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
        }
    }

    //错误代码
    if (m_mcStatus.errorCode == 0)
    {
        m_errorCode = m_mcStatus.errorCode;
        ui->labelState->setText(tr("Ready"));//状态：已就绪
        if((m_workStatus & WORK_STA_WORKING) == WORK_STA_WORKING)
        {
            ui->labelState->setText(tr("Working"));//状态: 工作中
        }
    }
    else
    {
        u32 errcode = m_mcStatus.errorCode;
        if(errcode != m_errorCode)
        {
            m_errorCode = errcode;

            //边框刺绣完成自动加载边框刺绣之前的花样
            if(errcode == STA_EMB_FRAME_FINISH)//回起绣点后，发送这个错误码
            {
                if(m_borderEmb == 1)
                {
                    m_borderEmb = 0;
                    QFile::remove(m_curFilePath);//删除边框刺绣dsr文件
                    m_curFilePath = m_preFilePath;
                }
                slotShowPatternPara(m_curFilePath,-1);//不显示花样参数设置窗体，直接显示主界面花样界面
                //轮廓刺绣后 ，将源文件名写回配置文件
                if(g_pSettings != NULL)
                {
                    g_pSettings->writeToInHMIiFile("Pattern/name",m_curFilePath);
                }
                //               //色序和花样参数可按
                //                ui->buttonNeedle->setEnabled(true);
                //                ui->buttonPatternInfo->setEnabled(true);
                //                for(int i = 0; i < m_patternSetItemList.size(); i++)
                //                {
                //                    if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR ||
                //                            m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
                //                    {
                //                        m_patternSetBtnList[i]->setEnabled(true);
                //                    }
                //                }
                return;
            }

            QString info;
            info.clear();
            info = getErrStr(m_mcStatus.errorCode);
            //如果不是通用错误(即info为空)，就从机型cpp中的错误代码查找
            if(info.length() <= 0)
            {
                for(int i = 0; i < m_errorCodeAndStateItemList.size(); i++)
                {
                    if(m_mcStatus.errorCode == m_errorCodeAndStateItemList[i].m_code)
                    {
                        info = m_errorCodeAndStateItemList[i].m_name;
                        break;
                    }
                }
            }
            //如果不是通用错误也不是机型cpp中的错误代码，就显示未定义错误
            if(info.length() <= 0)
            {
                QString errorCode;
                errorCode.sprintf("CODE 0x%x", m_mcStatus.errorCode);
                info.append(tr("Undefined error,") + errorCode);//未定义错误,
            }

            ui->labelState->setText(info);//状态:

            if ((errcode > 0 && errcode < 0x100) || errcode > 0x200)
            {
                if(m_mcStatus.errorCode == ERR_CHEN_CUT_TIMEOUT)//毛巾剪刀运动超时
                {
                   m_pMainWidgetFunction->funDetectBreakHeadStatusBit(1);
                }
                else if(m_mcStatus.errorCode == ERR_CHEN_CUT_NOT_ZERO)//毛巾剪刀未回位
                {
                    m_pMainWidgetFunction->funDetectBreakHeadStatusBit(0);
                }
                else if(m_mcStatus.errorCode == ERR_EMB_CUT_NOT_ZERO)//平绣剪刀未回位
                {
                    m_pMainWidgetFunction->funDetectBreakHeadStatusBit(2);
                }
                else if(m_mcStatus.errorCode == ERR_CHEN_HOIST_TIMOUT)//提升电机运动超时
                {
                   m_pMainWidgetFunction->funDetectBreakHeadStatus(1);
                }
                else if(m_mcStatus.errorCode == ERR_CHEN_HOIST_POS)//毛巾提升电机位置错误
                {
                    m_pMainWidgetFunction->funDetectBreakHeadStatus(0);
                }
                else if(m_mcStatus.errorCode == ERR_ZP_SIGNAL)//ZP信号异常
                {
                    m_pMainWidgetFunction->funDetectSignalStatus(1);
                }
                else if(m_mcStatus.errorCode == ERR_MP_SIGNAL)//MP信号异常
                {
                    m_pMainWidgetFunction->funDetectSignalStatus(0);
                }
                else
                {
                    m_pMainWidgetFunction->funErrorPrompt(errcode,info);
                }
                //将报错代码写入csv
                QString csvInfo;
                csvInfo.clear();
                csvInfo.sprintf("[0x%x] ", m_mcStatus.errorCode);// 错误代码,
                csvInfo.append(info);   // 错误信息
                g_pSettings->writeToCsv(csvInfo,TYPE_ERROR);//保存
            }
            else
            {
                if(m_mcStatus.errorCode == STA_LINE_TBREAK)
                {
                    //检测断线状态
                    int ret = m_pMainWidgetFunction->funDetectBreakLineStatus();
                    if(ret != 0)//断线报错
                    {
                        m_fileHead.breakLineParkNum += ret;
                    }
                }
//                if(m_mcStatus.errorCode == STA_LINE_TBREAK)
//                {
//                    //检测断线状态
//                    int ret = m_pMainWidgetFunction->funDetectBreakLineStatus();
//                    if(ret != 0)//断线报错
//                    {
//                        m_fileHead.breakLineParkNum += ret;
//                    }
//                }
            }
        }
    }
}

void MainWidget::slotShowPercentage(int val)
{
    ui->labelTitle->setText(QString::number(val)+"%");
}

void MainWidget::slotRefreshWifiIcon(bool bl)
{
    if(bl == true)//已连接
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Connect"));
    }
    else
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Unconnect"));
    }
}

//测试物联网用
//void MainWidget::slotLotDat()
//{
//    ui->labelTitle->setText("lotdat");
//}

void MainWidget::slotChangeColorTable(int selColor, int colorIdx)
{
    if(selColor < 0)
    {
        return;
    }

    m_fileHead.switchTable[selColor] = colorIdx;
}

void MainWidget::slotChangeTowelHighTable(int selColor, int colorIdx)
{
    if(selColor < 0)
    {
        return;
    }

    if(selColor >= m_towelHeightTable.length())
    {
        return;
    }

    memcpy(m_towelHeightTable.data()+selColor,(char*)&colorIdx,sizeof(u8));
}

void MainWidget::slotRemoveBorder(QString filePath)
{
    if(m_borderEmb == 1 && filePath != m_curFilePath)
    {
        m_borderEmb = 0;
        QFile::remove(m_curFilePath);//删除边框刺绣dsr文件
    }
}

void MainWidget::slotShowPatternPara(QString filePath,s16 showFlag)
{
    if(m_borderEmb == 1 && filePath != m_curFilePath && m_curFilePath.length() != 0 && filePath.length() != 0)
    {
        m_borderEmb = 0;
        QFile::remove(m_curFilePath);//删除边框刺绣dsr文件
    }

    QString beforeFilePath = m_curFilePath;
    m_curFilePath = filePath;
    if(m_curFilePath.length() <= 0){return;}
    QFile file(m_curFilePath);
    if(!file.exists()){return;}//文件不存在

    //获得花样参数的图标
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            break;
        }
    }

    m_pParameterSetDlg->setTypeLogo(tStyle);
    m_pParameterSetDlg->setMainTitle(tr("Pattern para"));//花样参数
    m_pParameterSetDlg->setSubTitle(tr("Pattern setting > Pattern para"));// 花样设置 > 花样参数
    //绣花花样参数-花样设置参数
    m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN);

    //得到花样参数
    DataFileHead fileHead;
    memset(&fileHead,0,sizeof(DataFileHead));
    memset(fileHead.switchTable,0,sizeof(fileHead.switchTable));

    m_pMainWidgetFunction->getPatternHeadConfig(filePath,fileHead);

    //int size = sizeof(m_fileHead);
    //rq   针步补偿写在配置文件中在超级用户花样参数里可以设置
    filePath += ".fcg";
    QFile fileFcg(filePath);
    if(!fileFcg.exists())//不存在fcg文件时，以下是默认的经验值  -rq
    {
        //u32 lockNeedlesNum = g_pSettings->readFromInHMIiFile("PatternPara/lockNeedlesNum").toInt(); // 锁针次数
        u32 lockNeedlesStepNum =  g_pSettings->readFromInHMIiFile("PatternPara/lockNeedlesStepNum").toInt(); // 锁针步数
        u32 lockNeedlesStepLength =  g_pSettings->readFromInHMIiFile("PatternPara/lockNeedlesStepLength").toInt();   // 锁针针步长度
        u32 minStep = g_pSettings->readFromInHMIiFile("PatternPara/minStep").toInt();   // 过滤针步长度
        //fileHead.lockNeedlesNum = lockNeedlesNum;
        fileHead.lockNeedlesStepNum = lockNeedlesStepNum;
        fileHead.lockNeedlesStepLength = lockNeedlesStepLength;
        fileHead.minStep = minStep;
        // u32 stepCompensation = g_pSettings->readFromIniFile("PatternPara/stepCompensation").toInt();//针步补偿
        // fileHead.stepCompensation = stepCompensation;
        u32 xCompensation = g_pSettings->readFromInHMIiFile("PatternPara/xCompensation").toInt();
        u32 yCompensation = g_pSettings->readFromInHMIiFile("PatternPara/yCompensation").toInt();
        fileHead.xCompensate = xCompensation;
        fileHead.yCompensate = yCompensation;
    }

    //得到花样毛巾高度
    u8 getTowelHighTable[TOWELHIGHBUF];      // 色序设定表, 支持512个色序设定
    memset(getTowelHighTable,0,sizeof(getTowelHighTable));

    QFileInfo fileInfo(m_curFilePath);
    if(fileInfo.suffix() == "DSR")
    {
        DataFileDsr dsr;
        memcpy(getTowelHighTable, dsr.getTowelHighTable(m_curFilePath), sizeof(getTowelHighTable));     //毛巾高度
    }

    //fcg不存在或fcg中毛巾高度数据为0时写入源dsr文件中的毛巾高度数据，自动设置毛巾高度
    memset(m_towelHeightTable.data(),0,m_towelHeightTable.length());
    m_pMainWidgetFunction->getPatternTowelHeightFcg(m_curFilePath,m_towelHeightTable);
    bool bl = false;
    for(int i = 0; i < m_towelHeightTable.length(); i++)
    {
        if(m_towelHeightTable.at(i) == 0)
        {
            bl = true;
            m_towelHeightTable[i] = getTowelHighTable[i];
        }
    }
    if(bl == true)
    {
        m_pMainWidgetFunction->setPatternTowelHeightFcg(m_curFilePath,m_towelHeightTable);
    }

    m_pParameterSetDlg->setItemValue(SET_ROTATESTYLE,fileHead.rotateStyle);     //旋转式样
    m_pParameterSetDlg->setItemValue(SET_HORIZONTALSTYLE,fileHead.horizontalStyle);     //水平翻转式样
    m_pParameterSetDlg->setItemValue(SET_VERTICALSTYLE,fileHead.verticalStyle);     //垂直翻转式样
    m_pParameterSetDlg->setItemValue(SET_ROTATEANGLE,fileHead.rotateAngle);     //旋转角度
    m_pParameterSetDlg->setItemValue(SET_XZOOM,fileHead.xZoom);               //X向倍率
    m_pParameterSetDlg->setItemValue(SET_YZOOM,fileHead.yZoom);                 //Y向倍率
    m_pParameterSetDlg->setItemValue(SET_REPEATSTYLE,fileHead.repeatStyle);     //反复方式
    m_pParameterSetDlg->setItemValue(SET_PRIORITY,fileHead.priority);           //优先次序
    m_pParameterSetDlg->setItemValue(SET_XREPEATNUM,fileHead.xRepeatNum);       //X向反复次数
    m_pParameterSetDlg->setItemValue(SET_YREPEATNUM,fileHead.yRepeatNum);       //Y向反复次数
    m_pParameterSetDlg->setItemValue(SET_XREPEATSPACE,fileHead.xRepeatSpace);   //X向反复间距
    m_pParameterSetDlg->setItemValue(SET_YREPEATSPACE,fileHead.yRepeatSpace);   //Y向反复间距
    m_pParameterSetDlg->setItemValue(SET_LOCKNEEDLESNUM,fileHead.lockNeedlesNum);     //锁针针数
    m_pParameterSetDlg->setItemValue(SET_LOCKNEEDLESSTEPNUM,fileHead.lockNeedlesStepNum);     //锁针步数
    m_pParameterSetDlg->setItemValue(SET_LOCKNEEDLESSTEPLENTH,fileHead.lockNeedlesStepLength);     //锁针针步长度
    m_pParameterSetDlg->setItemValue(SET_JUMPNEEDLECHANGE,fileHead.jumpNeedleChange);     //跳针变越框锁针针数
    m_pParameterSetDlg->setItemValue(SET_CHANGLOOKNEEDLE,fileHead.coloLockrNeedle);     //换色锁针针数
    //m_pParameterSetDlg->setItemValue(SET_STEPCOMPENSATE,fileHead.stepCompensation);     //针步补偿
    m_pParameterSetDlg->setItemValue(SET_XCOMPENSATE,fileHead.xCompensate);     //X向补偿
    m_pParameterSetDlg->setItemValue(SET_YCOMPENSATE,fileHead.yCompensate);     //Y向补偿
    m_pParameterSetDlg->setItemValue(SET_CONVERTJUMPSTEPSIZE,fileHead.convertJumpStepSize);//需要插入跳针的针步大小
    m_pParameterSetDlg->setItemValue(SET_JUMPSTEPSIZE,fileHead.jumpStepSize);//插入跳针的针步大小
    m_pParameterSetDlg->setItemValue(SET_MINSTEP,fileHead.minStep);     //过滤针步长度
    m_pParameterSetDlg->setItemValue(SET_PLEATEDMODE,fileHead.pleatedMode);     //是否为褶绣模式

    s32 offsetEnValueX = fileHead.offsetEn & 1;//取bit0的值
    m_pParameterSetDlg->setItemValue(SET_OFFSETPOINTXENFLAG,offsetEnValueX);     //偏移点X向允许
    s32 offsetEnValueY = (fileHead.offsetEn & 2)>>1;  //取bit1的值
    m_pParameterSetDlg->setItemValue(SET_OFFSETPOINTYENFLAG,offsetEnValueY);     //偏移点Y向允许

    m_pParameterSetDlg->setItemValue(SET_OFFSETPOINTX,fileHead.offsetX);     //偏移点X
    m_pParameterSetDlg->setItemValue(SET_OFFSETPOINTY,fileHead.offsetY);     //偏移点Y

    QFileInfo info(m_curFilePath);
    u8 table[BEADSEQUINTYPE];
    memset(table,0,sizeof(table));
    if(info.suffix().toUpper() == "DST")
    {
        int sequin = g_pSettings->readFromInHMIiFile("HMI/sequin").toInt();//是否有亮片功能
        int bead = g_pSettings->readFromInHMIiFile("HMI/bead").toInt();//是否有散珠功能

        memcpy(table,m_pPatternSelectWi->getBeadSequinTable(),sizeof(table));
        for(u32 i = 0; i < sizeof(table); i++)
        {
            if(table[i] == 1)
            {
                if ((sequin == 0) && (bead == 0))
                {
                    fileHead.beadSequinTable[i] = 0;     // 平绣
                }
                else
                {
                    m_pParameterSetDlg->addBeadSequinParaItem(SET_BEADSEQUIN+i,fileHead.beadSequinTable[i]);     //珠片
                }
            }
        }
    }
    m_pParameterSetDlg->setCurPage(1);

    s16 value = 0;
    if(showFlag != 0)//不显示此窗体直接加载花样参数(适用于开机自动加载花样文件)
    {
        value = 1;
    }
    else //显示此窗体
    {
        value = m_pParameterSetDlg->exec();
        m_pPatternSelectWi->hide();

#if(0)//昆仑通态操作屏下有问题，所以注释掉
        if(value == 1)
        {
            //正在加载花样提示窗体
            m_pPromptDlg->initDialog(PromptDialog::BTN_NONE);
            m_pPromptDlg->setTitleStr(tr("Prompt"));
            m_pPromptDlg->setContentStr(tr("Loading patterns, please wait..."));  //正在加载花样，请等待...
            m_pPromptDlg->show();
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }
#endif
    }

    if(value == 1)//花样参数设置(点击了确定按钮或直接加载文件后加载花样参数)
    {
        memcpy(&m_fileHead,&fileHead,sizeof(DataFileHead));
        setPatternSetBtnEnable(true);

        //文件头花样参数
        m_fileHead.rotateStyle = m_pParameterSetDlg->getItemValue(SET_ROTATESTYLE);    //旋转式样
        m_fileHead.horizontalStyle = m_pParameterSetDlg->getItemValue(SET_HORIZONTALSTYLE);    //水平翻转式样
        m_fileHead.verticalStyle = m_pParameterSetDlg->getItemValue(SET_VERTICALSTYLE);    //垂直翻转式样
        m_fileHead.rotateAngle = m_pParameterSetDlg->getItemValue(SET_ROTATEANGLE);    //旋转角度
        m_fileHead.xZoom = m_pParameterSetDlg->getItemValue(SET_XZOOM);                //X向倍率
        m_fileHead.yZoom = m_pParameterSetDlg->getItemValue(SET_YZOOM);                //Y向倍率
        m_fileHead.repeatStyle = m_pParameterSetDlg->getItemValue(SET_REPEATSTYLE);    //反复方式
        m_fileHead.priority = m_pParameterSetDlg->getItemValue(SET_PRIORITY);          //优先次序
        m_fileHead.xRepeatNum = m_pParameterSetDlg->getItemValue(SET_XREPEATNUM);      //X向反复次数
        m_fileHead.yRepeatNum = m_pParameterSetDlg->getItemValue(SET_YREPEATNUM);      //Y向反复次数
        m_fileHead.xRepeatSpace = m_pParameterSetDlg->getItemValue(SET_XREPEATSPACE);  //X向反复间距
        m_fileHead.yRepeatSpace = m_pParameterSetDlg->getItemValue(SET_YREPEATSPACE);  //Y向反复间距
        //m_fileHead.lockNeedlesNum = m_pParameterSetDlg->getItemValue(SET_LOCKNEEDLESNUM);  //锁针次数
        m_fileHead.lockNeedlesStepNum = m_pParameterSetDlg->getItemValue(SET_LOCKNEEDLESSTEPNUM);  //锁针针步
        m_fileHead.lockNeedlesStepLength = m_pParameterSetDlg->getItemValue(SET_LOCKNEEDLESSTEPLENTH);  //锁针针步长度
        m_fileHead.coloLockrNeedle = m_pParameterSetDlg->getItemValue(SET_CHANGLOOKNEEDLE);  //换色锁针针数
        m_fileHead.jumpNeedleChange = m_pParameterSetDlg->getItemValue(SET_JUMPNEEDLECHANGE);  //跳针变越框锁针针数
        m_fileHead.xCompensate = m_pParameterSetDlg->getItemValue(SET_XCOMPENSATE);    //X向补偿
        m_fileHead.yCompensate = m_pParameterSetDlg->getItemValue(SET_YCOMPENSATE);    //Y向补偿
        m_fileHead.convertJumpStepSize = m_pParameterSetDlg->getItemValue(SET_CONVERTJUMPSTEPSIZE);     // 绣花机中需要插入跳针的针步大小
        m_fileHead.jumpStepSize = m_pParameterSetDlg->getItemValue(SET_JUMPSTEPSIZE);     // 绣花机中插入跳针的针步大小
        m_fileHead.minStep = m_pParameterSetDlg->getItemValue(SET_MINSTEP);     // 过滤针步长度
        // m_fileHead.stepCompensation = m_pParameterSetDlg->getItemValue(SET_STEPCOMPENSATE);    //针步补偿
        m_fileHead.pleatedMode = m_pParameterSetDlg->getItemValue(SET_PLEATEDMODE);     // 是否为褶绣模式

        s32 offsetEnValueNewX= m_pParameterSetDlg->getItemValue(SET_OFFSETPOINTXENFLAG);// bit0,偏移点X向允许
        m_fileHead.offsetEn = offsetEnValueNewX & 1;
        s32 offsetEnValueNewY= m_pParameterSetDlg->getItemValue(SET_OFFSETPOINTYENFLAG);// bit1,偏移点Y向允许
        m_fileHead.offsetEn =  (offsetEnValueNewY<<1) | m_fileHead.offsetEn;

        m_fileHead.offsetX = m_pParameterSetDlg->getItemValue(SET_OFFSETPOINTX);    //偏移点X
        m_fileHead.offsetY = m_pParameterSetDlg->getItemValue(SET_OFFSETPOINTY);    //偏移点Y
        //m_fileHead.begHead = m_workNoseHead;//当前工作机头//这个是把机头写在了fcg里

        QFileInfo info(m_curFilePath);
        if(info.suffix().toUpper() == "DST")
        {
            for(u32 i = 0; i < sizeof(table); i++)
            {
                if(table[i] == 1)
                {
                   // qDebug()<<"m_fileHead.beadSequinTable[i]"<<m_fileHead.beadSequinTable[i];
                    m_fileHead.beadSequinTable[i] = m_pParameterSetDlg->getItemValue(SET_BEADSEQUIN+i);    //珠片
                }
            }
        }

        //qDebug()<<"slotSetPatternData before";
        slotSetPatternData();//设置花样数据并显示
        //qDebug()<<"slotSetPatternData end";
        //将反复绣设置写入文件头-用于下位机
        g_pCurEmbData->setMcRepeatEmb(m_fileHead);
#if(0)
        //发送花样数据  //测试
        QByteArray & ds16dat = g_pCurEmbData->getDsDat();

        // ds16数据（转换的）
        int size = ds16dat.size();
        if (size <= (int)sizeof(DataDs16FileHead))
        {
            qDebug("data less then head size");
            return;
        }
        DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());

        s32 text= pDs16Head->fileid;
        ui->labelfileid->setFont(fontNormal_6);
        ui->labelfileid->setStyleSheet(LABELWHITESTYLE);
        ui->labelfileid->setGeometry(400,2,350,30);
        ui->labelfileid->setText(QString::number(text));
#endif
#if(0)//昆仑通态操作屏下有问题，所以注释掉
        if(m_pPromptDlg->isVisible())//若是可见的
        {
            m_pPromptDlg->hide();//隐藏加载花样的提示窗体
        }
#endif

        if(m_linkSta == Connected)//已连接
        {
            //边框刺绣完成自动加载边框刺绣之前的花样,此时只需发送文件头
            if(m_errorCode == STA_EMB_FRAME_FINISH)
            {
#if(IFDYSENDMODE)
                {
                    m_pMainWidgetFunction->sendPatternData(m_curFilePath);//如果是动态传输，发送整个文件
                }
#else
                {
                    m_pMainWidgetFunction->sendPatternHead(m_curFilePath);
                }
#endif
                //总是不成功(数据发送失败)，所以加了延时解决
                QDateTime oldTime = QDateTime::currentDateTime();
                while(1)
                {
                    QDateTime curTime = QDateTime::currentDateTime();
                    if(oldTime.msecsTo(curTime) > 50)
                    {
                        break;
                    }
                }

                m_pMainWidgetFunction->sendPatternPatchHeadData(m_curFilePath);
            }
            else
            {
                if(m_curFilePath.length() > 0)
                {
#if(IFDYSENDMODE)
                    //动态传输上电记忆功能，界面扫描主控执行针数，界面将执行进度发给主控
                    if(showFlag != 0)
                    {
                        if(m_mcStatus.dataIdx != 0)
                        {
                            m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
                            int idx = m_mcStatus.dataIdx;
                            addOrDecNeedleIdx(idx);
                            m_expara.mvFrameFlag = 0;
                            int fileId = m_pMainWidgetFunction->getCurFileID();  //获取文件ID
                            g_pMachine->setFileExecProgress(0, fileId, m_expara);   //发送执行进度
                        }
                        else
                        {
                            if(m_borderEmb != 0)
                            {
                                m_pMainWidgetFunction->sendPatternData(m_curFilePath,FILE_TYPE_FRAME);//发送边框数据
                            }
                            else
                            {
                                m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
                            }
                        }
                    }
                    else
                    {
                        if(m_borderEmb != 0)
                        {
                            m_pMainWidgetFunction->sendPatternData(m_curFilePath,FILE_TYPE_FRAME);//发送边框数据
                        }
                        else
                        {
                            m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
                        }
                    }
#else
                    {
                        if(m_borderEmb != 0)
                        {
                            m_pMainWidgetFunction->sendPatternData(m_curFilePath,FILE_TYPE_FRAME);//发送边框数据
                        }
                        else
                        {
                            m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
                        }
                    }
#endif
                }
            }
            //设置为按进度执行模式
            g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度
        }
    }
    else
    {
        //点击取消按钮后花样路径恢复为上次选中的花样
        m_curFilePath = beforeFilePath;
    }
}

//删除文件后判断当前文件是否被删除
void MainWidget::slotIfFileExist()
{
    if(m_curFilePath.length() > 0)//当前选择的花样路径
    {
        QFile file(m_curFilePath);
        if(!file.exists())//不存在
        {
            m_curFilePath.clear();

            //花样参数、花样色序不可按
            for(int i = 0; i < m_patternSetItemList.size(); i++)
            {
                if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                        m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
                {
                    m_patternSetBtnList[i]->setEnabled(false);
                }
            }

            //隔头绣、贴布绣、边框刺绣等不可按
            for(int i = 0; i < m_embFunctionItemList.size(); i++)
            {
                if(m_embFunctionItemList[i].m_enumFunction == EMBFUN_HEADEMB ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_PATCHEMB ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_BORDEREMB ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINE ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINECHECK ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_LINEOFFSET ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_REPEATED )
                {
                    m_embFunctionBtnList[i]->setEnabled(false);
                }
            }

            for(int i = 0; i < m_quickItemList.size(); i++)
            {
                int enumFun = m_quickItemList[i].m_enumFunction;
                if(enumFun == FUN_FORWARDORBACK ||//快进快退
                        enumFun == FUN_SETSTARTEMBPOINT ||//定起绣点
                        enumFun == FUN_BACKSTARTEMBPOINT ||//回起绣点
                        enumFun == FUN_CHECKFRAME ||//边框检查
                        enumFun == FUN_BACKWORKPOINT //回工作点
                        )
                {
                    m_quickBtnList[i]->setEnabled(false);
                }
            }

            for(int i = 0; i < m_shortCutBtnList.size(); i++)//窗体下方的快捷按钮列表 10个
            {
                int commonBtnIdx = g_pSettings->readFromIniFile("HMI/commonbtn"+QString::number(i+1)).toInt();
                //快进快退等功能不可用
                if(    commonBtnIdx == FUN_FORWARDORBACK ||//快进快退
                       commonBtnIdx == FUN_SETSTARTEMBPOINT ||//定起绣点
                       commonBtnIdx == FUN_BACKSTARTEMBPOINT ||//回起绣点
                       commonBtnIdx == FUN_CHECKFRAME ||//边框检查
                       commonBtnIdx == FUN_BACKWORKPOINT //回工作点
                       )
                {
                    m_shortCutBtnList[i]->setEnabled(false);
                }
            }

            if(g_emMacType == QUIMACHINE_EMB)
            {
                 ui->buttonNineBtn1->setEnabled(true);
            }
            else if(g_emMacType == MACHINE_EMB)
            {
                ui->buttonNineBtn1->setEnabled(false);
            }

            if(g_pMachine != NULL)
            {
                g_pMachine->invalidateWorkFile();
            }
        }
    }
}

//花样导入替换文件，判断替换文件是否是当前所选的花样
void MainWidget::slotReplacePattrn(QString path)
{
    QFileInfo file(m_curFilePath);
    QFileInfo newfile(path);
    QString pathPattern = file.fileName();
    QString newPathPattern = newfile.fileName();
    if(m_curFilePath.length() > 0)//当前选择的花样路径
    {
        if(pathPattern == newPathPattern)//如果替换的花样等于当前选择的花样
        {
            m_curFilePath.clear();//清空当前的花样，并重新选择

            //花样参数、花样色序不可按
            for(int i = 0; i < m_patternSetItemList.size(); i++)
            {
                if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                        m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
                {
                    m_patternSetBtnList[i]->setEnabled(false);
                }
            }
            //隔头绣、贴布绣、边框刺绣等不可按
            for(int i = 0; i < m_embFunctionItemList.size(); i++)
            {
                if(m_embFunctionItemList[i].m_enumFunction == EMBFUN_HEADEMB ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_PATCHEMB ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_BORDEREMB ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINE ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINECHECK ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_LINEOFFSET ||
                        m_embFunctionItemList[i].m_enumFunction == EMBFUN_REPEATED )
                {
                    m_embFunctionBtnList[i]->setEnabled(false);
                }
            }

            if(g_pMachine != NULL)
            {
                g_pMachine->invalidateWorkFile();
            }
        }
    }
}
void MainWidget::slotClearPatternFcg()
{
    if(m_curFilePath.length() > 0)//当前选择的花样路径
    {
        m_curFilePath.clear();

        //花样参数、花样色序不可按
        for(int i = 0; i < m_patternSetItemList.size(); i++)
        {
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                    m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
            {
                m_patternSetBtnList[i]->setEnabled(false);
            }
        }

        //隔头绣、贴布绣、边框刺绣等不可按
        for(int i = 0; i < m_embFunctionItemList.size(); i++)
        {
            if(m_embFunctionItemList[i].m_enumFunction == EMBFUN_HEADEMB ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_PATCHEMB ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_BORDEREMB ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINE ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_OUTLINECHECK ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_LINEOFFSET ||
                    m_embFunctionItemList[i].m_enumFunction == EMBFUN_REPEATED )
            {
                m_embFunctionBtnList[i]->setEnabled(false);
            }
        }

        for(int i = 0; i < m_quickItemList.size(); i++)
        {
            int enumFun = m_quickItemList[i].m_enumFunction;
            if(enumFun == FUN_FORWARDORBACK ||//快进快退
                    enumFun == FUN_SETSTARTEMBPOINT ||//定起绣点
                    enumFun == FUN_BACKSTARTEMBPOINT ||//回起绣点
                    enumFun == FUN_CHECKFRAME ||//边框检查
                    enumFun == FUN_BACKWORKPOINT //回工作点
                    )
            {
                m_quickBtnList[i]->setEnabled(false);
            }
        }

        for(int i = 0; i < m_shortCutBtnList.size(); i++)//窗体下方的快捷按钮列表 10个
        {
            int commonBtnIdx = g_pSettings->readFromIniFile("HMI/commonbtn"+QString::number(i+1)).toInt();
            //快进快退等功能不可用
            if(    commonBtnIdx == FUN_FORWARDORBACK ||//快进快退
                   commonBtnIdx == FUN_SETSTARTEMBPOINT ||//定起绣点
                   commonBtnIdx == FUN_BACKSTARTEMBPOINT ||//回起绣点
                   commonBtnIdx == FUN_CHECKFRAME ||//边框检查
                   commonBtnIdx == FUN_BACKWORKPOINT //回工作点
                   )
            {
                m_shortCutBtnList[i]->setEnabled(false);
            }
        }

        if(g_emMacType == QUIMACHINE_EMB)
        {
             ui->buttonNineBtn1->setEnabled(true);
        }
        else if(g_emMacType == MACHINE_EMB)
        {
            ui->buttonNineBtn1->setEnabled(false);
        }


        if(g_pMachine != NULL)
        {
            g_pMachine->invalidateWorkFile();
        }
    }
}

void MainWidget::slotSetPatternData()
{
    if(m_curFilePath.length() <= 0)//当前选择的花样路径
    {
        return;
    }
    QFile curfile(m_curFilePath);
    if(!curfile.exists())
    {
        return;
    }

    if(m_pParameterSetDlg == NULL){return;}

    QFileInfo file(m_curFilePath);
    QString ext = file.suffix().toUpper();

    int totalNeedle = 0;

    if(ext == "DST")//dst文件
    {
        DataFileDst dst;
        dst.initFile(m_curFilePath);
        totalNeedle = dst.checkDstFile();
    }
    else if(ext == "DSR")//dsr文件
    {
        DataFileDsr dsr;
        dsr.initFile(m_curFilePath);
        totalNeedle = dsr.checkDsrVersion();
    }
    totalNeedle *= m_fileHead.xRepeatNum;
    totalNeedle *= m_fileHead.yRepeatNum;

    if(totalNeedle > PATTERN_LARGE_NEEDLES )//大于128万针
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        //所选花样X向反复次数设置不合理，请重新设置！
        str = tr("The number of repetitions in the X direction of the selected pattern is unreasonable, please reset it!");
        promptDlg.setContentStr(str);

        promptDlg.exec();

        memset(&m_fileHead,0,sizeof(DataFileHead));
        m_pMainWidgetFunction->getPatternHeadConfig(m_curFilePath,m_fileHead);

        return;
    }

    g_pCurEmbData->setViewInfo(m_embBackPix);
    g_pCurEmbData->setDrawMode(EmbData::DRAW_VIEW);//非预览模式
    ui->labelFilename->setText(file.fileName());//显示花样名
    g_pCurEmbData->clear();//清空当前选择的花样
    //int inosenum = 0;

    if(m_fileHead.combineMode == -1)//双头组合模式隔头绣不可用
    {
        slotSetHeadEmbBtnEnable(false);
    }
    else
    {
        slotSetHeadEmbBtnEnable(true);
    }

    if(m_fileHead.threeCombineMode == -1)//三头组合模式隔头绣不可用
    {
        slotSetHeadEmbBtnEnable(false);
    }
    else
    {
        slotSetHeadEmbBtnEnable(true);
    }
    //添加一个花样文件
    if(ext == "DST")//dst文件
    {
        DataFileDst dst;
        dst.initFile(m_curFilePath);
        dst.loadFile();
        if(g_emMacType == MACHINE_EMB ||
                g_emMacType == QUIMACHINE_EMB)
        {
            //将fcg里的偏移值XY 写在   dst源文件的头文件里
            dst.writeOffsetXYMoveToFile(m_fileHead.offsetEn,m_fileHead.offsetX,m_fileHead.offsetY);
        }
        dst.setBeadSequinTable(m_fileHead.beadSequinTable);
        dst.convertDataToAbs();//dsr 转换成中间数据

        g_pCurEmbData->setAbsDat(dst.getEmbAbsData());
    }
    else if(ext == "DSR")//dsr文件
    {
        DataFileDsr dsr;

        u8 getTowelHighTable[TOWELHIGHBUF];      // 色序设定表, 支持512个色序设定
        memset(getTowelHighTable,0,sizeof(getTowelHighTable));
        memcpy(getTowelHighTable, dsr.getTowelHighTable(m_curFilePath), sizeof(getTowelHighTable));     //毛巾高度

        for(int i = 0; i < m_towelHeightTable.length(); i++)
        {
            if(m_towelHeightTable.at(i) == 0)
            {
                m_towelHeightTable[i] = getTowelHighTable[i];
            }
        }

        dsr.initFile(m_curFilePath);
        dsr.loadFile();//下载dsr的文件
        //自动设置色序
        u8 getColorTable[0x400-0x200];      // 色序设定表, 支持512个色序设定
        memset(getColorTable,0,sizeof(getColorTable));
        DsrHead * dsrHead = (DsrHead *)(dsr.m_fileData.data());//读取dsr源文件的头文件的结构体
        memcpy(getColorTable, dsrHead->switchTable, sizeof(dsrHead->switchTable));

        for(u32 i = 0; i < sizeof(m_fileHead.switchTable); i++)
        {
            if(m_fileHead.switchTable[i] == 0)
            {
                m_fileHead.switchTable[i] = getColorTable[i];
            }
        }

        if(g_emMacType == MACHINE_EMB||
                g_emMacType == QUIMACHINE_EMB)
        {
            //将fcg里的偏移值XY 写在   dsr源文件的头文件里
            dsr.writeOffsetXYMoveToFile(m_fileHead.offsetEn,m_fileHead.offsetX,m_fileHead.offsetY);
        }
        //花样参数点击了确认按钮，判断dsr里有没有绣花，激光数据等
        dsr.convertDataToEmbAbs();// dsr转换为绝对数据（中间数据）
        g_pCurEmbData->setAbsDat(dsr.getEmbAbsData());//得到转换后的绝对坐标数据
    }
    else
    {
        return;
    }

    g_pCurEmbData->mergeMinStep(m_fileHead.minStep, 200);  // 合并小针步
    //qDebug()<<"mergeMinStep end";

    g_pCurEmbData->addLockStitchs(m_fileHead.lockNeedlesNum, m_fileHead.lockNeedlesStepNum, m_fileHead.lockNeedlesStepLength, m_fileHead.jumpNeedleChange, m_fileHead.coloLockrNeedle);  // 添加锁针针步
    //qDebug()<<"addLockStitchs end";

    g_pCurEmbData->appendAEmbAbsFile(m_curFilePath, g_pCurEmbData->getAbsDat());//生成文件信息
    //qDebug()<<"appendAEmbAbsFile end";

    s16 changeFlag = 0;//数据是否变换的标志 0：未变换  1：已变换

    int width = 0;
    int height = 0;

    g_pCurEmbData->getAbsDatRangeXY();//获得单个图元的宽高范围
    int maxX = g_pCurEmbData->m_maxX;
    int minX = g_pCurEmbData->m_minX;
    width = maxX - minX;
    int maxY = g_pCurEmbData->m_maxY;
    int minY = g_pCurEmbData->m_minY;
    height = maxY - minY;

    //旋转式样
    switch (m_fileHead.rotateStyle)
    {
    case 0:
        break;
    case 1:
        changeFlag = g_pCurEmbData->setRotate(360-90);
        break;
    case 2:
        changeFlag = g_pCurEmbData->setRotate(360-180);
        break;
    case 3:
        changeFlag = g_pCurEmbData->setRotate(360-270);
        break;
    case 4:
        changeFlag = g_pCurEmbData->setMirror(1);
        break;
    case 5:
        changeFlag = g_pCurEmbData->setMirror(1);
        changeFlag = g_pCurEmbData->setRotate(360-90);
        break;
    case 6:
        changeFlag = g_pCurEmbData->setMirror(1);
        changeFlag = g_pCurEmbData->setRotate(360-180);
        break;
    case 7:
        changeFlag = g_pCurEmbData->setMirror(1);
        changeFlag = g_pCurEmbData->setRotate(360-270);
        break;
    }
    //qDebug()<<"rotateStyle end";

    //水平翻转样式
    switch (m_fileHead.horizontalStyle)
    {
    case 0:
        break;
    case 1:
        changeFlag = g_pCurEmbData->setMirror(1);
        break;
    }
    //qDebug()<<"horizontalStyle end";

    //垂直翻转样式
    switch (m_fileHead.verticalStyle)
    {
    case 0:
        break;
    case 1:
        changeFlag = g_pCurEmbData->setMirror(2);
        break;
    }
    //qDebug()<<"verticalStyle end";

    //旋转
    changeFlag = g_pCurEmbData->setRotate(360-m_fileHead.rotateAngle);
    //qDebug()<<"rotateAngle end";

    //目前只有绣花机的时候有缩放，其他机型会默认是0，那么传入到算法里的数据就是-100，就会显示不出来花样  -rq
    if (g_emMacType == MACHINE_EMB||
            g_emMacType == QUIMACHINE_EMB)
    {
        //缩放   缩放算法里是用原数据加减缩放值算的，参数设置未设置时是100，所以要减100   -rq
        changeFlag = g_pCurEmbData->setDatSizeChange(m_fileHead.xZoom - 100, m_fileHead.yZoom - 100);   // 设置尺寸变化
        //qDebug()<<"setDatSizeChange end";
    }
    //反复次数
    int xRepeatNum = m_fileHead.xRepeatNum;
    int yRepeatNum = m_fileHead.yRepeatNum;

    //反复次数大于1
    if(xRepeatNum > 1 || yRepeatNum > 1)
    {
        //图之间的间距
        int spaceX = m_fileHead.xRepeatSpace * 10;
        int spaceY = m_fileHead.yRepeatSpace * 10;

        g_pCurEmbData->getAbsDatRangeXY();//获得单个图元的宽高范围
        maxX = g_pCurEmbData->m_maxX;
        minX = g_pCurEmbData->m_minX;
        width = maxX - minX;
        maxY = g_pCurEmbData->m_maxY;
        minY = g_pCurEmbData->m_minY;
        height = maxY - minY;

        //mirror值
        s16 mirror = 0;

#if(0)
        switch (m_fileHead.repeatStyle)
        {
        case 0:
        case 4:
            mirror = 0;//1,1,1(x、y、r)
            break;
        case 1:
        case 5:
            mirror = 1;//-1,1,-1(x、y、r)
            break;
        case 2:
        case 6:
            mirror = 2;//1,-1,-1(x、y、r)
            break;
        case 3:
        case 7:
            mirror = 3;//-1,-1,-1(x、y、r)
            break;
        default:
            mirror = 0;//1,1,1(x、y、r)
            break;
        }
#endif

        int first = 0;
        int cmirror = 0;//初始化cmirror为mirror

        int num1 = yRepeatNum;
        int num2 = xRepeatNum;
        int even = 0;
        if(m_fileHead.priority == 1)//纵向优先
        {
            num1 = xRepeatNum;
            num2 = yRepeatNum;
            even = num1 % 2; //x向是奇数还是偶数
        }

        for(int j = 0; j < num1; j++)
        {
            if(m_fileHead.priority == 1)//纵向优先
            {
                if(spaceX < 0)
                {
                    g_pCurEmbData->m_spaceX = 0 + j * (abs(spaceX) + abs(width));
                }
                else
                {
                    g_pCurEmbData->m_spaceX = 0 - j * (spaceX + abs(width));
                }
            }
            else //横向优先
            {
                if(spaceY < 0)
                {
                    g_pCurEmbData->m_spaceY = 0 + j * (abs(spaceY) + abs(height));
                }
                else
                {
                    g_pCurEmbData->m_spaceY = 0 - j * (spaceY + abs(height));
                }
            }

            for(int i = 0; i < num2; i++)
            {
                //从第二个文件开始添加，因为第一个文件上边已经添加完成
                if(first == 0)
                {
                    first = 1;//第一个不添加跳过
                    continue;
                }
                if(m_fileHead.priority == 1)//纵向优先
                {
                    if(spaceY < 0)
                    {
                        g_pCurEmbData->m_spaceY = 0 + i * (abs(spaceY) + abs(height));
                    }
                    else
                    {
                        g_pCurEmbData->m_spaceY = 0 - i * (spaceY + abs(height));
                    }

                    //反复方式
                    if(even != 0)//x向为奇数
                    {
                        if(i%2 == 0)
                        {
                            if( j%2 == 0)
                            {
                                cmirror = 0;
                            }
                            else
                            {
                                cmirror = mirror;
                            }
                        }
                        else//x向为偶数
                        {
                            if( j%2 == 0)
                            {
                                cmirror = mirror;
                            }
                            else
                            {
                                cmirror = 0;
                            }
                        }
                    }
                    else
                    {
                        if(j%2 == 0)
                        {
                            cmirror = 0;
                        }
                        else
                        {
                            cmirror = mirror;
                        }
                    }
                }
                else //横向优先
                {
                    if(spaceX < 0)
                    {
                        g_pCurEmbData->m_spaceX = 0 + i * (abs(spaceX) + abs(width));
                    }
                    else
                    {
                        g_pCurEmbData->m_spaceX = 0 - i * (spaceX + abs(width));
                    }

                    if(cmirror == 0)
                    {
                        cmirror = mirror;
                    }
                    else
                    {
                        cmirror = 0;
                    }
                }

                QByteArray absAry = g_pCurEmbData->getAbsDat();
                g_pCurEmbData->appendAEmbAbsFile(m_curFilePath,absAry,cmirror);//添加文件
            }
        }

        changeFlag = 1;//数据发生变化
        //qDebug()<<"RepeatNum end";
    }

    //针步补偿，为了使绣品加粗或变细
    g_pCurEmbData->setNeedleXYCompensation(m_fileHead.xCompensate,m_fileHead.yCompensate);
    //qDebug()<<"setNeedleXYCompensation end";

    //将绣花机中需要插入跳针的针步大小传入到g_pCurEmbData中
    g_pCurEmbData->setConvertSkipStepSize(m_fileHead.convertJumpStepSize,m_fileHead.jumpStepSize);
    //qDebug()<<"setConvertSkipStepSize end";

    //当为褶绣时需要修改褶绣跳针下一针的针步角度
    g_pCurEmbData->modifyStepAngle(m_fileHead.pleatedMode);
	
	u16 stepUnit = 1;
    if(m_stepDrive == 1)
    {
        stepUnit =10;
    }
     g_pCurEmbData->setDataStepUnit(stepUnit);

    //如果数据变换了需要将数据及图形居中(不需要居中，居中定位点会变)
    if(changeFlag == 1)
    {
#if(0)
        //        g_pCurEmbData->getAbsDatRangeXY();//获得宽高范围
        //        g_pCurEmbData->setToMiddle();
#endif
    }

    //保存参数配置
    m_pMainWidgetFunction->setPatternHeadConfig(m_curFilePath,m_fileHead);//打开fcg或者生成fcg文件，读取和写入
    //qDebug()<<"setPatternHeadConfig end";



#if(0)
    //按色绣作,反复时才生效(4:按色通常、5:按色X轴、6:按色Y轴、7:按色XY)
    if((m_fileHead.xRepeatNum > 1 ||
        m_fileHead.yRepeatNum > 1) &&
            m_fileHead.repeatStyle >= 4 &&
            m_fileHead.repeatStyle <= 7 )
    {
        g_pCurEmbData->getDsDat();//转换为ds16数据
        int num = xRepeatNum * yRepeatNum;
        g_pCurEmbData->createSameColorEmbDs16Dat(num);
    }
#endif

    //qDebug()<<"resetAllData begin";
    resetAllData(); //显示全部花样区域
    //qDebug()<<"resetAllData end";

    //保存毛巾高度设置
    //反复次数大于1，毛巾高度也循环
    if(xRepeatNum > 1 || yRepeatNum > 1)
    {
        int repeatNums =  xRepeatNum * yRepeatNum;
        int towelHighNums = g_pCurEmbData->getTowelHighNums() / repeatNums+1;
        for(s16 i = 0; i < repeatNums; i++)
        {
            if(i != 0)
            {
                if((u16)(i*towelHighNums+towelHighNums) <= m_towelHeightTable.size())
                {
                    memcpy(m_towelHeightTable.data()+i*towelHighNums, m_towelHeightTable.data(), towelHighNums);
                }
            }
        }
    }
    m_pMainWidgetFunction->setPatternTowelHeightFcg(m_curFilePath,m_towelHeightTable);
    //qDebug()<<"setPatternTowelHeightFcg end";

#if (1)
    //先转换为ds16数据，在把计算的fileid写回ds16
    //paraId   是计算fcg中数值，不存在fcg时，旋转式样这些是默认值
    u32 paraId = calcCrc16((u8*)(&m_fileHead.coloLockrNeedle),
                           ((&m_fileHead.lockNeedlesStepLength) - (&m_fileHead.coloLockrNeedle) + 1)*sizeof(s32));  
    u32 paraId1 = calcCrc16((u8*)(&m_fileHead.convertJumpStepSize),
                           ((&m_fileHead.pleatedMode) - (&m_fileHead.convertJumpStepSize) + 1)*sizeof(u16));
    paraId += paraId1;
    u32 headFileId = g_pCurEmbData->getDsDatHead()->checkCrc + paraId;//ds16文件头的crc + paraId
    g_pCurEmbData->setDsDatHeadFileID(headFileId);      //将计算得到的fileid写回到数据区ds16
    qDebug()<<"headFileId"<<headFileId;
#else
    //计算原数据的数据唯一ID和花样参数的ID
    u32 headFileId = g_pCurEmbData->getDsDatHead()->fileid;
    //改变锁针也需要从头开始绣作，所以fileid将锁针属性加进去
    u32 paraId = calcCrc16((u8*)(&m_fileHead.rotateStyle),
                           ((&m_fileHead.lockNeedlesStepLength) - (&m_fileHead.rotateStyle) + 1)*sizeof(s32));
    //    u32 paraId = calcCheckSum32((u8*)(&m_fileHead.rotateAngle),
    //                                (&m_fileHead.yCompensate) - (&m_fileHead.rotateAngle) + sizeof(s32));

    g_pCurEmbData->getDsDatHead()->fileid = headFileId+paraId;
    g_pCurEmbData->setDsDatHeadFileID();//将计算得到的fileid写回到数据区

#endif
    showPatternPreview();
}

void MainWidget::slotRefreshPattern()
{  
    //更新亮片颜色列表
    for(int i = 0; i < SEQUIN_NUM; i++)
    {
        QString idxStr = "SequinColor/"+QString::number(i+1)+"_coloridx";

        if(g_pSettings->ifKeyExists(idxStr) == true)
        {
            int idx = g_pSettings->readFromIniFile(idxStr).toInt();
            g_pCurEmbData->setSequinColorTable(i,idx);
        }
        else
        {
            g_pCurEmbData->setSequinColorTable(i,i);
        }
    }

    //更新散珠颜色列表
    for(int i = 0; i < BEAD_NUM; i++)
    {
        QString idxStr = "BeadColor/"+QString::number(i+1)+"_coloridx";

        if(g_pSettings->ifKeyExists(idxStr) == true)
        {
            int idx = g_pSettings->readFromIniFile(idxStr).toInt();
            g_pCurEmbData->setBeadColorTable(i,idx);
        }
        else
        {
            g_pCurEmbData->setBeadColorTable(i,i);
        }
    }

    //刷新右上方颜色列表显示
    refreshShowColorUi();
}

//色序设定之后重新刷新花样并发送文件头双头
void MainWidget::slotColorOrderChange(s16 combineMode,s16 threeCombineMode)
{
    m_fileHead.combineMode = combineMode;
    m_fileHead.threeCombineMode = threeCombineMode;

    g_pCurEmbData->setDs16ColorOfTable(m_fileHead.switchTable);
    //保存参数配置
    m_pMainWidgetFunction->setPatternHeadConfig(m_curFilePath,m_fileHead);//打开fcg或者生成fcg文件，读取和写入

    reSetPatternData();
    refreshShowColorUi();

    m_pMainWidgetFunction->funColorOrderChange(m_curFilePath,m_pColorOrderSetWi->getHeadBuf(),combineMode);
}

void MainWidget::slotTowelHighChange()
{
    //判断花版是否反复，反复的话毛巾高度也反复
    //反复次数
    int xRepeatNum = m_fileHead.xRepeatNum;
    int yRepeatNum = m_fileHead.yRepeatNum;

    //反复次数大于1
    if(xRepeatNum > 1 || yRepeatNum > 1)
    {
        int repeatNums =  xRepeatNum * yRepeatNum;
        int towelHighNums = g_pCurEmbData->getTowelHighNums() / repeatNums+1;
        for(s16 i = 0; i < repeatNums; i++)
        {
            if(i != 0)
            {
                if((u16)(i*towelHighNums+towelHighNums) <= m_towelHeightTable.size())
                {
                    memcpy(m_towelHeightTable.data()+i*towelHighNums, m_towelHeightTable.data(), towelHighNums);
                }
            }
        }
    }

    m_pMainWidgetFunction->setPatternTowelHeightFcg(m_curFilePath,m_towelHeightTable);
    m_pMainWidgetFunction->sendPatternTowelHeightData(m_curFilePath);
}

//设置隔头绣按钮是否可按
void MainWidget::slotSetHeadEmbBtnEnable(bool bl)
{
    //隔头绣不可按
    for(int i = 0; i < m_embFunctionItemList.size(); i++)
    {
        if(m_embFunctionItemList[i].m_enumFunction == EMBFUN_HEADEMB)
        {
            m_embFunctionBtnList[i]->setEnabled(bl);
            break;
        }
    }
}

void MainWidget::slotReSetEmbData(QByteArray table)
{
    //色序设定取消后恢复未设置色序的色序表(有反复时需要范围)
    memcpy(m_fileHead.switchTable,table,sizeof(m_fileHead.switchTable));
}

void MainWidget::slotReSetTowelHigh(QByteArray table)
{
    if(table.length() < m_towelHeightTable.length())
    {
        return;
    }
    memcpy(m_towelHeightTable.data(),table.data(),m_towelHeightTable.length());
}

//隔头绣
void MainWidget::slotHeadEmb()
{
    if (g_emMacType == MACHINE_EMB )               //绣花机
    {
        m_pMainWidgetFunction->funHeadEmb(m_curFilePath);
    }
    else
    {
        m_pMainWidgetFunction->funQuiHeadEmb(m_curFilePath);
    }
}

//显示动框角度设置界面
void MainWidget::slotShowFrameAngleWi()
{
    if(m_pSheetWi != NULL)
    {
        QString topImageName;
        for(int i = 0; i < m_assistItemList.size(); i++)
        {
            if(m_assistItemList[i].m_enumFunction == ASSIST_ROOT)//动框角度界面用超级用户的图标
            {
                topImageName = m_assistItemList[i].m_topImageName;
                break;
            }
        }

        //加载按钮顶图图标
        QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

        m_pSheetWi->setTypeLogo(tStyle);
        m_pSheetWi->setMainTitle(tr("Frame angle setting"));//动框角度设置
        m_pSheetWi->setSubTitle(tr("Root > Frame angle setting"));//超级用户 > 动框角度设置
        m_pSheetWi->setMinMax();
        m_pSheetWi->show();
    }
}
void MainWidget::slotEmbWorkArea()
{
    if (m_pSetWorkAreaWi != NULL)
    {
        m_pSetWorkAreaWi->setTitleStr(tr("Flat embroidery setting workable area"));
        m_pSetWorkAreaWi->setHead(FLATEMB);
        m_pSetWorkAreaWi->show();
    }
}
void MainWidget::slotChenWorkArea()
{
    if (m_pSetWorkAreaWi != NULL)
    {
        m_pSetWorkAreaWi->setTitleStr(tr("Chenille setting workable area"));
        m_pSetWorkAreaWi->setHead(TOWEL);
        m_pSetWorkAreaWi->show();
    }
}
void MainWidget::slotCoilWorkArea()
{
    if (m_pSetWorkAreaWi != NULL)
    {
        m_pSetWorkAreaWi->setTitleStr(tr("Coil embroidery setting workable area"));
        m_pSetWorkAreaWi->setHead(COIL);
        m_pSetWorkAreaWi->show();
    }
}
//每十万针主界面加载图片的进度条走一格
void MainWidget::slotChangeProgressBar(int value)
{
    ui->progressBar->setValue(value);
}

//快捷功能中的快捷按钮被点击
void MainWidget::slotQuickBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_quickBtnList.size(); i++)
    {
        if(button == m_quickBtnList[i])
        {
            int idx = (m_curPages-1)*m_itemPerPage+i;

            int enumFun = m_quickItemList[idx].m_enumFunction;
            runCommonBtnFunction(enumFun);
            break;
        }
    }
}

//界面下方的快捷按钮被点击
void MainWidget::slotShortCutBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //判断哪个快捷按钮被按下，获取功能索引并执行相关操作
    for(int i = 0; i < m_shortCutBtnList.size(); i++)
    {
        if(button == m_shortCutBtnList[i])
        {
            int commonBtnIdx = g_pSettings->readFromIniFile("HMI/commonbtn"+QString::number(i+1)).toInt();
            runCommonBtnFunction(commonBtnIdx);
            break;
        }
    }
}

//辅助功能中的辅助功能按钮被点击
void MainWidget::slotAssistBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_assistBtnList.size(); i++)
    {
        if(button == m_assistBtnList[i])
        {
            int idx = (m_curPages-1)*m_itemPerPage+i;
            int enumFun = m_assistItemList[idx].m_enumFunction;
            runAssistBtnFunction(enumFun,i);
            break;
        }
    }
}

//花样设置中的花样设置按钮被点击
void MainWidget::slotPatternSetBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_patternSetBtnList.size(); i++)
    {
        if(button == m_patternSetBtnList[i])
        {
            int enumFun = m_patternSetItemList[i].m_enumFunction;
            runPatternSetBtnFunction(enumFun,i);
            break;
        }
    }
}

//参数设置中的参数功能按钮被点击
void MainWidget::slotParaTypeBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    QString bStyle = m_setControlStyle.getBottomStyleSheet(ui->buttonParaSet->parent()->objectName());
    QString tStyle = m_setControlStyle.getTopStyleSheet(ui->buttonParaSet->objectName());

    m_pParameterSetDlg->setTypeLogo(tStyle);
    m_pParameterSetDlg->setMainTitle(tr("Parameter setting"));

    //执行快捷按钮动作
    for(int i = 0; i < m_paraSetBtnList.size(); i++)
    {
        if(button == m_paraSetBtnList[i])
        {
            int paraType = m_paraSetItemList[i].m_paraType;
            QString subStr;
            int64_t sort = -1;

            switch (paraType)
            {
            case PARASET_EMB:
                subStr = tr("Emb parameters");//绣花参数
                sort = MC_SORT_EMB;
                break;

            case PARASET_CHEN:
                subStr = tr("Chenille parameters");//毛巾参数
                sort = MC_SORT_CHEN;
                break;

            case PARASET_FEED:
                subStr = tr("Feed parameters");//上下料参数
                sort = MC_SORT_FEED;
                break;
            case PARASET_SHUTTLE:
                subStr = tr("Shuttle parameters");//自动换梭参数
                sort = MC_SORT_SHUTTLE;
                break;
            case PARASET_LASER:
                subStr = tr("Laser parameters");//激光参数
                sort = MC_SORT_LASER;
                break;
            case PARASET_SETTING:
                subStr = tr("Setting parameters");//设置参数
                sort = MC_SORT_SETTING;
                break;
            case PARASET_CUT:
                subStr = tr("Cut parameters");//剪线参数
                sort = MC_SORT_CUT;
                break;
            case PARASET_COIL:
                subStr = tr("Coil parameters");//缠绕参数
                sort = MC_SORT_COIL;
                break;
            case PARASET_TRACKROPR:
                subStr = tr("Tracking rope parameters");//跟踪绳绣参数
                sort = MC_SORT_TRACKROPR;
                break;
           case PARASET_SQU:
            {
                subStr = tr("Sequin parameters");//亮片参数
                int doubleFlag = g_pMachine->getMcPara().buf[15]&0x80;//bit7,亮片装置类型,0,非双亮片	1,双亮片
                if(doubleFlag == 0)
                {
                    sort = MC_SORT_DOUBLE_SEQUIN|MC_SORT_EIGHT_SEQUIN;//显示双亮片参数和八亮片参数
                }
                else
                {
                    sort = MC_SORT_DOUBLE_SEQUIN;//只显示双亮片参数
                }
            }
            break;
            case PARASET_BEAD:
                subStr = tr("Bead parameters");//散珠参数
                sort = MC_SORT_BEAD;
                break;
            case PARASET_SIMPLETOWEL:
                subStr = tr("Simple chenille parameters");//简易毛巾参数
                sort = MC_SORT_SIMPLETOWEL;
                break;
            default:
                subStr = tr("Parameter setting");//参数设置
                sort = -1;
                break;
            }

            m_pParameterSetDlg->setSubTitle(tr("Parameter setting > ") + subStr);//参数设置 >
            //机器参数和工作参数
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK,sort);
            m_pParameterSetDlg->exec();
            break;
        }
    }
}

//刺绣功能中的刺绣功能按钮被点击
void MainWidget::slotEmbFunctionBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_embFunctionBtnList.size(); i++)
    {
        if(button == m_embFunctionBtnList[i])
        {
            int enumFun = m_embFunctionItemList[i].m_enumFunction;
            runEmbFunctionBtnFunction(enumFun,i);
            break;
        }
    }
}

//设置超级用户图标
void MainWidget::slotSetButtonRootLogo(int level)
{
    ui->buttonUser->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonUser->objectName()+QString::number(level)));
}

void MainWidget::slotEXBUpgrade(u8 protocol, u8 nodeid, u8 nodeType)
{
    QString topImageName = "buttonEXBUpgrade";
    //加载按钮顶图图标
    QString bStyle = m_setControlStyle.getTopStyleSheet(topImageName);
    QString tStyle = m_setControlStyle.getTopStyleSheet(ui->buttonAssist1->objectName());

    if(m_pMainWidgetFunction != NULL)
    {
        m_pMainWidgetFunction->funEXBUpgrade(tStyle,protocol,nodeid,nodeType);
    }
}

//清空花版断线次数
void MainWidget::slotClearPatternBreakLineNum()
{
    m_fileHead.breakLineParkNum = 0;
}

//边框检查超限后重新定定位点(起绣点)
void MainWidget::slotResetStartPos(DataFilePos pos)
{
    //ui->labelTitle->setText("receive signal");
    if(m_pMainWidgetFunction != NULL)
    {
        //ui->labelTitle->setText("receive before");
        m_pMainWidgetFunction->funResetStartPoint(m_curFilePath,pos);
        double xPos = g_pCurEmbData->m_beginX*0.01;
        ui->labelXValue->setText(QString("%1").arg(xPos));
        double yPos = g_pCurEmbData->m_beginY*0.01;
        ui->labelYValue->setText(QString("%1").arg(yPos));
        //ui->labelTitle->setText("receive end");
    }
}

void MainWidget::slotDebugState()
{
    if(g_emDebugMode == debugMode)
    {
        ui->labelTitle->setStyleSheet(LABELREDSTYLE);
    }
    else
    {
        ui->labelTitle->setStyleSheet(LABELWHITESTYLE);
    }
}
void MainWidget::slotCloseRootPara()
{
    g_emUser = operate;
    m_pParameterSetDlg->done(0);
}

void MainWidget::onRefreshPatternTimer()
{
    // 文件执行进度(当前针数) labelNeedleIdx
    m_curDatIdx++;
    reSetDatIdx(m_curDatIdx);
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);
}


//1秒定时器
void MainWidget::onOneSecondTimer()
{
    // 获取系统当前时间
    QDateTime dateTime = QDateTime::currentDateTime();
    ui->labelTime->setText(dateTime.toString("yyyy/MM/dd HH:mm:ss"));
    refConnectUi(dateTime.time().second());//刷新连接
}

//5秒定时器
void MainWidget::onFiveSecondTimer()
{
    if(m_conFlag == 0)//已连接
    {

    }
    else
    {
        g_pMachine->setTcpConnectState(1);//将连接状态置为1
    }
    m_conFlag = -1;
}

void MainWidget::onTenMiniteTimer()
{
    s16 rel = m_pMainWidgetFunction->detectWifiConnect();
    if(rel > 0)//已连接
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Connect"));
    }
    else
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Unconnect"));
    }
}

//1分钟定时器,记录当前系统时间,用于上电时  计算  关机时间
void MainWidget::onOneMinTimer()
{
    // 获取系统当前时间
    QDateTime dateTime = QDateTime::currentDateTime();
    g_pSettings->writeToIniFile(("DateTime/second"),dateTime.toTime_t());//单位为秒
#if(0)
    //30天自动删除是只删除超过30天的记录
    //文件路径
    QDir apppath(qApp->applicationDirPath());
    QString csvfile;
    csvfile = apppath.path() + apppath.separator() + CSV_FILEID;
    //获取文件的创建时间
    QFileInfo info(csvfile);
    qDebug() << info.size();//获取文件大小
    QDateTime dt = info.created();//获取文件创建时间
    int days = dt.daysTo(dateTime);//获取文件相对于当前时间的天数
    if (days >30)
    {
        QFile::remove(csvfile);//大于30天，删除这个文件
    }
#endif
}

//刷新版本信息
void MainWidget::onRefreshVer()
{
    //版本显示
    QString verStr = m_pMainWidgetFunction->getVersionStr();
    //    verStr.sprintf("XPlatForm-RP-HMI-L1910-V%d.%02d.%02d",
    //                   EMB_VER_CODE_Y,
    //                   EMB_VER_CODE_M,
    //                   EMB_VER_CODE_D);
#if(0)
    QString boardVerStr;
    MCInfo info1 = g_pMachine->getMcInfo();

    char softwareVerStr[32+1];//软件版本
    memcpy(softwareVerStr, info1.softwareVerStr, 32);
    softwareVerStr[32] = 0;
    QString strBoardVer;
    strBoardVer.sprintf("%s", softwareVerStr);
    if(strBoardVer.length() > 6)
    {
        QString str1;
        str1 = strBoardVer.right(6);
        boardVerStr = "-DewMock-V" + str1;
    }
#endif
    ui->labelHMIVersion->setText(verStr);//界面版本
}

//主界面
void MainWidget::on_buttonMainMenu_clicked()
{
    hideMenuFrame();
    showPatternPreview();
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

//花样设置
void MainWidget::on_buttonPatternSet_clicked()
{
#if(0)
    //如果为当前显示页面，再点击时需隐藏，显示花样页面
    if(ui->framePatternSet->isVisible())
    {
        showPatternPreview();
    }
#endif
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->framePatternSet->setVisible(true);
    ui->buttonPatternSet->setCheckable(true);
    ui->buttonPatternSet->setChecked(true);
}

//参数设定按钮
void MainWidget::on_buttonParaSet_clicked()
{
    int doubleFlag = 0;
    if(g_pMachine != NULL)
    {
        ParaStruct mcParaValues;
        mcParaValues = g_pMachine->getMcPara();
        doubleFlag = mcParaValues.buf[15]&0x80;//bit7,亮片装置类型,0,非双亮片	1,双亮片
    }

    s16 paraSort = g_pSettings->readFromInHMIiFile("HMI/paraSort").toInt();

    if(paraSort == 1)//分类显示参数
    {
        hideMenuFrame();
        ui->frameMenuBack->setVisible(true);
        ui->frameParaSet->setVisible(true);
        ui->buttonParaSet->setCheckable(true);
        ui->buttonParaSet->setChecked(true);
    }
    else if(paraSort == 0)//不分类显示参数
    {
        showPatternPreview();

        //QString bStyle = m_setControlStyle.getBottomStyleSheet(ui->buttonParaSet->parent()->objectName());
        QString tStyle = m_setControlStyle.getTopStyleSheet(ui->buttonParaSet->objectName());

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Parameter setting"));
        m_pParameterSetDlg->setSubTitle(tr("Parameter setting > Parameter setting"));
        //机器参数和工作参数
        if(doubleFlag == 0)//显示双亮片参数和八亮片参数
        {
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK,MC_SORT_SETTING|MC_SORT_POSITION|MC_SORT_SPEED|MC_SORT_DETECT|MC_SORT_ACTION|MC_SORT_EMB|MC_SORT_CHEN|MC_SORT_FEED|MC_SORT_SHUTTLE|MC_SORT_LASER|MC_SORT_CUT|MC_SORT_COIL|MC_SORT_DOUBLE_SEQUIN|MC_SORT_EIGHT_SEQUIN|MC_SORT_BEAD|MC_SORT_SIMPLETOWEL|MC_SORT_TRACKROPR);
        }
        else
        {
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK,MC_SORT_SETTING|MC_SORT_POSITION|MC_SORT_SPEED|MC_SORT_DETECT|MC_SORT_ACTION|MC_SORT_EMB|MC_SORT_CHEN|MC_SORT_FEED|MC_SORT_SHUTTLE|MC_SORT_LASER|MC_SORT_CUT|MC_SORT_COIL|MC_SORT_DOUBLE_SEQUIN|MC_SORT_BEAD|MC_SORT_SIMPLETOWEL|MC_SORT_TRACKROPR);
        }
        m_pParameterSetDlg->exec();
    }
}

//刺绣功能按钮
void MainWidget::on_buttonEmbFunction_clicked()
{
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->frameEmbFunction->setVisible(true);
    ui->buttonEmbFunction->setCheckable(true);
    ui->buttonEmbFunction->setChecked(true);
}

//快捷功能按钮
void MainWidget::on_buttonShortcutFunction_clicked()
{
    m_curPages = 1; // 当前页
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->frameShortcutFunction->raise();
    ui->frameShortcutFunction->setVisible(true);
    ui->buttonShortcutFunction->setCheckable(true);
    ui->buttonShortcutFunction->setChecked(true);
    if(m_quickItemList.size() > m_itemPerPage)
    {
        ui->buttonShortCutPgDn->setVisible(true);
        ui->buttonShortCutPgUp->setVisible(true);
        ui->labelShortCutPage->setVisible(true);
        refreshPageUi(INTERFACE_SHORTCUT);
    }
}

//辅助功能按钮
void MainWidget::on_buttonAccessFunction_clicked()
{
    m_curPages = 1; // 当前页
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->frameAccessFunction->setVisible(true);
    ui->buttonAccessFunction->setCheckable(true);
    ui->buttonAccessFunction->setChecked(true);
    if(m_assistItemList.size() > m_itemPerPage)
    {
        ui->buttonAssistPgDn->setVisible(true);
        ui->buttonAssistPgUp->setVisible(true);
        ui->labelAssistPage->setVisible(true);
        refreshPageUi(INTERFACE_ACCESS);
    }
}

void MainWidget::on_buttonUp_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    //移动图片
    m_imageMoveY = m_imageMoveY - 100;
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    QPixmap pix;
    pix = QPixmap(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    pix.fill(Qt::transparent);//用透明色填充
    QPainter painter(&pix);
    painter.translate(m_imageMoveX+ui->labelPatternPreView->width()/2-patternPix.width()/2,m_imageMoveY+ui->labelPatternPreView->height()/2-patternPix.height()/2); //将此点设为坐标原点
    painter.drawPixmap(0,0,patternPix.width(),patternPix.height(),patternPix);
    ui->labelPatternPreView->setPixmap(pix);
}

void MainWidget::on_buttonDown_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    //移动图片
    m_imageMoveY = m_imageMoveY + 100;
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    QPixmap pix;
    pix = QPixmap(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    pix.fill(Qt::transparent);//用透明色填充
    QPainter painter(&pix);
    painter.translate(m_imageMoveX+ui->labelPatternPreView->width()/2-patternPix.width()/2,m_imageMoveY+ui->labelPatternPreView->height()/2-patternPix.height()/2); //将此点设为坐标原点
    painter.drawPixmap(0,0,patternPix.width(),patternPix.height(),patternPix);
    ui->labelPatternPreView->setPixmap(pix);
}

void MainWidget::on_buttonLeft_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    //移动图片
    m_imageMoveX = m_imageMoveX - 100;
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    QPixmap pix;
    pix = QPixmap(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    pix.fill(Qt::transparent);//用透明色填充
    QPainter painter(&pix);
    painter.translate(m_imageMoveX+ui->labelPatternPreView->width()/2-patternPix.width()/2,m_imageMoveY+ui->labelPatternPreView->height()/2-patternPix.height()/2); //将此点设为坐标原点
    painter.drawPixmap(0,0,patternPix.width(),patternPix.height(),patternPix);
    ui->labelPatternPreView->setPixmap(pix);
}

void MainWidget::on_buttonRight_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    //移动图片
    m_imageMoveX = m_imageMoveX + 100;
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    QPixmap pix;
    pix = QPixmap(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    pix.fill(Qt::transparent);//用透明色填充
    QPainter painter(&pix);
    painter.translate(m_imageMoveX+ui->labelPatternPreView->width()/2-patternPix.width()/2,m_imageMoveY+ui->labelPatternPreView->height()/2-patternPix.height()/2); //将此点设为坐标原点
    painter.drawPixmap(0,0,patternPix.width(),patternPix.height(),patternPix);
    ui->labelPatternPreView->setPixmap(pix);
}

void MainWidget::on_buttonAuto_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    //图形恢复原状
    m_imageMoveX = 0;
    m_imageMoveY = 0;
    m_imageZoom = 0;

    g_pCurEmbData->setViewInfo(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    g_pCurEmbData->setEmbData();//ds16数据转换为画图数据
    m_dispMode = EmbData::DISP_ALL_NORMAL;
    g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);       // 重新画图

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternPreView->setPixmap(patternPix);
}

void MainWidget::on_buttonZoom_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    int width = ui->labelPatternPreView->width();
    int height = ui->labelPatternPreView->height();
    int maxSide = width * 0.6;
    if(maxSide < height)
    {
        maxSide = height * 0.6;
    }
    m_imageZoom = m_imageZoom + maxSide;//花样图片缩放值
    if(m_imageZoom > maxSide * 3)
    {
        m_imageZoom = m_imageZoom - maxSide;
        return;
    }
    g_pCurEmbData->setViewInfo(width + m_imageZoom,height + m_imageZoom);
    g_pCurEmbData->setEmbData();//ds16数据转换为画图数据
    m_dispMode = EmbData::DISP_ALL_NORMAL;
    g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);       // 重新画图
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();

    //移动图片
    QPixmap pix;
    pix = QPixmap(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    pix.fill(Qt::transparent);//用透明色填充
    QPainter painter(&pix);
    painter.translate(m_imageMoveX+ui->labelPatternPreView->width()/2-patternPix.width()/2,m_imageMoveY+ui->labelPatternPreView->height()/2-patternPix.height()/2); //将此点设为坐标原点
    painter.drawPixmap(0,0,patternPix.width(),patternPix.height(),patternPix);
    ui->labelPatternPreView->setPixmap(pix);
}

void MainWidget::on_buttonNarrow_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    int width = ui->labelPatternPreView->width();
    int height = ui->labelPatternPreView->height();
    int maxSide = width * 0.6;
    if(maxSide < height)
    {
        maxSide = height * 0.6;
    }

    m_imageZoom = m_imageZoom - maxSide;//花样图片缩放值
    if(m_imageZoom < 0)
    {
        m_imageZoom = m_imageZoom + maxSide;
        return;
    }
    g_pCurEmbData->setViewInfo(width + m_imageZoom,height + m_imageZoom);

    m_dispMode = EmbData::DISP_ALL_NORMAL;
    g_pCurEmbData->setEmbData();//ds16数据转换为画图数据
    g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();

    //移动图片
    QPixmap pix;
    pix = QPixmap(ui->labelPatternPreView->width(),ui->labelPatternPreView->height());
    pix.fill(Qt::transparent);//用透明色填充
    QPainter painter(&pix);
    painter.translate(m_imageMoveX+ui->labelPatternPreView->width()/2-patternPix.width()/2,m_imageMoveY+ui->labelPatternPreView->height()/2-patternPix.height()/2); //将此点设为坐标原点
    painter.drawPixmap(0,0,patternPix.width(),patternPix.height(),patternPix);
    ui->labelPatternPreView->setPixmap(pix);
}

void MainWidget::on_buttonMiddle_clicked()
{
    m_imageMoveX = 0;
    m_imageMoveY = 0;
    m_imageZoom = 0;

    bool bl = ui->buttonUp->isVisible();
    if(bl == true)
    {
        ui->labelPatternView->setVisible(true);//非预览模式绘制区域
        ui->labelPatternPreView->setVisible(false);//预览模式绘制区域

        g_pCurEmbData->setDrawMode(EmbData::DRAW_VIEW);//非预览模式
        g_pCurEmbData->setViewInfo(m_embBackPix);//带背景图的背景
        g_pCurEmbData->setEmbData();//ds16数据转换为画图数据

        m_dispMode = EmbData::DISP_ALL_EXEC;
        g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 重新画图

        m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
        g_pCurEmbData->setDispMode(m_dispMode, 0,m_gradientFlag);       // 设置为按进度执行模式
        g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度

        setZoomMoveBtnVisible(false);
        //ui->frameColor->show();
        //ui->framePatternInfo->show();

        QPixmap patternPix = g_pCurEmbData->getPreviewImage();
        ui->labelPatternView->setPixmap(patternPix);
    }
    else
    {
        //透明背景
        ui->labelPatternView->setVisible(false);//非预览模式绘制区域
        ui->labelPatternPreView->setVisible(true);//预览模式绘制区域
        g_pCurEmbData->setDrawMode(EmbData::DRAW_PREVIEW);//非预览模式
        g_pCurEmbData->setViewInfo(ui->labelPatternPreView->width() - 4,ui->labelPatternPreView->height() - 4);//留4个像素为了生成花样轮廓的边界采集
        g_pCurEmbData->setEmbData();//ds16数据转换为画图数据

        //图形恢复原状
        m_dispMode = EmbData::DISP_ALL_NORMAL;
        g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);       // 重新画图

        setZoomMoveBtnVisible(true);
        //ui->frameColor->hide();
        //ui->framePatternInfo->hide();

        QPixmap patternPix = g_pCurEmbData->getPreviewImage();
        ui->labelPatternPreView->setPixmap(patternPix);
    }
}

void MainWidget::on_buttonPreNode_clicked()
{
    m_nodeIdx--;

    if(m_nodeIdx < 0)
    {
        m_nodeIdx = 0;
    }

    refreshOpenLineInfo();
}

void MainWidget::on_buttonNextNode_clicked()
{
    m_nodeIdx++;

    if(m_nodeIdx > NODENUMBER -1)
    {
        m_nodeIdx = NODENUMBER -1;
    }

    refreshOpenLineInfo();
}

void MainWidget::on_buttonSetNode_clicked()
{
    if(m_nodeList.size() < m_nodeIdx+1)
    {
        return;
    }

    if(m_nodeIdx > NODENUMBER -1)
    {
        m_nodeIdx = 0;
    }

    int x = m_mcStatus.xPos;
    int y = m_mcStatus.yPos;

    m_nodeList[m_nodeIdx].nodeX = x;
    m_nodeList[m_nodeIdx].nodeY = y;

    m_nodeIdx++;

    if(m_nodeIdx == NODENUMBER)
    {
        m_nodeIdx = 0;
    }

    double nodeX = m_nodeList[m_nodeIdx].nodeX*0.01;
    double nodeY = m_nodeList[m_nodeIdx].nodeY*0.01;
    QString xStr = QString("%1").arg(nodeX);
    QString yStr = QString("%1").arg(nodeY);
    ui->labelCoorXValue->setText(xStr);
    ui->labelCoorYValue->setText(yStr);
    ui->labelCurNodeValue->setText(QString::number(m_nodeIdx+1));
}

void MainWidget::on_buttonNodeDelete_clicked()
{
    if(m_nodeList.size() < m_nodeIdx+1)
    {
        return;
    }

    m_nodeList[m_nodeIdx].nodeX = 0;
    m_nodeList[m_nodeIdx].nodeY = 0;

    ui->labelCoorXValue->setText("0");
    ui->labelCoorYValue->setText("0");
}

void MainWidget::on_buttonOpenLineOk_clicked()
{
    //生成开位线绣数据并保存成配置文件
    if(g_pCurEmbData == NULL)
    {
        return;
    }

    QByteArray datAry;
    datAry.clear();

    datAry.append(g_pCurEmbData->createOpenLineEmbData(m_nodeList)); // 生成开位线绣数据
    g_pCurEmbData->setViewInfo(m_embBackPix);
    g_pCurEmbData->clear();//清空当前选择的花样

    if(datAry.length() <= 0)
    {
        return;
    }

    g_pCurEmbData->appendAEmbAbsFile(m_curFilePath,datAry);//生成文件信息
    resetAllData();
    showPatternPreview();
    QString str = tr("Open line embroidery");//开位线绣
    ui->labelFilename->setText(str);

    m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送开位线绣数据
    //设置为按进度执行模式
    g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度

    //开位线绣模式色序和花样参数不可按
    ui->buttonNeedle->setEnabled(false);
    ui->buttonPatternInfo->setEnabled(false);
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
        {
            m_patternSetBtnList[i]->setEnabled(false);
        }
    }

    for(int i = 0; i < m_nodeList.size(); i++)
    {
        g_pSettings->writeToIniFile(("OpenLine/nodeX"+QString::number(i+1)),m_nodeList[i].nodeX);
        g_pSettings->writeToIniFile(("OpenLine/nodeY"+QString::number(i+1)),m_nodeList[i].nodeY);
    }

    ui->frameOpenLineEmb->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonNineBtn4->setEnabled(true);//锁界面可用
}

void MainWidget::on_buttonOpenLineClose_clicked()
{
    //恢复之前的数据
    m_nodeList.clear();
    for(int i = 0; i < NODENUMBER; i++)
    {
        int nodeX = g_pSettings->readFromIniFile("OpenLine/nodeX"+QString::number(i+1)).toInt();
        int nodeY = g_pSettings->readFromIniFile("OpenLine/nodeY"+QString::number(i+1)).toInt();

        OpenLineNode node;
        node.nodeX = nodeX;
        node.nodeY = nodeY;

        m_nodeList.append(node);
    }

    ui->frameOpenLineEmb->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonNineBtn4->setEnabled(true);//锁界面可用
}

//速度加
void MainWidget::on_buttonSpeedAdd_clicked()
{
    if(g_pMachine != NULL)
    {
        int speed = 0;
        if(m_speedLevel == 1)
        {
            speed = 10;
        }
        else if(m_speedLevel == 2)
        {
            speed = 50;
        }
        else if(m_speedLevel == 3)
        {
            speed = 100;
        }

        g_pMachine->msRpmChange(speed,0);
    }
}

//速度减
void MainWidget::on_buttonSpeedDec_clicked()
{
    if(g_pMachine != NULL)
    {
        int speed = 0;
        if(m_speedLevel == 1)
        {
            speed = -10;
        }
        else if(m_speedLevel == 2)
        {
            speed = -50;
        }
        else if(m_speedLevel == 3)
        {
            speed = -100;
        }

        g_pMachine->msRpmChange(speed,0);
    }
}

void MainWidget::on_buttonNineBtnUp_pressed()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet("frameNineBtnUp"));
    if(g_pMachine != NULL)
    {
        g_pMachine->manualAction(XY_MOVE_FRONT, m_speedLevel);
    }
}

void MainWidget::on_buttonNineBtnUp_released()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        g_pMachine->motoMove(XY_MOVE_FRONT, MT_MOVE_DIR_STOP, 0);
    }
}

void MainWidget::on_buttonNineBtnDown_pressed()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet("frameNineBtnDown"));
    if(g_pMachine != NULL)
    {
        g_pMachine->manualAction(XY_MOVE_BACK, m_speedLevel);
    }
}

void MainWidget::on_buttonNineBtnDown_released()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        g_pMachine->motoMove(XY_MOVE_BACK, MT_MOVE_DIR_STOP, 0);
    }
}

void MainWidget::on_buttonNineBtnLeft_pressed()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet("frameNineBtnLeft"));
    if(g_pMachine != NULL)
    {
        g_pMachine->manualAction(XY_MOVE_LEFT, m_speedLevel);
    }
}

void MainWidget::on_buttonNineBtnLeft_released()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        g_pMachine->motoMove(XY_MOVE_LEFT, MT_MOVE_DIR_STOP, 0);
    }
}

void MainWidget::on_buttonNineBtnRight_pressed()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet("frameNineBtnRight"));
    if(g_pMachine != NULL)
    {
        g_pMachine->manualAction(XY_MOVE_RIGHT, m_speedLevel);
    }
}

void MainWidget::on_buttonNineBtnRight_released()
{
    ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        g_pMachine->motoMove(XY_MOVE_RIGHT, MT_MOVE_DIR_STOP, 0);
    }
}

void MainWidget::on_buttonNineBtnMiddle_pressed()
{
    m_speedLevel = m_speedLevel + 1;
    if(m_speedLevel > 3)
    {
        m_speedLevel = 1;
    }

    bool cVal = ui->frameShortcutBtn->isEnabled();//按钮是否失能,是否锁界面

    if(cVal == true)
    {
        ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet("frameNineBtnMiddle"));
    }
}

void MainWidget::on_buttonNineBtnMiddle_released()
{
    bool cVal = ui->frameShortcutBtn->isEnabled();//按钮是否失能,是否锁界面

    if(cVal == true)
    {
        ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    }

    setFrameNineBtnStyle();
}

//绣花机：前进回退/////////绗绣机：定起绣点/
void MainWidget::on_buttonNineBtn1_clicked()
{
    if(g_emMacType == MACHINE_EMB)
    {
        funForwardOrBack();
    }
    else if(g_emMacType == QUIMACHINE_EMB)
    {
        m_pMainWidgetFunction->funSetStartPoint(m_curFilePath);
        double xPos = g_pCurEmbData->m_beginX*0.01;
        ui->labelXValue->setText(QString("%1").arg(xPos));
        double yPos = g_pCurEmbData->m_beginY*0.01;
        ui->labelYValue->setText(QString("%1").arg(yPos));
    }
}

//绣花机：锁针功能 ///////绗绣机：主轴点动
void MainWidget::on_buttonNineBtn2_clicked()
{
    if(g_emMacType == MACHINE_EMB)
    {
        if(g_pMachine != NULL)
        {
            if ((m_mcStatus.workStatus & WORK_STA_ENSTATE) == WORK_STA_ENSTATE) //允许状态
            {
                //禁止工作
                g_pMachine->setDisableWorkSta();
            }
            else //禁止状态
            {
                //允许工作
                g_pMachine->setEnableWorkSta();
            }
        }
    }
    else if(g_emMacType == QUIMACHINE_EMB)
    {
        m_pMainWidgetFunction->funSpindleJog();
    }
#if(0)
    //用于匹绣功能
    hideMenuFrame();
    showPatternPreview();

    ui->frameMateEmb->setVisible(true);
    ui->frameMateEmb->raise();//置于顶层

    setUiBtnEnable(false);
    ui->buttonNineBtn4->setEnabled(false);//锁界面不可用

    ui->buttonNineBtnUp->setEnabled(true);
    ui->buttonNineBtnDown->setEnabled(true);
    ui->buttonNineBtnLeft->setEnabled(true);
    ui->buttonNineBtnRight->setEnabled(true);
    ui->buttonNineBtnMiddle->setEnabled(true);
#endif
}

//工作状态切换
void MainWidget::on_buttonNineBtn3_clicked()
{
    //m_pRefreshPatternTimer->start();//测试花样实时刷新的定时器启动

    m_pMainWidgetFunction->funWorkState();
}

//绣花机：锁界面  ///////绗绣机：边框检查
void MainWidget::on_buttonNineBtn4_clicked()
{
    if(g_emMacType == MACHINE_EMB)
    {
        hideMenuFrame();
        showPatternPreview();
        ui->buttonMainMenu->setCheckable(true);
        ui->buttonMainMenu->setChecked(true);

        bool cVal = ui->frameShortcutBtn->isEnabled();//按钮是否失能,是否锁界面

        if(cVal == true)
        {
            ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn4->objectName()+"Unlock"));
            ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()+"Disable"));
            setZoomMoveBtnVisible(false);
            setUiBtnEnable(false);
        }
        else
        {
            ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn4->objectName()));
            ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
            setUiBtnEnable(true);
        }

        if(m_dispMode != EmbData::DISP_EXECING)//不是执行状态
        {
            g_pCurEmbData->setViewInfo(m_embBackPix);//带背景图的背景
            g_pCurEmbData->setEmbData();//ds16数据转换为画图数据

            m_dispMode = EmbData::DISP_ALL_EXEC;
            g_pCurEmbData->setDispMode(m_dispMode, 1,m_gradientFlag);    // 重新画图

            m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
            g_pCurEmbData->setDispMode(m_dispMode, 0,m_gradientFlag);       // 设置为按进度执行模式
            g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度

            QPixmap patternPix = g_pCurEmbData->getPreviewImage();
            ui->labelPatternView->setPixmap(patternPix);
        }
    }
    else if(g_emMacType == QUIMACHINE_EMB)
    {
          m_pMainWidgetFunction->funBorderCheck();
    }
}

//色序设定的快捷按钮
void MainWidget::on_buttonNeedle_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    patternColorSet();
}

//花样参数的快捷按钮
void MainWidget::on_buttonPatternInfo_clicked()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }

    showPatternPreview();
    slotShowPatternPara(m_curFilePath);
}

void MainWidget::on_buttonNeedleBegin_clicked()
{
    m_forwardBackNeedleIdx = 0;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleEnd_clicked()
{
    int needleNum = g_pCurEmbData->getStitchNums(); //总针数
    //m_forwardBackNeedleIdx = g_pCurEmbData->getStitchNums(); //总针数
    //可设置针数
    int rslt;
    NumerInputDialog ndlg(this);
    ndlg.setTitleStr(tr("needle num"));//针数
    ndlg.setUnitStr("");
    ndlg.setValueAndRange(m_forwardBackNeedleIdx, 1, needleNum, 0);
    rslt = ndlg.exec();

    if (rslt == 1)
    {
        s32 val = ndlg.getValue();
        m_forwardBackNeedleIdx = val;
    }

    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec1_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 1;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd1_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 1;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec10_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 10;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd10_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 10;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec100_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 100;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd100_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 100;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec1000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 1000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd1000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 1000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec10000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 10000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd10000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 10000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonColorDec_clicked()
{
    m_forwardBackColorIdx = m_forwardBackColorIdx - 1;
    addOrDecColorIdx(m_forwardBackColorIdx,-1);
}

void MainWidget::on_buttonColorAdd_clicked()
{
    m_forwardBackColorIdx = m_forwardBackColorIdx + 1;
    addOrDecColorIdx(m_forwardBackColorIdx,1);
}

void MainWidget::on_buttonForwardBackOk_clicked()
{
    if ((m_mcStatus.workStatus & WORK_STA_BUSY) != 0)    // 下位机在执行动作
    {
        return;
    }
    //g_pMachine->fastJump(m_expara.newIdx);//前进回退
#if(IFDYSENDMODE)
    {
        m_expara.mvFrameFlag = 1;
        int fileId = m_pMainWidgetFunction->getCurFileID();  //获取文件ID
        g_pMachine->setFileExecProgress(0, fileId, m_expara);   //发送执行进度
    }
#else
    {
        g_pMachine->fastJump(m_expara.newIdx);//前进回退
    }
#endif
    ui->frameForwardBack->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

void MainWidget::on_buttonForwardBackCancel_clicked()
{
    g_pCurEmbData->setExecIndex(m_curDatIdx);// 更新针数

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);

    ui->frameForwardBack->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

//退出登录
void MainWidget::on_buttonUser_clicked()
{
    //退回到无密码的普通用户
    if(g_emUser == repair || g_emUser == factory || g_emUser == root)
    {
        m_pMainWidgetFunction->funExitRoot();
        ui->buttonUser->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonUser->objectName()));
    }
}

//匹绣下针(进入匹绣)
void MainWidget::on_buttonNeedleDown_clicked()
{
    if(g_pMachine != NULL)
    {
        g_pMachine->enterClothEmbroidery();
    }
}

//匹绣抬针(退出匹绣)
void MainWidget::on_buttonNeedleUp_clicked()
{
    if(g_pMachine != NULL)
    {
        g_pMachine->exitClothEmbroidery();
    }
}

//退出匹绣
void MainWidget::on_buttonExitMateEmb_clicked()
{
    ui->frameMateEmb->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonNineBtn4->setEnabled(true);//锁界面可用
}

void MainWidget::mousePressEvent(QMouseEvent *e)
{
    if ( e->button() == Qt::LeftButton)
    {
        m_mousePressX = e->x();
        m_mousePressY = e->y();
        m_mouseReleaseX = 0;
        m_mouseReleaseY = 0;
    }
}

void MainWidget::mouseReleaseEvent(QMouseEvent *e)
{
    if ( e->button() == Qt::LeftButton)
    {
        m_mouseReleaseX = e->x();
        m_mouseReleaseY = e->y();
    }

    int width = this->width();
    int height = this->height();
    if ((m_mousePressX >= 0 && m_mousePressX <= 100)  &&
            ((m_mousePressY >= (height - 100)) && m_mousePressY <= height) &&
            ((m_mouseReleaseX >= (width - 100)) && ((m_mouseReleaseX <= (width)))) &&
            ((m_mouseReleaseY >= (height - 100)) && m_mouseReleaseY <= height)
            )
    {
        m_usbPath.clear();//清空路径字符串 //优盘路径
        m_usbPath = m_pMainWidgetFunction->detectUsb();//优盘检测
        if(m_usbPath.length() <= 0)
        {
            //优盘不存在
            return;
        }
        else
        {
            QPixmap pixmap=QPixmap::grabWindow(this->winId(),0,0,this->width(),this->height());//截屏存放在pixmap
            QString name_pc = m_usbPath +  "EMB" + //
                    QDateTime::currentDateTime().toString("yyyyMMdd") +//获取时期时间
                    +"_"+
                    QDateTime::currentDateTime().toString("hhmmss")    + ".png";

            pixmap.save(name_pc,"png"); // 路径

            if (m_usbPath!= "")
            {
                //截屏效果
                ui->labelScreenshot->show();
                SetControlStyle setControlStyle;
                setControlStyle.setUiName(this->objectName());
                ui->labelScreenshot->setStyleSheet(setControlStyle.getStyleSheet("labelScreenshot"));
                QTimer::singleShot(2000,ui->labelScreenshot,SLOT(hide())); // 停留一秒  隐藏
            }
        }
    }

    m_mousePressX = 0;
    m_mousePressY = 0;
    m_mouseReleaseX = 0;
    m_mouseReleaseY = 0;
}

//刷新界面显示
void MainWidget::refreshPageUi(s16 type)
{
    if(m_itemPerPage <= 0)//界面每页按钮数
    {
        return;
    }

    //-----------
    int itemNum, pageNums;
    itemNum = pageNums = 0;

    if(type == INTERFACE_SHORTCUT)
    {
        itemNum = m_quickItemList.size();//快捷功能列表
    }
    else if(type == INTERFACE_ACCESS)
    {
        itemNum = m_assistItemList.size();//辅助功能列表
    }

    pageNums = (itemNum+m_itemPerPage-1) / m_itemPerPage;//计算总页数

    if (m_curPages > pageNums)                 // 当前页
    {
        m_curPages = pageNums;
    }
    if (m_curPages <= 1)
    {
        m_curPages = 1;
    }

    // 刷新文本和图标
    int i, itemidx;
    itemidx = (m_curPages-1) * m_itemPerPage;
    for (i = 0; i < m_itemPerPage; i++)
    {
        if (itemidx < itemNum)    //itemNum   从绣花参数一共有的按钮功能，可以是28+个
        {
            if(type == INTERFACE_SHORTCUT)
            {
                QString name = m_quickItemList[itemidx].m_name;
                m_quickLabelList[i]->setText(name);
                m_quickLabelList.at(i)->show();//名称

                QString topImageName = m_quickItemList[itemidx].m_topImageName;
                //加载按钮顶图图标
                QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
                m_quickBtnList[i]->setTopImage(btnStyle);
                m_quickBtnList.at(i)->show();
            }
            else if(type == INTERFACE_ACCESS)
            {
                QString name = m_assistItemList[itemidx].m_name;
                m_assistLabelList[i]->setText(name);
                m_assistLabelList.at(i)->show();//名称

                QString topImageName = m_assistItemList[itemidx].m_topImageName;
                //加载按钮顶图图标
                QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
                m_assistBtnList[i]->setTopImage(btnStyle);
                m_assistBtnList.at(i)->show();
            }
        }
        else
        {
            if(type == INTERFACE_SHORTCUT)
            {
                m_quickBtnList.at(i)->hide();//按钮
                m_quickLabelList.at(i)->hide();//名称
            }
            else if(type == INTERFACE_ACCESS)
            {
                m_assistBtnList.at(i)->hide();//按钮
                m_assistLabelList.at(i)->hide();//名称
            }
        }
        itemidx++;
    }

    // 刷新按钮
    if (m_curPages <= 1)
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgUp->setEnabled(false);
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgUp->setEnabled(false);
        }
    }
    else
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgUp->setEnabled(true);//上一页按钮显示
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgUp->setEnabled(true);
        }
    }
    if (m_curPages >= pageNums)//当前页大于等于总页数
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgDn->setEnabled(false);
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgDn->setEnabled(false);
        }
    }
    else
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgDn->setEnabled(true);
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgDn->setEnabled(true);
        }
    }

    if(pageNums == 0)
    {
        m_curPages = 0;
    }

    // 页信息
    QString str = tr("pageNum: ") + QString("%1/%2").arg(m_curPages).arg(pageNums);//页数:
    if(type == INTERFACE_SHORTCUT)
    {
        ui->labelShortCutPage->setText(str);
    }
    else if(type == INTERFACE_ACCESS)
    {
        ui->labelAssistPage->setText(str);
    }
}

//接收到调试信息改变的槽函数
void MainWidget::slotDebugInfo()
{
    DebugInfo info;//调试信息
    char mDebugInfoStr[1024+1];

    info = g_pMachine->getDebugInfo();
    memcpy(mDebugInfoStr, info.debugInfoStr, 1024);

    mDebugInfoStr[1024] = 0;

    QString strDebugInfoStr;
    strDebugInfoStr.sprintf("%s", mDebugInfoStr);
    if(strDebugInfoStr.length()>0)
    {
        g_pSettings->writeToCsv(strDebugInfoStr,TYPE_DEBUGINFO);//写入csv
    }
}

void MainWidget::on_buttonShortCutPgUp_clicked()
{
    m_curPages--;
    refreshPageUi(INTERFACE_SHORTCUT);
}

void MainWidget::on_buttonShortCutPgDn_clicked()
{
    m_curPages++;
    refreshPageUi(INTERFACE_SHORTCUT);
}

void MainWidget::on_buttonAssistPgUp_clicked()
{
    m_curPages--;
    refreshPageUi(INTERFACE_ACCESS);
}

void MainWidget::on_buttonAssistPgDn_clicked()
{
    m_curPages++;
    refreshPageUi(INTERFACE_ACCESS);
}

void MainWidget::on_buttonMove_pressed()
{
#ifdef Q_OS_LINUX
#else
    //qDebug()<<"buttonMove_pressed";
    QPoint msPos;
    int msX,msY;
    int uiX,uiY;

    uiX = g_mainWidgetPos.x();
    uiY = g_mainWidgetPos.y();
    msPos = QCursor::pos();
    msX = msPos.x();
    msY = msPos.y();
    ui->buttonMove->setChecked(true);

    do
    {
        msPos = QCursor::pos();
        g_mainWidgetPos.setX((msPos.x() - msX) + uiX);
        g_mainWidgetPos.setY((msPos.y() - msY) + uiY);

        this->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        if(ui->buttonMove->isChecked() == false)
        {
            break;
        }
        QCoreApplication::processEvents(QEventLoop::AllEvents);

    }while(1);

    switch (g_emResolut)
    {
    case resolution1910:
        m_pPatternSelectWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pParameterSetDlg->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pPatternManageWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pSensorInputWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pControlActionWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pColorOrderSetWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pNeedleBarSetWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pSheetWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pSetWorkAreaWi->move((1920-m_pSetWorkAreaWi->width())/2+g_mainWidgetPos.x(),(1080-m_pSetWorkAreaWi->height())/2+g_mainWidgetPos.y());
        break;
    case resolution1006:
        m_pPatternSelectWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pParameterSetDlg->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pPatternManageWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pSensorInputWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pControlActionWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pColorOrderSetWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pNeedleBarSetWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pSheetWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        m_pSetWorkAreaWi->move((1024-m_pSetWorkAreaWi->width())/2+g_mainWidgetPos.x(),(600-m_pSetWorkAreaWi->height())/2+g_mainWidgetPos.y());
    default:
        break;
    }

    m_pMainWidgetFunction->moveDlgPos();
#endif
}

void MainWidget::on_buttonMove_released()
{
#ifdef Q_OS_LINUX
#else
    ui->buttonMove->setChecked(false);
    //qDebug()<<"on_buttonMove_released";
#endif
}
