更新文档
This commit is contained in:
@@ -10,6 +10,10 @@ DeviceButton::DeviceButton(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
canMove = false;
|
||||
text = "1";
|
||||
|
||||
colorNormal = "black";
|
||||
colorAlarm = "red";
|
||||
|
||||
buttonStyle = ButtonStyle_Police;
|
||||
buttonColor = ButtonColor_Green;
|
||||
|
||||
@@ -17,9 +21,10 @@ DeviceButton::DeviceButton(QWidget *parent) : QWidget(parent)
|
||||
lastPoint = QPoint();
|
||||
|
||||
type = "police";
|
||||
imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type);
|
||||
isDark = false;
|
||||
imgPath = ":/image/devicebutton/devicebutton";
|
||||
imgName = QString("%1_green_%2.png").arg(imgPath).arg(type);
|
||||
|
||||
isDark = false;
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(500);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(checkAlarm()));
|
||||
@@ -119,6 +124,16 @@ QString DeviceButton::getText() const
|
||||
return this->text;
|
||||
}
|
||||
|
||||
QString DeviceButton::getColorNormal() const
|
||||
{
|
||||
return this->colorNormal;
|
||||
}
|
||||
|
||||
QString DeviceButton::getColorAlarm() const
|
||||
{
|
||||
return this->colorAlarm;
|
||||
}
|
||||
|
||||
DeviceButton::ButtonStyle DeviceButton::getButtonStyle() const
|
||||
{
|
||||
return this->buttonStyle;
|
||||
@@ -142,9 +157,9 @@ QSize DeviceButton::minimumSizeHint() const
|
||||
void DeviceButton::checkAlarm()
|
||||
{
|
||||
if (isDark) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_black_%1.png").arg(type);
|
||||
imgName = QString("%1_%2_%3.png").arg(imgPath).arg(colorNormal).arg(type);
|
||||
} else {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_red_%1.png").arg(type);
|
||||
imgName = QString("%1_%2_%3.png").arg(imgPath).arg(colorAlarm).arg(type);
|
||||
}
|
||||
|
||||
isDark = !isDark;
|
||||
@@ -164,6 +179,22 @@ void DeviceButton::setText(const QString &text)
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceButton::setColorNormal(const QString &colorNormal)
|
||||
{
|
||||
if (this->colorNormal != colorNormal) {
|
||||
this->colorNormal = colorNormal;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceButton::setColorAlarm(const QString &colorAlarm)
|
||||
{
|
||||
if (this->colorAlarm != colorAlarm) {
|
||||
this->colorAlarm = colorAlarm;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceButton::setButtonStyle(const DeviceButton::ButtonStyle &buttonStyle)
|
||||
{
|
||||
this->buttonStyle = buttonStyle;
|
||||
@@ -188,25 +219,35 @@ void DeviceButton::setButtonStyle(const DeviceButton::ButtonStyle &buttonStyle)
|
||||
|
||||
void DeviceButton::setButtonColor(const DeviceButton::ButtonColor &buttonColor)
|
||||
{
|
||||
//先停止定时器
|
||||
this->buttonColor = buttonColor;
|
||||
isDark = false;
|
||||
if (timer->isActive()) {
|
||||
timer->stop();
|
||||
}
|
||||
|
||||
QString color;
|
||||
if (buttonColor == ButtonColor_Green) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type);
|
||||
color = "green";
|
||||
} else if (buttonColor == ButtonColor_Blue) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_blue_%1.png").arg(type);
|
||||
color = "blue";
|
||||
} else if (buttonColor == ButtonColor_Gray) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_gray_%1.png").arg(type);
|
||||
color = "gray";
|
||||
} else if (buttonColor == ButtonColor_Black) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_black_%1.png").arg(type);
|
||||
color = "black";
|
||||
} else if (buttonColor == ButtonColor_Purple) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_purple_%1.png").arg(type);
|
||||
color = "purple";
|
||||
} else if (buttonColor == ButtonColor_Yellow) {
|
||||
imgName = QString(":/image/devicebutton/devicebutton_yellow_%1.png").arg(type);
|
||||
color = "yellow";
|
||||
} else if (buttonColor == ButtonColor_Red) {
|
||||
color = "red";
|
||||
} else {
|
||||
color = "green";
|
||||
}
|
||||
|
||||
//如果和报警颜色一致则主动启动定时器切换报警颜色
|
||||
imgName = QString("%1_%2_%3.png").arg(imgPath).arg(color).arg(type);
|
||||
if (color == colorAlarm) {
|
||||
checkAlarm();
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* 设备按钮控件 作者:feiyangqingyun(QQ:517216493) 2018-07-02
|
||||
* 1. 可设置按钮样式 圆形、警察、气泡、气泡2、消息、消息2。
|
||||
* 2. 可设置按钮颜色 布防、撤防、报警、旁路、故障。
|
||||
* 3. 可设置报警切换。
|
||||
* 3. 可设置报警切换及对应报警切换的颜色。
|
||||
* 4. 可设置显示的防区号。
|
||||
* 5. 可设置是否可鼠标拖动。
|
||||
* 6. 发出单击和双击信号。
|
||||
@@ -27,6 +27,9 @@ class DeviceButton : public QWidget
|
||||
Q_PROPERTY(bool canMove READ getCanMove WRITE setCanMove)
|
||||
Q_PROPERTY(QString text READ getText WRITE setText)
|
||||
|
||||
Q_PROPERTY(QString colorNormal READ getColorNormal WRITE setColorNormal)
|
||||
Q_PROPERTY(QString colorAlarm READ getColorAlarm WRITE setColorAlarm)
|
||||
|
||||
Q_PROPERTY(ButtonStyle buttonStyle READ getButtonStyle WRITE setButtonStyle)
|
||||
Q_PROPERTY(ButtonColor buttonColor READ getButtonColor WRITE setButtonColor)
|
||||
|
||||
@@ -62,6 +65,10 @@ protected:
|
||||
private:
|
||||
bool canMove; //是否可移动
|
||||
QString text; //显示文字
|
||||
|
||||
QString colorNormal; //正常颜色
|
||||
QString colorAlarm; //报警颜色
|
||||
|
||||
ButtonStyle buttonStyle; //按钮样式
|
||||
ButtonColor buttonColor; //按钮颜色
|
||||
|
||||
@@ -69,7 +76,9 @@ private:
|
||||
QPoint lastPoint; //鼠标按下最后坐标
|
||||
|
||||
QString type; //图片末尾类型
|
||||
QString imgPath; //背景图片路径
|
||||
QString imgName; //背景图片名称
|
||||
|
||||
bool isDark; //是否加深报警
|
||||
QTimer *timer; //报警闪烁定时器
|
||||
|
||||
@@ -80,6 +89,9 @@ public:
|
||||
bool getCanMove() const;
|
||||
QString getText() const;
|
||||
|
||||
QString getColorNormal() const;
|
||||
QString getColorAlarm() const;
|
||||
|
||||
ButtonStyle getButtonStyle() const;
|
||||
ButtonColor getButtonColor() const;
|
||||
|
||||
@@ -91,6 +103,11 @@ public Q_SLOTS:
|
||||
void setCanMove(bool canMove);
|
||||
//设置显示文字
|
||||
void setText(const QString &text);
|
||||
|
||||
//设置正常颜色和报警颜色
|
||||
void setColorNormal(const QString &colorNormal);
|
||||
void setColorAlarm(const QString &colorAlarm);
|
||||
|
||||
//设置样式
|
||||
void setButtonStyle(const ButtonStyle &buttonStyle);
|
||||
//设置颜色
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<width>900</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user