#ifndef CONTROLACTIONWIDGET_H
#define CONTROLACTIONWIDGET_H

#include <QWidget>
#include "items/outctrlitem.h"
#include "mybutton.h"
#include "setcontrolstyle.h"
#include <QMouseEvent>
#include <QDateTime>
#include "mctype/mainwidgetfunction.h"
#include <QTimer>

#define BORDER_RADIUS "5"

namespace Ui {
class ControlActionWidget;
}

class ControlActionWidget : public QWidget
{
    Q_OBJECT

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

private:
    Ui::ControlActionWidget *ui;

    enum BTNEVENT { BTNCLICK = 1, BTNPRE, BTNREL};

    int m_itemPerPage;//界面每页条目数
    int m_btnPerRow;//每行按钮数
    int m_curPage;//当前页数
    QList<QFrame*> m_itemFrameList;
    QList<QLabel*> m_itemLabelList;
    QList<MyButton*> m_itemBtnList;
    QList <OutCtrlItem> m_allItemList;
    QList <OutCtrlItem> m_itemList;

    QTimer * m_motorTimer;  // 电机停止命令多次发送
    int m_speed;//换挡速度

private:
    void initControl();//初始化窗体控件，包括位置、尺寸、样式
    void initResolution1910();//初始化窗体控件为1920x1080分辨率
    void initResolution1006();//初始化窗体控件为1024x600分辨率
    void initControlStyle();//初始化窗体控件样式
    void initArabControlPos();//设置阿拉伯语时控件对齐方式

    void btnAction(int rowidx, int btnidx, int event);//按钮动作，参数包括行、按钮索引、按钮事件
    void excuteOrder(int def,int fun);//执行按钮动作

public:
    void setTypeLogo(QString tStyle);//设置类型图标
    void setMainTitle(QString str);//设置主title
    void setSubTitle(QString str);//设置副title

    void refreshUi(int idx = 0);

public:
    void addItemList(QList<OutCtrlItem> itemList);

private slots:
    void slotItemBtnClicked();//控制按钮被点击
    void slotItemBtnPressed();//控制按钮按下
    void slotItemBtnReleased();//控制按钮抬起
    void on_buttonPgUp_clicked();
    void on_buttonPgDn_clicked();
    void on_buttonBack_clicked();

public slots:
    void slotSpeed(int speed);
 //鼠标事件
protected:
    void mousePressEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);

private:
    int m_mousePressX;
    int m_mousePressY;
    int m_mouseReleaseX;
    int m_mouseReleaseY;

signals:
    void siTowelMZero(s16 code,s16 type);//毛巾M轴
    void siTowelRZero(s16 code,s16 type);//毛巾打环轴
    void siCoilCFZero(s16 code,s16 type);//缠绕压脚电机
    void siCoilCZZero(s16 code,s16 type);//缠绕锯齿电机

};

#endif // CONTROLACTIONWIDGET_H
