From 020b6fb0e7435c9fb89568891ea2df2b006ef778 Mon Sep 17 00:00:00 2001 From: feiyangqingyun Date: Mon, 17 May 2021 14:46:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0snap/{buttondefence.gif => devicebutton.gif} | Bin README.md | 4 +- buttondefence/buttondefence.h | 99 ------------------ buttondefence/frmbuttondefence.cpp | 71 ------------- buttondefence/frmbuttondefence.h | 36 ------- buttondefence/main.qrc | 35 ------- .../devicebutton.cpp | 64 +++++------ devicebutton/devicebutton.h | 99 ++++++++++++++++++ .../devicebutton.pro | 12 +-- devicebutton/frmdevicebutton.cpp | 71 +++++++++++++ devicebutton/frmdevicebutton.h | 36 +++++++ .../frmdevicebutton.ui | 24 ++--- .../image/bg_call.jpg | Bin .../devicebutton_black_bubble.png | Bin .../devicebutton_black_bubble2.png | Bin .../devicebutton_black_circle.png | Bin .../devicebutton/devicebutton_black_msg.png | Bin .../devicebutton/devicebutton_black_msg2.png | Bin .../devicebutton_black_police.png | Bin .../devicebutton/devicebutton_blue_bubble.png | Bin .../devicebutton_blue_bubble2.png | Bin .../devicebutton/devicebutton_blue_circle.png | Bin .../devicebutton/devicebutton_blue_msg.png | Bin .../devicebutton/devicebutton_blue_msg2.png | Bin .../devicebutton/devicebutton_blue_police.png | Bin .../devicebutton/devicebutton_gray_bubble.png | Bin .../devicebutton_gray_bubble2.png | Bin .../devicebutton/devicebutton_gray_circle.png | Bin .../devicebutton/devicebutton_gray_msg.png | Bin .../devicebutton/devicebutton_gray_msg2.png | Bin .../devicebutton/devicebutton_gray_police.png | Bin .../devicebutton_green_bubble.png | Bin .../devicebutton_green_bubble2.png | Bin .../devicebutton_green_circle.png | Bin .../devicebutton/devicebutton_green_msg.png | Bin .../devicebutton/devicebutton_green_msg2.png | Bin .../devicebutton_green_police.png | Bin .../devicebutton/devicebutton_red_bubble.png | Bin .../devicebutton/devicebutton_red_bubble2.png | Bin .../devicebutton/devicebutton_red_circle.png | Bin .../devicebutton/devicebutton_red_msg.png | Bin .../devicebutton/devicebutton_red_msg2.png | Bin .../devicebutton/devicebutton_red_police.png | Bin {buttondefence => devicebutton}/main.cpp | 6 +- devicebutton/main.qrc | 35 +++++++ 45 files changed, 296 insertions(+), 296 deletions(-) rename 0snap/{buttondefence.gif => devicebutton.gif} (100%) delete mode 100644 buttondefence/buttondefence.h delete mode 100644 buttondefence/frmbuttondefence.cpp delete mode 100644 buttondefence/frmbuttondefence.h delete mode 100644 buttondefence/main.qrc rename buttondefence/buttondefence.cpp => devicebutton/devicebutton.cpp (68%) create mode 100644 devicebutton/devicebutton.h rename buttondefence/buttondefence.pro => devicebutton/devicebutton.pro (63%) create mode 100644 devicebutton/frmdevicebutton.cpp create mode 100644 devicebutton/frmdevicebutton.h rename buttondefence/frmbuttondefence.ui => devicebutton/frmdevicebutton.ui (87%) rename {buttondefence => devicebutton}/image/bg_call.jpg (100%) rename buttondefence/image/buttondefence/btn_defence_error_bubble.png => devicebutton/image/devicebutton/devicebutton_black_bubble.png (100%) rename buttondefence/image/buttondefence/btn_defence_error_bubble2.png => devicebutton/image/devicebutton/devicebutton_black_bubble2.png (100%) rename buttondefence/image/buttondefence/btn_defence_error_circle.png => devicebutton/image/devicebutton/devicebutton_black_circle.png (100%) rename buttondefence/image/buttondefence/btn_defence_error_msg.png => devicebutton/image/devicebutton/devicebutton_black_msg.png (100%) rename buttondefence/image/buttondefence/btn_defence_error_msg2.png => devicebutton/image/devicebutton/devicebutton_black_msg2.png (100%) rename buttondefence/image/buttondefence/btn_defence_error_police.png => devicebutton/image/devicebutton/devicebutton_black_police.png (100%) rename buttondefence/image/buttondefence/btn_defence_disarming_bubble.png => devicebutton/image/devicebutton/devicebutton_blue_bubble.png (100%) rename buttondefence/image/buttondefence/btn_defence_disarming_bubble2.png => devicebutton/image/devicebutton/devicebutton_blue_bubble2.png (100%) rename buttondefence/image/buttondefence/btn_defence_disarming_circle.png => devicebutton/image/devicebutton/devicebutton_blue_circle.png (100%) rename buttondefence/image/buttondefence/btn_defence_disarming_msg.png => devicebutton/image/devicebutton/devicebutton_blue_msg.png (100%) rename buttondefence/image/buttondefence/btn_defence_disarming_msg2.png => devicebutton/image/devicebutton/devicebutton_blue_msg2.png (100%) rename buttondefence/image/buttondefence/btn_defence_disarming_police.png => devicebutton/image/devicebutton/devicebutton_blue_police.png (100%) rename buttondefence/image/buttondefence/btn_defence_bypass_bubble.png => devicebutton/image/devicebutton/devicebutton_gray_bubble.png (100%) rename buttondefence/image/buttondefence/btn_defence_bypass_bubble2.png => devicebutton/image/devicebutton/devicebutton_gray_bubble2.png (100%) rename buttondefence/image/buttondefence/btn_defence_bypass_circle.png => devicebutton/image/devicebutton/devicebutton_gray_circle.png (100%) rename buttondefence/image/buttondefence/btn_defence_bypass_msg.png => devicebutton/image/devicebutton/devicebutton_gray_msg.png (100%) rename buttondefence/image/buttondefence/btn_defence_bypass_msg2.png => devicebutton/image/devicebutton/devicebutton_gray_msg2.png (100%) rename buttondefence/image/buttondefence/btn_defence_bypass_police.png => devicebutton/image/devicebutton/devicebutton_gray_police.png (100%) rename buttondefence/image/buttondefence/btn_defence_arming_bubble.png => devicebutton/image/devicebutton/devicebutton_green_bubble.png (100%) rename buttondefence/image/buttondefence/btn_defence_arming_bubble2.png => devicebutton/image/devicebutton/devicebutton_green_bubble2.png (100%) rename buttondefence/image/buttondefence/btn_defence_arming_circle.png => devicebutton/image/devicebutton/devicebutton_green_circle.png (100%) rename buttondefence/image/buttondefence/btn_defence_arming_msg.png => devicebutton/image/devicebutton/devicebutton_green_msg.png (100%) rename buttondefence/image/buttondefence/btn_defence_arming_msg2.png => devicebutton/image/devicebutton/devicebutton_green_msg2.png (100%) rename buttondefence/image/buttondefence/btn_defence_arming_police.png => devicebutton/image/devicebutton/devicebutton_green_police.png (100%) rename buttondefence/image/buttondefence/btn_defence_alarm_bubble.png => devicebutton/image/devicebutton/devicebutton_red_bubble.png (100%) rename buttondefence/image/buttondefence/btn_defence_alarm_bubble2.png => devicebutton/image/devicebutton/devicebutton_red_bubble2.png (100%) rename buttondefence/image/buttondefence/btn_defence_alarm_circle.png => devicebutton/image/devicebutton/devicebutton_red_circle.png (100%) rename buttondefence/image/buttondefence/btn_defence_alarm_msg.png => devicebutton/image/devicebutton/devicebutton_red_msg.png (100%) rename buttondefence/image/buttondefence/btn_defence_alarm_msg2.png => devicebutton/image/devicebutton/devicebutton_red_msg2.png (100%) rename buttondefence/image/buttondefence/btn_defence_alarm_police.png => devicebutton/image/devicebutton/devicebutton_red_police.png (100%) rename {buttondefence => devicebutton}/main.cpp (87%) create mode 100644 devicebutton/main.qrc diff --git a/0snap/buttondefence.gif b/0snap/devicebutton.gif similarity index 100% rename from 0snap/buttondefence.gif rename to 0snap/devicebutton.gif diff --git a/README.md b/README.md index 92cdbaa..525c08f 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ | 22 | lineeditnext | 文本框回车焦点下移 | | 23 | zhtopy | 汉字转拼音 | | 24 | qwtdemo | qwt的源码版本,无需插件,直接源码集成到你的项目即可 | -| 25 | buttondefence | 通用按钮地图效果 | +| 25 | devicebutton | 设备按钮地图效果 | | 26 | mouseline | 鼠标定位十字线 | | 27 | emailtool | 邮件发送工具 | | 28 | ntpclient | NTP服务器时间同步 | @@ -81,7 +81,7 @@ ![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/lineeditnext.gif) ![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/zhtopy.gif) ![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/qwtdemo.jpg) -![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/buttondefence.gif) +![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/devicebutton.gif) ![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/mouseline.gif) ![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/emailtool.gif) ![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/ntpclient.gif) diff --git a/buttondefence/buttondefence.h b/buttondefence/buttondefence.h deleted file mode 100644 index 8c300bc..0000000 --- a/buttondefence/buttondefence.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef BUTTONDEFENCE_H -#define BUTTONDEFENCE_H - -/** - * 防区按钮控件 作者:feiyangqingyun(QQ:517216493) 2018-7-2 - * 1. 可设置防区样式 圆形、警察、气泡、气泡2、消息、消息2 - * 2. 可设置防区状态 布防、撤防、报警、旁路、故障 - * 3. 可设置报警切换 - * 4. 可设置显示的防区号 - * 5. 可设置是否可鼠标拖动 - * 6. 发出单击和双击信号 - */ - -#include - -#ifdef quc -class Q_DECL_EXPORT ButtonDefence : public QWidget -#else -class ButtonDefence : public QWidget -#endif - -{ - Q_OBJECT - Q_ENUMS(ButtonStyle) - Q_ENUMS(ButtonStatus) - - Q_PROPERTY(bool canMove READ getCanMove WRITE setCanMove) - Q_PROPERTY(QString text READ getText WRITE setText) - - Q_PROPERTY(ButtonStyle buttonStyle READ getButtonStyle WRITE setButtonStyle) - Q_PROPERTY(ButtonStatus buttonStatus READ getButtonStatus WRITE setButtonStatus) - -public: - //防区样式 圆形、警察、气泡、气泡2、消息、消息2 - enum ButtonStyle { - ButtonStyle_Circle = 0, - ButtonStyle_Police = 1, - ButtonStyle_Bubble = 2, - ButtonStyle_Bubble2 = 3, - ButtonStyle_Msg = 4, - ButtonStyle_Msg2 = 5 - }; - - //防区状态 布防、撤防、报警、旁路、故障 - enum ButtonStatus { - ButtonStatus_Arming = 0, - ButtonStatus_Disarming = 1, - ButtonStatus_Alarm = 2, - ButtonStatus_Bypass = 3, - ButtonStatus_Error = 4 - }; - - explicit ButtonDefence(QWidget *parent = 0); - ~ButtonDefence(); - -protected: - void paintEvent(QPaintEvent *); - bool eventFilter(QObject *watched, QEvent *event); - -private: - bool canMove; //是否可移动 - QString text; //显示文字 - ButtonStyle buttonStyle; //防区样式 - ButtonStatus buttonStatus; //防区状态 - - QString type; //图片末尾类型 - QString imgName; //背景图片名称 - bool isDark; //是否加深报警 - QTimer *timer; //报警闪烁定时器 - -private slots: - void checkAlarm(); - -public: - bool getCanMove() const; - QString getText() const; - - ButtonStyle getButtonStyle() const; - ButtonStatus getButtonStatus() const; - - QSize sizeHint() const; - QSize minimumSizeHint() const; - -public Q_SLOTS: - //设置可移动 - void setCanMove(bool canMove); - //设置显示文字 - void setText(const QString &text); - //设置防区样式 - void setButtonStyle(const ButtonStyle &buttonStyle); - //设置防区状态 - void setButtonStatus(const ButtonStatus &buttonStatus); - -Q_SIGNALS: - void clicked(); - void doubleClicked(); -}; - -#endif //BUTTONDEFENCE_H diff --git a/buttondefence/frmbuttondefence.cpp b/buttondefence/frmbuttondefence.cpp deleted file mode 100644 index 03cce01..0000000 --- a/buttondefence/frmbuttondefence.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "frmbuttondefence.h" -#include "ui_frmbuttondefence.h" -#include "buttondefence.h" -#include "qdebug.h" - -frmButtonDefence::frmButtonDefence(QWidget *parent) : QWidget(parent), ui(new Ui::frmButtonDefence) -{ - ui->setupUi(this); - this->initForm(); -} - -frmButtonDefence::~frmButtonDefence() -{ - delete ui; -} - -void frmButtonDefence::initForm() -{ - //设置背景地图 - ui->labMap->setStyleSheet("border-image:url(:/image/bg_call.jpg);"); - - btn1 = new ButtonDefence(ui->labMap); - btn1->setText("#1"); - btn1->setGeometry(5, 5, 35, 35); - - btn2 = new ButtonDefence(ui->labMap); - btn2->setText("#2"); - btn2->setGeometry(45, 5, 35, 35); - - btn3 = new ButtonDefence(ui->labMap); - btn3->setText("#3"); - btn3->setGeometry(85, 5, 35, 35); - - btnStyle << ui->btnCircle << ui->btnPolice << ui->btnBubble << ui->btnBubble2 << ui->btnMsg << ui->btnMsg2; - foreach (QPushButton *btn, btnStyle) { - connect(btn, SIGNAL(clicked(bool)), this, SLOT(changeStyle())); - } - - btnStatus << ui->btnArming << ui->btnDisarming << ui->btnAlarm << ui->btnBypass << ui->btnError; - foreach (QPushButton *btn, btnStatus) { - connect(btn, SIGNAL(clicked(bool)), this, SLOT(changeStatus())); - } -} - -void frmButtonDefence::changeStyle() -{ - QPushButton *btn = (QPushButton *)sender(); - int index = btnStyle.indexOf(btn); - ButtonDefence::ButtonStyle style = (ButtonDefence::ButtonStyle)index; - btn1->setButtonStyle(style); - btn2->setButtonStyle(style); - btn3->setButtonStyle(style); -} - -void frmButtonDefence::changeStatus() -{ - QPushButton *btn = (QPushButton *)sender(); - int index = btnStatus.indexOf(btn); - ButtonDefence::ButtonStatus style = (ButtonDefence::ButtonStatus)index; - btn1->setButtonStatus(style); - btn2->setButtonStatus(style); - btn3->setButtonStatus(style); -} - -void frmButtonDefence::on_ckCanMove_stateChanged(int arg1) -{ - bool canMove = (arg1 != 0); - btn1->setCanMove(canMove); - btn2->setCanMove(canMove); - btn3->setCanMove(canMove); -} diff --git a/buttondefence/frmbuttondefence.h b/buttondefence/frmbuttondefence.h deleted file mode 100644 index e815330..0000000 --- a/buttondefence/frmbuttondefence.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FRMBUTTONDEFENCE_H -#define FRMBUTTONDEFENCE_H - -#include - -class ButtonDefence; -class QPushButton; - -namespace Ui { -class frmButtonDefence; -} - -class frmButtonDefence : public QWidget -{ - Q_OBJECT - -public: - explicit frmButtonDefence(QWidget *parent = 0); - ~frmButtonDefence(); - -private slots: - void initForm(); - void changeStyle(); - void changeStatus(); - void on_ckCanMove_stateChanged(int arg1); - -private: - Ui::frmButtonDefence *ui; - ButtonDefence *btn1; - ButtonDefence *btn2; - ButtonDefence *btn3; - QList btnStyle; - QList btnStatus; -}; - -#endif // FRMBUTTONDEFENCE_H diff --git a/buttondefence/main.qrc b/buttondefence/main.qrc deleted file mode 100644 index c0e3c1f..0000000 --- a/buttondefence/main.qrc +++ /dev/null @@ -1,35 +0,0 @@ - - - image/bg_call.jpg - image/buttondefence/btn_defence_alarm_bubble.png - image/buttondefence/btn_defence_alarm_bubble2.png - image/buttondefence/btn_defence_alarm_circle.png - image/buttondefence/btn_defence_alarm_msg.png - image/buttondefence/btn_defence_alarm_msg2.png - image/buttondefence/btn_defence_alarm_police.png - image/buttondefence/btn_defence_arming_bubble.png - image/buttondefence/btn_defence_arming_bubble2.png - image/buttondefence/btn_defence_arming_circle.png - image/buttondefence/btn_defence_arming_msg.png - image/buttondefence/btn_defence_arming_msg2.png - image/buttondefence/btn_defence_arming_police.png - image/buttondefence/btn_defence_bypass_bubble.png - image/buttondefence/btn_defence_bypass_bubble2.png - image/buttondefence/btn_defence_bypass_circle.png - image/buttondefence/btn_defence_bypass_msg.png - image/buttondefence/btn_defence_bypass_msg2.png - image/buttondefence/btn_defence_bypass_police.png - image/buttondefence/btn_defence_disarming_bubble.png - image/buttondefence/btn_defence_disarming_bubble2.png - image/buttondefence/btn_defence_disarming_circle.png - image/buttondefence/btn_defence_disarming_msg.png - image/buttondefence/btn_defence_disarming_msg2.png - image/buttondefence/btn_defence_disarming_police.png - image/buttondefence/btn_defence_error_bubble.png - image/buttondefence/btn_defence_error_bubble2.png - image/buttondefence/btn_defence_error_circle.png - image/buttondefence/btn_defence_error_msg.png - image/buttondefence/btn_defence_error_msg2.png - image/buttondefence/btn_defence_error_police.png - - diff --git a/buttondefence/buttondefence.cpp b/devicebutton/devicebutton.cpp similarity index 68% rename from buttondefence/buttondefence.cpp rename to devicebutton/devicebutton.cpp index c869f7d..5c250bb 100644 --- a/buttondefence/buttondefence.cpp +++ b/devicebutton/devicebutton.cpp @@ -1,20 +1,20 @@ #pragma execution_character_set("utf-8") -#include "buttondefence.h" +#include "devicebutton.h" #include "qpainter.h" #include "qevent.h" #include "qtimer.h" #include "qdebug.h" -ButtonDefence::ButtonDefence(QWidget *parent) : QWidget(parent) +DeviceButton::DeviceButton(QWidget *parent) : QWidget(parent) { canMove = false; text = "1"; buttonStyle = ButtonStyle_Police; - buttonStatus = ButtonStatus_Arming; + buttonColor = ButtonColor_Green; type = "police"; - imgName = QString(":/image/buttondefence/btn_defence_disarming_%1.png").arg(type); + imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type); isDark = false; timer = new QTimer(this); @@ -24,14 +24,14 @@ ButtonDefence::ButtonDefence(QWidget *parent) : QWidget(parent) this->installEventFilter(this); } -ButtonDefence::~ButtonDefence() +DeviceButton::~DeviceButton() { if (timer->isActive()) { timer->stop(); } } -void ButtonDefence::paintEvent(QPaintEvent *) +void DeviceButton::paintEvent(QPaintEvent *) { double width = this->width(); double height = this->height(); @@ -77,7 +77,7 @@ void ButtonDefence::paintEvent(QPaintEvent *) painter.drawText(rect, Qt::AlignCenter, text); } -bool ButtonDefence::eventFilter(QObject *watched, QEvent *event) +bool DeviceButton::eventFilter(QObject *watched, QEvent *event) { if (canMove) { static QPoint lastPoint; @@ -109,54 +109,54 @@ bool ButtonDefence::eventFilter(QObject *watched, QEvent *event) return QWidget::eventFilter(watched, event); } -bool ButtonDefence::getCanMove() const +bool DeviceButton::getCanMove() const { return this->canMove; } -QString ButtonDefence::getText() const +QString DeviceButton::getText() const { return this->text; } -ButtonDefence::ButtonStyle ButtonDefence::getButtonStyle() const +DeviceButton::ButtonStyle DeviceButton::getButtonStyle() const { return this->buttonStyle; } -ButtonDefence::ButtonStatus ButtonDefence::getButtonStatus() const +DeviceButton::ButtonColor DeviceButton::getButtonColor() const { - return this->buttonStatus; + return this->buttonColor; } -QSize ButtonDefence::sizeHint() const +QSize DeviceButton::sizeHint() const { return QSize(50, 50); } -QSize ButtonDefence::minimumSizeHint() const +QSize DeviceButton::minimumSizeHint() const { return QSize(10, 10); } -void ButtonDefence::checkAlarm() +void DeviceButton::checkAlarm() { if (isDark) { - imgName = QString(":/image/buttondefence/btn_defence_error_%1.png").arg(type); + imgName = QString(":/image/devicebutton/devicebutton_black_%1.png").arg(type); } else { - imgName = QString(":/image/buttondefence/btn_defence_alarm_%1.png").arg(type); + imgName = QString(":/image/devicebutton/devicebutton_red_%1.png").arg(type); } isDark = !isDark; this->update(); } -void ButtonDefence::setCanMove(bool canMove) +void DeviceButton::setCanMove(bool canMove) { this->canMove = canMove; } -void ButtonDefence::setText(const QString &text) +void DeviceButton::setText(const QString &text) { if (this->text != text) { this->text = text; @@ -164,7 +164,7 @@ void ButtonDefence::setText(const QString &text) } } -void ButtonDefence::setButtonStyle(const ButtonDefence::ButtonStyle &buttonStyle) +void DeviceButton::setButtonStyle(const DeviceButton::ButtonStyle &buttonStyle) { this->buttonStyle = buttonStyle; if (buttonStyle == ButtonStyle_Circle) { @@ -183,26 +183,26 @@ void ButtonDefence::setButtonStyle(const ButtonDefence::ButtonStyle &buttonStyle type = "circle"; } - setButtonStatus(buttonStatus); + setButtonColor(buttonColor); } -void ButtonDefence::setButtonStatus(const ButtonDefence::ButtonStatus &buttonStatus) +void DeviceButton::setButtonColor(const DeviceButton::ButtonColor &buttonColor) { - this->buttonStatus = buttonStatus; + this->buttonColor = buttonColor; isDark = false; if (timer->isActive()) { timer->stop(); } - if (buttonStatus == ButtonStatus_Arming) { - imgName = QString(":/image/buttondefence/btn_defence_arming_%1.png").arg(type); - } else if (buttonStatus == ButtonStatus_Disarming) { - imgName = QString(":/image/buttondefence/btn_defence_disarming_%1.png").arg(type); - } else if (buttonStatus == ButtonStatus_Bypass) { - imgName = QString(":/image/buttondefence/btn_defence_bypass_%1.png").arg(type); - } else if (buttonStatus == ButtonStatus_Error) { - imgName = QString(":/image/buttondefence/btn_defence_error_%1.png").arg(type); - } else if (buttonStatus == ButtonStatus_Alarm) { + if (buttonColor == ButtonColor_Green) { + imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type); + } else if (buttonColor == ButtonColor_Blue) { + imgName = QString(":/image/devicebutton/devicebutton_blue_%1.png").arg(type); + } else if (buttonColor == ButtonColor_Gray) { + imgName = QString(":/image/devicebutton/devicebutton_gray_%1.png").arg(type); + } else if (buttonColor == ButtonColor_Black) { + imgName = QString(":/image/devicebutton/devicebutton_black_%1.png").arg(type); + } else if (buttonColor == ButtonColor_Red) { checkAlarm(); if (!timer->isActive()) { timer->start(); diff --git a/devicebutton/devicebutton.h b/devicebutton/devicebutton.h new file mode 100644 index 0000000..bc7c104 --- /dev/null +++ b/devicebutton/devicebutton.h @@ -0,0 +1,99 @@ +#ifndef DEVICEBUTTON_H +#define DEVICEBUTTON_H + +/** + * 设备按钮控件 作者:feiyangqingyun(QQ:517216493) 2018-7-2 + * 1. 可设置按钮样式 圆形、警察、气泡、气泡2、消息、消息2 + * 2. 可设置按钮颜色 布防、撤防、报警、旁路、故障 + * 3. 可设置报警切换 + * 4. 可设置显示的防区号 + * 5. 可设置是否可鼠标拖动 + * 6. 发出单击和双击信号 + */ + +#include + +#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) + + 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 { + ButtonColor_Green = 0, //绿色 设备激活状态 + ButtonColor_Blue = 1, //蓝色 设备在线状态 + ButtonColor_Red = 2, //红色 设备报警状态 + ButtonColor_Gray = 3, //灰色 设备离线状态 + ButtonColor_Black = 4 //黑色 设备故障状态 + }; + + explicit DeviceButton(QWidget *parent = 0); + ~DeviceButton(); + +protected: + void paintEvent(QPaintEvent *); + bool eventFilter(QObject *watched, QEvent *event); + +private: + bool canMove; //是否可移动 + QString text; //显示文字 + ButtonStyle buttonStyle; //按钮样式 + ButtonColor buttonColor; //按钮颜色 + + QString type; //图片末尾类型 + QString imgName; //背景图片名称 + bool isDark; //是否加深报警 + QTimer *timer; //报警闪烁定时器 + +private slots: + void checkAlarm(); //切换报警状态 + +public: + bool getCanMove() const; + QString getText() const; + + ButtonStyle getButtonStyle() const; + ButtonColor getButtonColor() const; + + QSize sizeHint() const; + QSize minimumSizeHint() const; + +public Q_SLOTS: + //设置可移动 + void setCanMove(bool canMove); + //设置显示文字 + void setText(const QString &text); + //设置样式 + void setButtonStyle(const ButtonStyle &buttonStyle); + //设置颜色 + void setButtonColor(const ButtonColor &buttonColor); + +Q_SIGNALS: + void clicked(); + void doubleClicked(); +}; + +#endif //DEVICEBUTTON_H diff --git a/buttondefence/buttondefence.pro b/devicebutton/devicebutton.pro similarity index 63% rename from buttondefence/buttondefence.pro rename to devicebutton/devicebutton.pro index c0699cc..cbd4038 100644 --- a/buttondefence/buttondefence.pro +++ b/devicebutton/devicebutton.pro @@ -8,18 +8,18 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = buttondefence +TARGET = devicebutton TEMPLATE = app DESTDIR = $$PWD/../bin CONFIG += warn_off SOURCES += main.cpp -SOURCES += frmbuttondefence.cpp -SOURCES += buttondefence.cpp +SOURCES += frmdevicebutton.cpp +SOURCES += devicebutton.cpp -HEADERS += frmbuttondefence.h -HEADERS += buttondefence.h +HEADERS += frmdevicebutton.h +HEADERS += devicebutton.h -FORMS += frmbuttondefence.ui +FORMS += frmdevicebutton.ui RESOURCES += main.qrc diff --git a/devicebutton/frmdevicebutton.cpp b/devicebutton/frmdevicebutton.cpp new file mode 100644 index 0000000..7d8da86 --- /dev/null +++ b/devicebutton/frmdevicebutton.cpp @@ -0,0 +1,71 @@ +#include "frmdevicebutton.h" +#include "ui_frmdevicebutton.h" +#include "devicebutton.h" +#include "qdebug.h" + +frmDeviceButton::frmDeviceButton(QWidget *parent) : QWidget(parent), ui(new Ui::frmDeviceButton) +{ + ui->setupUi(this); + this->initForm(); +} + +frmDeviceButton::~frmDeviceButton() +{ + delete ui; +} + +void frmDeviceButton::initForm() +{ + //设置背景地图 + ui->labMap->setStyleSheet("border-image:url(:/image/bg_call.jpg);"); + + btn1 = new DeviceButton(ui->labMap); + btn1->setText("#1"); + btn1->setGeometry(5, 5, 35, 35); + + btn2 = new DeviceButton(ui->labMap); + btn2->setText("#2"); + btn2->setGeometry(45, 5, 35, 35); + + btn3 = new DeviceButton(ui->labMap); + btn3->setText("#3"); + btn3->setGeometry(85, 5, 35, 35); + + btnStyle << ui->btnCircle << ui->btnPolice << ui->btnBubble << ui->btnBubble2 << ui->btnMsg << ui->btnMsg2; + foreach (QPushButton *btn, btnStyle) { + connect(btn, SIGNAL(clicked(bool)), this, SLOT(changeStyle())); + } + + btnColor << ui->btnGreen << ui->btnBlue << ui->btnRed << ui->btnGray << ui->btnBlack; + foreach (QPushButton *btn, btnColor) { + connect(btn, SIGNAL(clicked(bool)), this, SLOT(changeColor())); + } +} + +void frmDeviceButton::changeStyle() +{ + QPushButton *btn = (QPushButton *)sender(); + int index = btnStyle.indexOf(btn); + DeviceButton::ButtonStyle style = (DeviceButton::ButtonStyle)index; + btn1->setButtonStyle(style); + btn2->setButtonStyle(style); + btn3->setButtonStyle(style); +} + +void frmDeviceButton::changeColor() +{ + QPushButton *btn = (QPushButton *)sender(); + int index = btnColor.indexOf(btn); + DeviceButton::ButtonColor style = (DeviceButton::ButtonColor)index; + btn1->setButtonColor(style); + btn2->setButtonColor(style); + btn3->setButtonColor(style); +} + +void frmDeviceButton::on_ckCanMove_stateChanged(int arg1) +{ + bool canMove = (arg1 != 0); + btn1->setCanMove(canMove); + btn2->setCanMove(canMove); + btn3->setCanMove(canMove); +} diff --git a/devicebutton/frmdevicebutton.h b/devicebutton/frmdevicebutton.h new file mode 100644 index 0000000..b8b45ca --- /dev/null +++ b/devicebutton/frmdevicebutton.h @@ -0,0 +1,36 @@ +#ifndef FRMDEVICEBUTTON_H +#define FRMDEVICEBUTTON_H + +#include + +class DeviceButton; +class QPushButton; + +namespace Ui { +class frmDeviceButton; +} + +class frmDeviceButton : public QWidget +{ + Q_OBJECT + +public: + explicit frmDeviceButton(QWidget *parent = 0); + ~frmDeviceButton(); + +private slots: + void initForm(); + void changeStyle(); + void changeColor(); + void on_ckCanMove_stateChanged(int arg1); + +private: + Ui::frmDeviceButton *ui; + DeviceButton *btn1; + DeviceButton *btn2; + DeviceButton *btn3; + QList btnStyle; + QList btnColor; +}; + +#endif // FRMDEVICEBUTTON_H diff --git a/buttondefence/frmbuttondefence.ui b/devicebutton/frmdevicebutton.ui similarity index 87% rename from buttondefence/frmbuttondefence.ui rename to devicebutton/frmdevicebutton.ui index 5e914fc..4470065 100644 --- a/buttondefence/frmbuttondefence.ui +++ b/devicebutton/frmdevicebutton.ui @@ -1,7 +1,7 @@ - frmButtonDefence - + frmDeviceButton + 0 @@ -95,37 +95,37 @@ - + - 布防 + 绿色 - + - 撤防 + 蓝色 - + - 报警 + 红色 - + - 旁路 + 灰色 - + - 故障 + 黑色 diff --git a/buttondefence/image/bg_call.jpg b/devicebutton/image/bg_call.jpg similarity index 100% rename from buttondefence/image/bg_call.jpg rename to devicebutton/image/bg_call.jpg diff --git a/buttondefence/image/buttondefence/btn_defence_error_bubble.png b/devicebutton/image/devicebutton/devicebutton_black_bubble.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_error_bubble.png rename to devicebutton/image/devicebutton/devicebutton_black_bubble.png diff --git a/buttondefence/image/buttondefence/btn_defence_error_bubble2.png b/devicebutton/image/devicebutton/devicebutton_black_bubble2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_error_bubble2.png rename to devicebutton/image/devicebutton/devicebutton_black_bubble2.png diff --git a/buttondefence/image/buttondefence/btn_defence_error_circle.png b/devicebutton/image/devicebutton/devicebutton_black_circle.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_error_circle.png rename to devicebutton/image/devicebutton/devicebutton_black_circle.png diff --git a/buttondefence/image/buttondefence/btn_defence_error_msg.png b/devicebutton/image/devicebutton/devicebutton_black_msg.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_error_msg.png rename to devicebutton/image/devicebutton/devicebutton_black_msg.png diff --git a/buttondefence/image/buttondefence/btn_defence_error_msg2.png b/devicebutton/image/devicebutton/devicebutton_black_msg2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_error_msg2.png rename to devicebutton/image/devicebutton/devicebutton_black_msg2.png diff --git a/buttondefence/image/buttondefence/btn_defence_error_police.png b/devicebutton/image/devicebutton/devicebutton_black_police.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_error_police.png rename to devicebutton/image/devicebutton/devicebutton_black_police.png diff --git a/buttondefence/image/buttondefence/btn_defence_disarming_bubble.png b/devicebutton/image/devicebutton/devicebutton_blue_bubble.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_disarming_bubble.png rename to devicebutton/image/devicebutton/devicebutton_blue_bubble.png diff --git a/buttondefence/image/buttondefence/btn_defence_disarming_bubble2.png b/devicebutton/image/devicebutton/devicebutton_blue_bubble2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_disarming_bubble2.png rename to devicebutton/image/devicebutton/devicebutton_blue_bubble2.png diff --git a/buttondefence/image/buttondefence/btn_defence_disarming_circle.png b/devicebutton/image/devicebutton/devicebutton_blue_circle.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_disarming_circle.png rename to devicebutton/image/devicebutton/devicebutton_blue_circle.png diff --git a/buttondefence/image/buttondefence/btn_defence_disarming_msg.png b/devicebutton/image/devicebutton/devicebutton_blue_msg.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_disarming_msg.png rename to devicebutton/image/devicebutton/devicebutton_blue_msg.png diff --git a/buttondefence/image/buttondefence/btn_defence_disarming_msg2.png b/devicebutton/image/devicebutton/devicebutton_blue_msg2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_disarming_msg2.png rename to devicebutton/image/devicebutton/devicebutton_blue_msg2.png diff --git a/buttondefence/image/buttondefence/btn_defence_disarming_police.png b/devicebutton/image/devicebutton/devicebutton_blue_police.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_disarming_police.png rename to devicebutton/image/devicebutton/devicebutton_blue_police.png diff --git a/buttondefence/image/buttondefence/btn_defence_bypass_bubble.png b/devicebutton/image/devicebutton/devicebutton_gray_bubble.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_bypass_bubble.png rename to devicebutton/image/devicebutton/devicebutton_gray_bubble.png diff --git a/buttondefence/image/buttondefence/btn_defence_bypass_bubble2.png b/devicebutton/image/devicebutton/devicebutton_gray_bubble2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_bypass_bubble2.png rename to devicebutton/image/devicebutton/devicebutton_gray_bubble2.png diff --git a/buttondefence/image/buttondefence/btn_defence_bypass_circle.png b/devicebutton/image/devicebutton/devicebutton_gray_circle.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_bypass_circle.png rename to devicebutton/image/devicebutton/devicebutton_gray_circle.png diff --git a/buttondefence/image/buttondefence/btn_defence_bypass_msg.png b/devicebutton/image/devicebutton/devicebutton_gray_msg.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_bypass_msg.png rename to devicebutton/image/devicebutton/devicebutton_gray_msg.png diff --git a/buttondefence/image/buttondefence/btn_defence_bypass_msg2.png b/devicebutton/image/devicebutton/devicebutton_gray_msg2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_bypass_msg2.png rename to devicebutton/image/devicebutton/devicebutton_gray_msg2.png diff --git a/buttondefence/image/buttondefence/btn_defence_bypass_police.png b/devicebutton/image/devicebutton/devicebutton_gray_police.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_bypass_police.png rename to devicebutton/image/devicebutton/devicebutton_gray_police.png diff --git a/buttondefence/image/buttondefence/btn_defence_arming_bubble.png b/devicebutton/image/devicebutton/devicebutton_green_bubble.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_arming_bubble.png rename to devicebutton/image/devicebutton/devicebutton_green_bubble.png diff --git a/buttondefence/image/buttondefence/btn_defence_arming_bubble2.png b/devicebutton/image/devicebutton/devicebutton_green_bubble2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_arming_bubble2.png rename to devicebutton/image/devicebutton/devicebutton_green_bubble2.png diff --git a/buttondefence/image/buttondefence/btn_defence_arming_circle.png b/devicebutton/image/devicebutton/devicebutton_green_circle.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_arming_circle.png rename to devicebutton/image/devicebutton/devicebutton_green_circle.png diff --git a/buttondefence/image/buttondefence/btn_defence_arming_msg.png b/devicebutton/image/devicebutton/devicebutton_green_msg.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_arming_msg.png rename to devicebutton/image/devicebutton/devicebutton_green_msg.png diff --git a/buttondefence/image/buttondefence/btn_defence_arming_msg2.png b/devicebutton/image/devicebutton/devicebutton_green_msg2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_arming_msg2.png rename to devicebutton/image/devicebutton/devicebutton_green_msg2.png diff --git a/buttondefence/image/buttondefence/btn_defence_arming_police.png b/devicebutton/image/devicebutton/devicebutton_green_police.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_arming_police.png rename to devicebutton/image/devicebutton/devicebutton_green_police.png diff --git a/buttondefence/image/buttondefence/btn_defence_alarm_bubble.png b/devicebutton/image/devicebutton/devicebutton_red_bubble.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_alarm_bubble.png rename to devicebutton/image/devicebutton/devicebutton_red_bubble.png diff --git a/buttondefence/image/buttondefence/btn_defence_alarm_bubble2.png b/devicebutton/image/devicebutton/devicebutton_red_bubble2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_alarm_bubble2.png rename to devicebutton/image/devicebutton/devicebutton_red_bubble2.png diff --git a/buttondefence/image/buttondefence/btn_defence_alarm_circle.png b/devicebutton/image/devicebutton/devicebutton_red_circle.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_alarm_circle.png rename to devicebutton/image/devicebutton/devicebutton_red_circle.png diff --git a/buttondefence/image/buttondefence/btn_defence_alarm_msg.png b/devicebutton/image/devicebutton/devicebutton_red_msg.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_alarm_msg.png rename to devicebutton/image/devicebutton/devicebutton_red_msg.png diff --git a/buttondefence/image/buttondefence/btn_defence_alarm_msg2.png b/devicebutton/image/devicebutton/devicebutton_red_msg2.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_alarm_msg2.png rename to devicebutton/image/devicebutton/devicebutton_red_msg2.png diff --git a/buttondefence/image/buttondefence/btn_defence_alarm_police.png b/devicebutton/image/devicebutton/devicebutton_red_police.png similarity index 100% rename from buttondefence/image/buttondefence/btn_defence_alarm_police.png rename to devicebutton/image/devicebutton/devicebutton_red_police.png diff --git a/buttondefence/main.cpp b/devicebutton/main.cpp similarity index 87% rename from buttondefence/main.cpp rename to devicebutton/main.cpp index b0b2855..0ab185b 100644 --- a/buttondefence/main.cpp +++ b/devicebutton/main.cpp @@ -1,6 +1,6 @@ #pragma execution_character_set("utf-8") -#include "frmbuttondefence.h" +#include "frmdevicebutton.h" #include #include @@ -23,8 +23,8 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); #endif - frmButtonDefence w; - w.setWindowTitle("防区按钮控件"); + frmDeviceButton w; + w.setWindowTitle("设备按钮控件"); w.show(); return a.exec(); diff --git a/devicebutton/main.qrc b/devicebutton/main.qrc new file mode 100644 index 0000000..07d37f5 --- /dev/null +++ b/devicebutton/main.qrc @@ -0,0 +1,35 @@ + + + image/bg_call.jpg + image/devicebutton/devicebutton_black_bubble.png + image/devicebutton/devicebutton_black_bubble2.png + image/devicebutton/devicebutton_black_circle.png + image/devicebutton/devicebutton_black_msg.png + image/devicebutton/devicebutton_black_msg2.png + image/devicebutton/devicebutton_black_police.png + image/devicebutton/devicebutton_blue_bubble.png + image/devicebutton/devicebutton_blue_bubble2.png + image/devicebutton/devicebutton_blue_circle.png + image/devicebutton/devicebutton_blue_msg.png + image/devicebutton/devicebutton_blue_msg2.png + image/devicebutton/devicebutton_blue_police.png + image/devicebutton/devicebutton_gray_bubble.png + image/devicebutton/devicebutton_gray_bubble2.png + image/devicebutton/devicebutton_gray_circle.png + image/devicebutton/devicebutton_gray_msg.png + image/devicebutton/devicebutton_gray_msg2.png + image/devicebutton/devicebutton_gray_police.png + image/devicebutton/devicebutton_green_bubble.png + image/devicebutton/devicebutton_green_bubble2.png + image/devicebutton/devicebutton_green_circle.png + image/devicebutton/devicebutton_green_msg.png + image/devicebutton/devicebutton_green_msg2.png + image/devicebutton/devicebutton_green_police.png + image/devicebutton/devicebutton_red_bubble.png + image/devicebutton/devicebutton_red_bubble2.png + image/devicebutton/devicebutton_red_circle.png + image/devicebutton/devicebutton_red_msg.png + image/devicebutton/devicebutton_red_msg2.png + image/devicebutton/devicebutton_red_police.png + +