qt_demoe/control/devicebutton/devicebutton.h

124 lines
3.6 KiB
C
Raw Normal View History

2021-05-17 06:43:33 +00:00
#ifndef DEVICEBUTTON_H
#define DEVICEBUTTON_H
/**
2021-09-26 01:50:09 +00:00
* :feiyangqingyun(QQ:517216493) 2018-07-02
2021-09-13 08:12:35 +00:00
* 1. 22
* 2.
2022-05-06 08:37:44 +00:00
* 3.
2021-09-13 08:12:35 +00:00
* 4.
* 5.
* 6.
2021-05-17 06:43:33 +00:00
*/
#include <QWidget>
#ifdef quc
class Q_DECL_EXPORT DeviceButton : public QWidget
#else
class DeviceButton : public QWidget
#endif
{
Q_OBJECT
Q_ENUMS(ButtonStyle)
Q_ENUMS(ButtonColor)
Q_PROPERTY(bool canMove READ getCanMove WRITE setCanMove)
Q_PROPERTY(QString text READ getText WRITE setText)
2022-05-06 08:37:44 +00:00
Q_PROPERTY(QString colorNormal READ getColorNormal WRITE setColorNormal)
Q_PROPERTY(QString colorAlarm READ getColorAlarm WRITE setColorAlarm)
2021-05-17 06:43:33 +00:00
Q_PROPERTY(ButtonStyle buttonStyle READ getButtonStyle WRITE setButtonStyle)
Q_PROPERTY(ButtonColor buttonColor READ getButtonColor WRITE setButtonColor)
public:
//设备按钮样式
enum ButtonStyle {
ButtonStyle_Circle = 0, //圆形
ButtonStyle_Police = 1, //警察
ButtonStyle_Bubble = 2, //气泡
ButtonStyle_Bubble2 = 3, //气泡2
ButtonStyle_Msg = 4, //消息
ButtonStyle_Msg2 = 5 //消息2
};
//设备按钮颜色
enum ButtonColor {
2023-09-08 05:51:39 +00:00
ButtonColor_Green = 0, //绿色(激活状态)
ButtonColor_Blue = 1, //蓝色(在线状态)
ButtonColor_Red = 2, //红色(报警状态)
ButtonColor_Gray = 3, //灰色(离线状态)
ButtonColor_Black = 4, //黑色(故障状态)
ButtonColor_Purple = 5, //紫色(其他状态)
ButtonColor_Yellow = 6 //黄色(其他状态)
2021-05-17 06:43:33 +00:00
};
explicit DeviceButton(QWidget *parent = 0);
~DeviceButton();
protected:
void paintEvent(QPaintEvent *);
bool eventFilter(QObject *watched, QEvent *event);
private:
2023-09-08 05:51:39 +00:00
bool canMove; //是否可移动
QString text; //显示文字
2022-05-06 08:37:44 +00:00
2023-09-08 05:51:39 +00:00
QString colorNormal; //正常颜色
QString colorAlarm; //报警颜色
2022-05-06 08:37:44 +00:00
2023-09-08 05:51:39 +00:00
ButtonStyle buttonStyle;//按钮样式
ButtonColor buttonColor;//按钮颜色
2021-05-17 06:43:33 +00:00
2023-09-08 05:51:39 +00:00
bool isPressed; //鼠标是否按下
QPoint lastPoint; //鼠标按下最后坐标
2022-04-30 10:17:02 +00:00
2023-09-08 05:51:39 +00:00
QString type; //图片末尾类型
QString imgPath; //背景图片路径
QString imgName; //背景图片名称
2022-05-06 08:37:44 +00:00
2023-09-08 05:51:39 +00:00
bool isDark; //是否加深报警
QTimer *timer; //报警闪烁定时器
2021-05-17 06:43:33 +00:00
private slots:
2023-09-08 05:51:39 +00:00
void checkAlarm(); //切换报警状态
2021-05-17 06:43:33 +00:00
public:
2023-09-08 05:51:39 +00:00
//默认尺寸和最小尺寸
QSize sizeHint() const;
QSize minimumSizeHint() const;
2021-05-17 06:43:33 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置可移动
bool getCanMove() const;
2021-05-17 06:43:33 +00:00
void setCanMove(bool canMove);
2023-09-08 05:51:39 +00:00
//获取和设置显示文字
QString getText() const;
2021-05-17 06:43:33 +00:00
void setText(const QString &text);
2022-05-06 08:37:44 +00:00
2023-09-08 05:51:39 +00:00
//获取和设置正常颜色
QString getColorNormal() const;
2022-05-06 08:37:44 +00:00
void setColorNormal(const QString &colorNormal);
2023-09-08 05:51:39 +00:00
//获取和设置报警颜色
QString getColorAlarm() const;
2022-05-06 08:37:44 +00:00
void setColorAlarm(const QString &colorAlarm);
2023-09-08 05:51:39 +00:00
//获取和设置样式
ButtonStyle getButtonStyle() const;
2021-05-17 06:43:33 +00:00
void setButtonStyle(const ButtonStyle &buttonStyle);
2023-09-08 05:51:39 +00:00
//获取和设置颜色
ButtonColor getButtonColor() const;
2021-05-17 06:43:33 +00:00
void setButtonColor(const ButtonColor &buttonColor);
Q_SIGNALS:
2022-04-30 10:17:02 +00:00
//鼠标单击双击事件
2021-05-17 06:43:33 +00:00
void clicked();
void doubleClicked();
};
#endif //DEVICEBUTTON_H