feat:完成收到实时报警时的UI提示功能

This commit is contained in:
duanshengchao 2025-10-29 17:38:57 +08:00
parent 68a9956bcb
commit 2a09f7656e
4 changed files with 115 additions and 11 deletions

View File

@ -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:

View File

@ -2,6 +2,7 @@
#define ALARMEVENTREALTIMEDOCK_H
#include <QWidget>
#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;
};

View File

@ -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)

View File

@ -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();
}