Add WarningLabel and WarningMessageWidget to App, and add some reference event to EventCenter

This commit is contained in:
chenhuijun
2024-04-19 14:08:44 +08:00
parent 14599ba05f
commit 7dc0404481
6 changed files with 458 additions and 8 deletions

View File

@@ -0,0 +1,55 @@
#include "WarningLabel.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QStyleOption>
#include <QPainter>
WarningLabel::WarningLabel(QWidget *aParent, WarningType aType, const QString& aMessageTime, const QString& content):QWidget(aParent)
{
setObjectName("WarningLabelWidget");
auto layout = new QVBoxLayout(this);
layout->setMargin(3);
layout->setSpacing(3);
auto titleLayout = new QHBoxLayout;
titleLayout->setMargin(0);
layout->addLayout(titleLayout);
auto icon = new QLabel;
icon->setObjectName("WarningLabelIcon");
titleLayout->addWidget(icon);
auto title = new QLabel;
titleLayout->addWidget(title);
title->setObjectName("WarningLabelTitle");
titleLayout->addSpacerItem(new QSpacerItem(2,2,QSizePolicy::Expanding));
auto contentText = new QLabel;
contentText->setText(content);
layout->addWidget(contentText);
contentText->setObjectName("WarningLabelText");
if(aType==ERROR){
QPixmap pixmap(":/icons/dicom/echo_fail.png");
icon->setPixmap(pixmap.scaledToHeight(20, Qt::SmoothTransformation));
title->setText(aMessageTime);
}
else{
QPixmap pixmap(":/icons/dicom/warning.png");
icon->setPixmap(pixmap.scaledToHeight(20, Qt::SmoothTransformation));
title->setText(aMessageTime);
}
}
void WarningLabel::paintEvent(QPaintEvent * aEvent)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View File

@@ -0,0 +1,24 @@
#ifndef _GUI_WARNINGLABEL_H__
#define _GUI_WARNINGLABEL_H__
#include <QWidget>
#include <QString>
enum WarningType{
ERROR, WARNING
};
class WarningLabel: public QWidget {
Q_OBJECT
public:
explicit WarningLabel(QWidget *aParent, WarningType aType,const QString& aMessageTime, const QString& content);
~WarningLabel() =default;
protected:
void paintEvent(QPaintEvent * aEvent);
private:
};
#endif // __WARNINGLABEL_H__

View File

@@ -0,0 +1,223 @@
#include "WarningMessageWidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QPropertyAnimation>
#include <QScrollArea>
#include <QScrollBar>
#include <QList>
#include <QDateTime>
#include <QDebug>
#include "SlideWidget.h"
#include "WarningLabel.h"
#include "event/EventCenter.h"
WarningMessageWidget::WarningMessageWidget(QWidget *parent):QWidget(parent)
, mWarnWidget(new SlideWidget(this))
, mErrorsWidget(new SlideWidget(this))
, mScrollArea(new QScrollArea(this))
, mScrollAreaW(new QScrollArea(this))
, mErrorCount(0)
, mWarningCount(0)
, mErrorEmptyMessage(new QLabel(tr("System is working properly.")))
, mWarningEmptyMessage(new QLabel(tr("No message.")))
{
// setWindowFlags(windowFlags()|Qt::FramelessWindowHint|Qt::Popup);
setWindowFlags(windowFlags()|Qt::FramelessWindowHint);
setWindowOpacity(1);
setAttribute(Qt::WA_TranslucentBackground);
setObjectName("WarningPanel");
auto layout = new QVBoxLayout(this);
//error panel
auto errorPanel = new QWidget;
errorPanel->setObjectName("ErrorPanelContent");
layout->addWidget(errorPanel);
auto errorLayout = new QVBoxLayout(errorPanel);
auto errorTitle = new QLabel;
errorTitle->setObjectName("WarningPanelTitle");
errorTitle->setText(tr("System Status"));
errorLayout->addWidget(errorTitle);
errorLayout->setMargin(0);
errorLayout->addWidget(mErrorEmptyMessage,0, Qt::AlignCenter | Qt::AlignHCenter);
//error slide widget
mScrollArea = new QScrollArea;
mScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
errorLayout->addWidget(mScrollArea);
mErrorsWidget = new SlideWidget(this);
mScrollArea->setWidget(mErrorsWidget);
mScrollArea->setWidgetResizable(true);
mErrorsWidget->setVerticalScrollBar(mScrollArea->verticalScrollBar());
{
auto l = new QVBoxLayout(mErrorsWidget);
l->setMargin(3);
l->addSpacerItem(new QSpacerItem(2,2,QSizePolicy::Expanding,QSizePolicy::Expanding));
}
mScrollArea->setVisible(false);
//warning panel
auto warningPanel = new QWidget(this);
warningPanel->setObjectName("WarningPanelContent");
layout->addWidget(warningPanel);
auto warningLayout = new QVBoxLayout(warningPanel);
auto warningTitle = new QLabel;
warningTitle->setObjectName("WarningPanelTitle");
warningTitle->setText(tr("System Notifications"));
warningLayout->addWidget(warningTitle);
warningLayout->setMargin(0);
warningLayout->addWidget(mWarningEmptyMessage, 0,Qt::AlignCenter | Qt::AlignHCenter);
mScrollAreaW->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
warningLayout->addWidget(mScrollAreaW);
mScrollAreaW->setVisible(false);
mScrollAreaW->setWidget(mWarnWidget);
mScrollAreaW->setWidgetResizable(true);
mWarnWidget->setVerticalScrollBar(mScrollAreaW->verticalScrollBar());
{
auto l = new QVBoxLayout(mWarnWidget);
l->setMargin(3);
l->addSpacerItem(new QSpacerItem(2,2,QSizePolicy::Expanding,QSizePolicy::Expanding));
}
mScrollAreaW->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
auto hl = new QHBoxLayout;
hl->setMargin(0);
warningLayout->addLayout(hl);
auto clearBtn= new QToolButton(this);
clearBtn->setText(tr("Clear"));
clearBtn->setObjectName("WarningPanelBtn");
hl->addWidget(clearBtn);
connect(clearBtn, &QToolButton::clicked, this, &WarningMessageWidget::clearWarning);
}
void WarningMessageWidget::setPopupArgs(int aHeight, int aX, int aY)
{
if (nullptr != showAnimation) return;
showAnimation = new QPropertyAnimation(this,"pos",this);
showAnimation->setDuration(250);
showAnimation->setStartValue(QPoint(aX,aY-10));
showAnimation->setEndValue(QPoint(aX-358,aY-10));
this->setFixedHeight(aHeight -aY -50 );
connect(EventCenter::Default(),&EventCenter::WarningMessageRaise,this,&WarningMessageWidget::addWarningProxySlot,Qt::QueuedConnection);
connect(EventCenter::Default(),&EventCenter::ErrorStateUnactive,this,&WarningMessageWidget::unactiveErrorProxySlot,Qt::QueuedConnection);
}
void WarningMessageWidget::addWarning(const QString& aDateTime, const QString& aContent)
{
QMutexLocker locker(&mWarningMutex);
auto label = new WarningLabel(mWarnWidget,WARNING,aDateTime,aContent);
qobject_cast<QVBoxLayout*>(mWarnWidget->layout())->insertWidget(0,label);
if(mWarningCount==0){
mWarningEmptyMessage->setVisible(false);
mScrollAreaW->setVisible(true);
}
mWarningCount++;
}
void WarningMessageWidget::addWarningProxySlot(QObject*, QObject* aData)
{
if (!aData){
qDebug()<<"addLabelProxy with null aData";
return;
}
QString str = *((QString*)aData);
activeError(601, str);
addWarning(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"), str);
}
void WarningMessageWidget::activeErrorProxySlot(QObject*, QObject* aData)
{
if (!aData){
qDebug()<<"activeErrorProxy with null aData";
return;
}
//TODO: real active error logic
QString str = "Test Error";
activeError(601, str);
}
void WarningMessageWidget::unactiveErrorProxySlot(QObject*, QObject* aData)
{
//TODO: real unactive error logic
// if (!aData){
// qDebug()<<"unactiveErrorProxy with null aData";
// return;
// }
unactiveError(601);
}
void WarningMessageWidget::clearWarning()
{
QMutexLocker locker(&mWarningMutex);
auto lbls = mWarnWidget->children();
for (QObject* item: lbls)
{
WarningLabel* lbl = qobject_cast<WarningLabel*>(item);
if (!lbl) continue;
mWarnWidget->layout()->removeWidget(lbl);
lbl->deleteLater();
}
mWarningCount=0;
mWarningEmptyMessage->setVisible(true);
mScrollAreaW->setVisible(false);
}
void WarningMessageWidget::activeError(int aCode, const QString&aContent)
{
QMutexLocker locker(&mErrorMutex);
auto lbls = mErrorsWidget->children();
for (QObject* item: lbls)
{
WarningLabel* lbl = qobject_cast<WarningLabel*>(item);
if (!lbl) continue;
if (lbl->property("code").toInt() == aCode) return;
}
auto label = new WarningLabel(mErrorsWidget,ERROR,QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"),aContent);
label->setProperty("code",aCode);
qobject_cast<QVBoxLayout*>(mErrorsWidget->layout())->insertWidget(0,label);
if(mErrorCount==0){
mErrorEmptyMessage->setVisible(false);
mScrollArea->setVisible(true);
}
mErrorCount++;
}
void WarningMessageWidget::unactiveError(int aCode)
{
QMutexLocker locker(&mErrorMutex);
auto lbls = mErrorsWidget->children();
for (QObject* item: lbls)
{
WarningLabel* lbl = qobject_cast<WarningLabel*>(item);
if (!lbl) continue;
if (lbl->property("code").toInt() == aCode){
mErrorsWidget->layout()->removeWidget(lbl);
lbl->deleteLater();
mErrorCount--;
break;
}
}
if (mErrorCount==0){
mErrorEmptyMessage->setVisible(true);
mScrollArea->setVisible(false);
}
}
void WarningMessageWidget::showEvent(QShowEvent* aEvent)
{
if (nullptr == showAnimation)return;
showAnimation->start();
QWidget::showEvent(aEvent);
}

View File

@@ -0,0 +1,43 @@
#ifndef _CUI_WARNINGMESSAGEWIDGET_H__
#define _CUI_WARNINGMESSAGEWIDGET_H__
#include <QWidget>
#include <QLinkedList>
#include <QMutex>
class QPropertyAnimation;
class SlideWidget;
class QScrollArea;
class QLabel;
class WarningMessageWidget: public QWidget {
Q_OBJECT
public:
explicit WarningMessageWidget(QWidget *parent = nullptr);
~WarningMessageWidget() =default;
void setPopupArgs(int aHeight, int aX, int aY);
void addWarning(const QString& aDateTime, const QString& aContent);
void clearWarning();
void activeError(int aCode, const QString&aContent);
void unactiveError(int aCode);
protected:
void showEvent(QShowEvent* aEvent);
protected slots:
void addWarningProxySlot(QObject*, QObject* aData);
void activeErrorProxySlot(QObject*, QObject* aData);
void unactiveErrorProxySlot(QObject*, QObject* aData);
private:
QPropertyAnimation* showAnimation = nullptr;
SlideWidget * mErrorsWidget;
SlideWidget * mWarnWidget;
QScrollArea* mScrollArea;
QScrollArea* mScrollAreaW;
QLabel* mErrorEmptyMessage;
QLabel* mWarningEmptyMessage;
QMutex mWarningMutex;
QMutex mErrorMutex;
int mErrorCount;
int mWarningCount;
};
#endif // __WARNINGMESSAGEWIDGET_H__

View File

@@ -41,6 +41,12 @@ ADD_EVENT_VALUE(RequestScreenSaver)\
ADD_EVENT_VALUE(ReconConnectionUpdated)\
ADD_EVENT_VALUE(InputWorkListSearchValue)\
ADD_EVENT_VALUE(DoWorkListSearch)\
ADD_EVENT_VALUE(WarningMessageRaise)\
ADD_EVENT_VALUE(ErrorStateActive)\
ADD_EVENT_VALUE(ErrorStateUnactive)\
enum GUIEvents {
#define ADD_EVENT_VALUE(val) val,

View File

@@ -258,6 +258,33 @@ QLabel#AlertDialogTitle
border-bottom: 1px solid grey;
}
/*------Global Scrollbar----------------------------------------------------------*/
QScrollBar:vertical {
background: #3c3c3c;
width: 12px;
margin-left: 1px;
margin-right: 2px;
margin-bottom: 5px;
}
QScrollBar::handle:vertical {
background: silver;
min-height: 20px;
border-radius: 3px;
padding: 2px 2px 2px 2px;
}
QScrollBar::add-line:vertical {
display: none;
background: none;
}
QScrollBar::sub-line:vertical {
display: none;
background: none;
}
/*------LoginWindow----------------------------------------------------------*/
QFrame#loginFrame {
min-width: 700px;
@@ -394,14 +421,6 @@ QLabel#link {
qproperty-scaledContents:true;
}
QLabel#ready {
min-width: 28px;
max-width: 28px;
min-height: 28px;
max-height: 28px;
qproperty-pixmap:url(":/icons/ready.png");
qproperty-scaledContents:true;
}
QLabel#company {
min-width: 150px;
@@ -412,6 +431,86 @@ QLabel#systemMsgBar {
min-width: 500px;
}
QToolButton#ready {
min-width: 28px;
max-width: 28px;
min-height: 28px;
max-height: 28px;
background: transparent;
qproperty-icon:url(":/icons/dicom/echo_suc.png");
qproperty-toolButtonStyle:ToolButtonTextBesideIcon;
qproperty-iconSize:26px 26px;
}
/*------WarningMessageWidget-------------------------------------------------*/
QWidget#WarningPanel{
min-width: 360px;
max-width: 500px;
/* background: darkgray; */
}
QWidget#WarningLabelWidget{
background: #505050;
border-radius: 5px;
padding: 5px;
padding-right: 0px;
margin-left: 2px;
}
QLabel#WarningLabelIcon{
min-height: 20px;
max-height: 20px;
margin-left: 3px;
}
QLabel#WarningLabelTitle{
font-size: 12px;
}
QLabel#WarningPanelTitle{
font-size: 20px;
border-bottom: 1px solid darkgoldenrod;
margin-left: 5px;
margin-right: 5px;
min-height: 30px;
max-height:30px;
}
QWidget#ErrorPanelContent QLabel#WarningLabelText{
font-size: 12px;
qproperty-wordWrap:true;
margin-left: 1px;
border-top: 1px solid darkgoldenrod ;
padding-top: 3px;
}
QWidget#WarningPanelContent QLabel#WarningLabelText{
font-size: 12px;
qproperty-wordWrap:true;
margin-left: 1px;
border-top: 1px solid darkgoldenrod;
padding-top: 3px;
}
QWidget#ErrorPanelContent{
border: 1px solid darkgoldenrod;
border-radius: 5px;
min-height: 300px;
max-height: 300px;
background: #323232;
}
QWidget#WarningPanelContent{
border: 1px solid darkgoldenrod;
border-radius: 5px;
min-height: 600px;
max-height: 800px;
background: #323232;
}
QToolButton#WarningPanelBtn{
font-size: 18px;
min-height: 30px;
max-height: 30px;
min-width: 120px;
max-width:120px;
border:2px solid #505050;
margin-bottom: 10px;
}
/*------TabFormWidget--------------------------------------------------------*/
TabFormWidget {
border-top: 1px solid #505050;