From 2a09f7656ec6a66f9356551c6ade0bbf2e823a66 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Wed, 29 Oct 2025 17:38:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=8C=E6=88=90=E6=94=B6=E5=88=B0?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E6=8A=A5=E8=AD=A6=E6=97=B6=E7=9A=84UI?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/alarmEventDataView.h | 5 ++ include/alarmEventRealTimeDock.h | 17 ++++- source/alarmEventDataView.cpp | 4 +- source/alarmEventRealTimeDock.cpp | 100 +++++++++++++++++++++++++++--- 4 files changed, 115 insertions(+), 11 deletions(-) diff --git a/include/alarmEventDataView.h b/include/alarmEventDataView.h index 7c492c9..c15f201 100644 --- a/include/alarmEventDataView.h +++ b/include/alarmEventDataView.h @@ -108,6 +108,9 @@ public: void firstPage(); void lastPage(); +signals: + void receivedNewAlarm(const EventData& even); + private slots: void onTimeoutSimulateData(); void onRealTimeEventReceived(const EventData& event); @@ -180,6 +183,8 @@ public: AlarmEventDataView(AlarmDataMode mode, QWidget* parent = nullptr); ~AlarmEventDataView(); + AlarmEventDataModel* model() const { return m_tableModel; } + //void setModelMode(AlarmDataMode, int maxRealTimeEvents = 5); public slots: diff --git a/include/alarmEventRealTimeDock.h b/include/alarmEventRealTimeDock.h index ff899e6..393c10e 100644 --- a/include/alarmEventRealTimeDock.h +++ b/include/alarmEventRealTimeDock.h @@ -2,6 +2,7 @@ #define ALARMEVENTREALTIMEDOCK_H #include +#include "alarmEventGlobal.h" QT_BEGIN_NAMESPACE namespace Ui { @@ -14,6 +15,7 @@ class QPropertyAnimation; class AlarmEventRealTimeDock : public QWidget { Q_OBJECT + Q_PROPERTY(float alertWidgetBGColorAlpha READ alertWidgetBGColorAlpha WRITE setAlertWidgetBGColorAlpha NOTIFY alertWidgetBGColorAlphaChanged) public: AlarmEventRealTimeDock(QWidget *parent = nullptr); @@ -21,21 +23,34 @@ public: void updateGeometry(); +signals: + void alertWidgetBGColorAlphaChanged(float value); + public slots: void onBtnClicked_open(); void onBtnClicked_close(); void onBtnClicked_confirmAll(); void onBtnClicked_checkAll(); + void onSIG_receivedNewAlarm(const EventData& event); private: void expand(); void collapse(); + void startAlarmAlert(); + void stopAlarmAlert(); + float alertWidgetBGColorAlpha() {return m_alertWidgetBGColorAlpha;} + void setAlertWidgetBGColorAlpha(float value); + void updateAlertWidgetBGColorAlpha(); + Ui::alarmEventRealTimeDock* ui; AlarmEventDataView* m_tableView; QPropertyAnimation* m_animationExpand; QPropertyAnimation* m_animationAlert; - bool m_isInAnimation; + bool m_isInAnimationExpand; + bool m_isInAnimationAlert; + float m_alertWidgetBGColorAlpha; + QString m_alertWidgetStyleSheet; QString m_curState; }; diff --git a/source/alarmEventDataView.cpp b/source/alarmEventDataView.cpp index 10f5dbf..37a4269 100644 --- a/source/alarmEventDataView.cpp +++ b/source/alarmEventDataView.cpp @@ -109,7 +109,7 @@ AlarmEventDataModel::AlarmEventDataModel(AlarmDataMode mode, QObject* parent) //实时数据测试 m_simulatedDataTimer = new QTimer(this); connect(m_simulatedDataTimer, &QTimer::timeout, this, &AlarmEventDataModel::onTimeoutSimulateData); - m_simulatedDataTimer->start(2500); + m_simulatedDataTimer->start(3000); } AlarmEventDataModel::~AlarmEventDataModel() @@ -423,6 +423,8 @@ void AlarmEventDataModel::onRealTimeEventReceived(const EventData& event) m_displayEvents.append(event); endResetModel(); + + emit receivedNewAlarm(event); } bool AlarmEventDataModel::setCurrentPage(int page) diff --git a/source/alarmEventRealTimeDock.cpp b/source/alarmEventRealTimeDock.cpp index c490898..b70d617 100644 --- a/source/alarmEventRealTimeDock.cpp +++ b/source/alarmEventRealTimeDock.cpp @@ -13,15 +13,31 @@ AlarmEventRealTimeDock::AlarmEventRealTimeDock(QWidget* parent) ui->setupUi(this); setAttribute(Qt::WA_TranslucentBackground); - m_isInAnimation = false; + m_isInAnimationExpand = false; + m_isInAnimationAlert = false; m_curState = "collapse"; m_tableView = new AlarmEventDataView(RealTime, this); ui->tableLayout->addWidget(m_tableView); + connect(m_tableView->model(), &AlarmEventDataModel::receivedNewAlarm, this, &AlarmEventRealTimeDock::onSIG_receivedNewAlarm); - m_animationExpand = new QPropertyAnimation(this, "geometry"); + m_animationExpand = new QPropertyAnimation(this, "geometry", this); m_animationExpand->setDuration(120); - connect(m_animationExpand, &QPropertyAnimation::finished, this, [this]{m_isInAnimation = false;}); + connect(m_animationExpand, &QPropertyAnimation::finished, this, [this]{m_isInAnimationExpand = false;}); + + m_animationAlert = new QPropertyAnimation(this, "alertWidgetBGColorAlpha", this); + m_animationAlert->setDuration(3000); + m_animationAlert->setStartValue(0.0); + m_animationAlert->setEndValue(1.0); + m_animationAlert->setLoopCount(-1);//无限循环 + m_alertWidgetStyleSheet = QString( + "background-color: qradialgradient(" + "spread:pad, " + "cx:0.5, cy:0.5, radius:0.5, " + "fx:0.5, fy:0.5, " + "stop:0 rgba(200, 0, 0, 0), " + "stop:1 rgba(255, 255, 255, 0));" + ); ui->btnClose->setVisible(false); connect(ui->btnOpen, &QPushButton::clicked, this, &AlarmEventRealTimeDock::onBtnClicked_open); @@ -45,7 +61,7 @@ AlarmEventRealTimeDock::~AlarmEventRealTimeDock() void AlarmEventRealTimeDock::expand() { - if(m_isInAnimation || m_curState == "expand" ) + if(m_isInAnimationExpand || m_curState == "expand" ) return; QWidget* parent = this->parentWidget(); @@ -57,13 +73,15 @@ void AlarmEventRealTimeDock::expand() m_animationExpand->setEndValue(endRect); m_animationExpand->start(); m_curState = "expand"; - m_isInAnimation = true; + m_isInAnimationExpand = true; + + stopAlarmAlert(); } } void AlarmEventRealTimeDock::collapse() { - if(m_isInAnimation || m_curState == "collapse" ) + if(m_isInAnimationExpand || m_curState == "collapse" ) return; QWidget* parent = this->parentWidget(); @@ -75,7 +93,7 @@ void AlarmEventRealTimeDock::collapse() m_animationExpand->setEndValue(endRect); m_animationExpand->start(); m_curState = "collapse"; - m_isInAnimation = true; + m_isInAnimationExpand = true; } } @@ -95,6 +113,63 @@ void AlarmEventRealTimeDock::updateGeometry() } } +void AlarmEventRealTimeDock::startAlarmAlert() +{ + if(m_isInAnimationAlert || m_curState == "expand") + return; + + m_animationAlert->start(); + m_isInAnimationAlert = true; +} + +void AlarmEventRealTimeDock::stopAlarmAlert() +{ + if(!m_isInAnimationAlert) + return; + + m_animationAlert->stop(); + m_isInAnimationAlert = false; + + m_alertWidgetStyleSheet = QString( + "background-color: qradialgradient(" + "spread:pad, " + "cx:0.5, cy:0.5, radius:0.5, " + "fx:0.5, fy:0.5, " + "stop:0 rgba(200, 0, 0, 0), " + "stop:1 rgba(255, 255, 255, 0));" + ); + ui->alertWidget->setStyleSheet(m_alertWidgetStyleSheet); +} + +void AlarmEventRealTimeDock::setAlertWidgetBGColorAlpha(float value) +{ + m_alertWidgetBGColorAlpha = value; + updateAlertWidgetBGColorAlpha(); +} + +void AlarmEventRealTimeDock::updateAlertWidgetBGColorAlpha() +{ + // 计算透明度 (从0到200再到0) + int alpha = 200 * (1 - qAbs(2 * m_alertWidgetBGColorAlpha - 1)); + if(alpha == 1) //1表示不透,具体原因为探究,先舍弃该值 + return; + QString styleSheet = QString( + "background-color: qradialgradient(" + "spread:pad, " + "cx:0.5, cy:0.5, radius:0.5, " + "fx:0.5, fy:0.5, " + "stop:0 rgba(200, 0, 0, %1), " + "stop:1 rgba(255, 255, 255, 0));" + ).arg(alpha); + + if(m_alertWidgetStyleSheet != styleSheet) + { + //qDebug() << alpha; + ui->alertWidget->setStyleSheet(styleSheet); + m_alertWidgetStyleSheet = styleSheet; + } +} + void AlarmEventRealTimeDock::onBtnClicked_open() { expand(); @@ -110,9 +185,16 @@ void AlarmEventRealTimeDock::onBtnClicked_close() } void AlarmEventRealTimeDock::onBtnClicked_confirmAll() -{} +{ + //stopAlarmAlert(); +} void AlarmEventRealTimeDock::onBtnClicked_checkAll() -{} +{ +} +void AlarmEventRealTimeDock::onSIG_receivedNewAlarm(const EventData& event) +{ + startAlarmAlert(); +}