From 5f1c06314a6880ca3888287bd2f9a52eb61200d4 Mon Sep 17 00:00:00 2001 From: sunwen Date: Thu, 20 Jun 2024 18:07:34 +0800 Subject: [PATCH] feat: Add ErrorLabel component. --- src/components/ErrorLabel.cpp | 17 +++++++++++++++++ src/components/ErrorLabel.h | 14 ++++++++++++++ src/dialogs/MppsSettingsDialog.cpp | 17 ++++++++--------- src/dialogs/MppsSettingsDialog.h | 4 ++-- src/dialogs/PacsSettingsDialog.cpp | 17 ++++++++--------- src/dialogs/PacsSettingsDialog.h | 4 ++-- src/dialogs/ReconSettingsDialog.cpp | 17 ++++++++--------- src/dialogs/ReconSettingsDialog.h | 4 ++-- src/dialogs/WorklistSettingsDialog.cpp | 16 ++++++++-------- src/dialogs/WorklistSettingsDialog.h | 4 ++-- 10 files changed, 71 insertions(+), 43 deletions(-) create mode 100644 src/components/ErrorLabel.cpp create mode 100644 src/components/ErrorLabel.h diff --git a/src/components/ErrorLabel.cpp b/src/components/ErrorLabel.cpp new file mode 100644 index 0000000..dabc9a3 --- /dev/null +++ b/src/components/ErrorLabel.cpp @@ -0,0 +1,17 @@ +#include "ErrorLabel.h" + +ErrorLabel::ErrorLabel(QWidget* aParent) + : QLabel(aParent) +{ + setObjectName("warn"); + setWordWrap(true); +} + +void ErrorLabel::setErrorText(const QString& aText) +{ + QFont font = this->font(); + QFontMetrics metrics(font); + int width = metrics.width(aText); + this->setFixedHeight(metrics.lineSpacing() * (width / this->width()) + 30 ); + setText(aText); +} diff --git a/src/components/ErrorLabel.h b/src/components/ErrorLabel.h new file mode 100644 index 0000000..da4a716 --- /dev/null +++ b/src/components/ErrorLabel.h @@ -0,0 +1,14 @@ +#ifndef ERRORLABEL_H +#define ERRORLABEL_H + +#include + +class ErrorLabel : public QLabel +{ +public: + ErrorLabel(QWidget* aParent); + + void setErrorText(const QString& aText); +}; + +#endif // ERRORLABEL_H diff --git a/src/dialogs/MppsSettingsDialog.cpp b/src/dialogs/MppsSettingsDialog.cpp index 8d533c1..5b0c0e7 100644 --- a/src/dialogs/MppsSettingsDialog.cpp +++ b/src/dialogs/MppsSettingsDialog.cpp @@ -1,12 +1,12 @@ #include "MppsSettingsDialog.h" #include "components/ULineEdit.h" +#include "components/ErrorLabel.h" #include "dialogs/DicomSettingsArea.h" #include "json/jsonobject.h" #include "log/UserOperationLog.h" #include -#include namespace { @@ -16,7 +16,7 @@ namespace MppsSettingsDialog::MppsSettingsDialog(QWidget* aParent, Qt::WindowFlags aWindowFlag) : GUIFormBaseDialog(aParent, aWindowFlag) , mSettingsArea(new DicomSettingsArea(this)) - , mErrorText(new QLabel(this)) + , mErrorText(new ErrorLabel(this)) { QVBoxLayout* layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); @@ -33,7 +33,6 @@ MppsSettingsDialog::MppsSettingsDialog(QWidget* aParent, Qt::WindowFlags aWindow endline->setObjectName("endline"); layout->addWidget(endline); layout->addWidget(mErrorText); - mErrorText->setObjectName("warn"); mErrorText->hide(); initConfig(); @@ -65,37 +64,37 @@ bool MppsSettingsDialog::updateReferenceData() if(myAETitle.isEmpty()) { - mErrorText->setText(tr("AE can't be empty")); + mErrorText->setErrorText(tr("AE can't be empty")); return false; } if(serverAETitle.isEmpty()) { - mErrorText->setText(tr("Server AE can't be empty")); + mErrorText->setErrorText(tr("Server AE can't be empty")); return false; } if(serverIp.isEmpty()) { - mErrorText->setText(tr("Server Ip can't be empty")); + mErrorText->setErrorText(tr("Server Ip can't be empty")); return false; } if(serverPort.isEmpty()) { - mErrorText->setText(tr("Server Port can't be empty")); + mErrorText->setErrorText(tr("Server Port can't be empty")); return false; } if(!mSettingsArea->isIpAddressValid()) { - mErrorText->setText(tr("Ip Address is not valid")); + mErrorText->setErrorText(tr("Ip Address is not valid")); return false; } if(!mSettingsArea->isPortValid()) { - mErrorText->setText(tr("Port is not valid")); + mErrorText->setErrorText(tr("Port is not valid")); return false; } diff --git a/src/dialogs/MppsSettingsDialog.h b/src/dialogs/MppsSettingsDialog.h index 9dab622..8feda59 100644 --- a/src/dialogs/MppsSettingsDialog.h +++ b/src/dialogs/MppsSettingsDialog.h @@ -4,7 +4,7 @@ #include "dialogs/GUIFormBaseDialog.h" class DicomSettingsArea; -class QLabel; +class ErrorLabel; class MppsSettingsDialog : public GUIFormBaseDialog { @@ -21,7 +21,7 @@ private: private: DicomSettingsArea* mSettingsArea; - QLabel* mErrorText; + ErrorLabel* mErrorText; }; #endif // MPPSSETTINGSDIALOG_H diff --git a/src/dialogs/PacsSettingsDialog.cpp b/src/dialogs/PacsSettingsDialog.cpp index 1b42ff4..42726ed 100644 --- a/src/dialogs/PacsSettingsDialog.cpp +++ b/src/dialogs/PacsSettingsDialog.cpp @@ -2,9 +2,9 @@ #include "dialogs/DicomSettingsArea.h" #include "json/jsonobject.h" #include "log/UserOperationLog.h" +#include "components/ErrorLabel.h" #include -#include namespace { @@ -14,7 +14,7 @@ namespace PacsSettingsDialog::PacsSettingsDialog(QWidget* aParent, Qt::WindowFlags aWindowFlag) : GUIFormBaseDialog(aParent, aWindowFlag) , mSettingsArea(new DicomSettingsArea(this)) - , mErrorText(new QLabel(this)) + , mErrorText(new ErrorLabel(this)) { QVBoxLayout* layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); @@ -31,7 +31,6 @@ PacsSettingsDialog::PacsSettingsDialog(QWidget* aParent, Qt::WindowFlags aWindow endline->setObjectName("endline"); layout->addWidget(endline); layout->addWidget(mErrorText); - mErrorText->setObjectName("warn"); mErrorText->hide(); initConfig(); @@ -62,37 +61,37 @@ bool PacsSettingsDialog::updateReferenceData() if(myAETitle.isEmpty()) { - mErrorText->setText(tr("AE can't be empty")); + mErrorText->setErrorText(tr("AE can't be empty")); return false; } if(serverAETitle.isEmpty()) { - mErrorText->setText(tr("Server AE can't be empty")); + mErrorText->setErrorText(tr("Server AE can't be empty")); return false; } if(serverIp.isEmpty()) { - mErrorText->setText(tr("Server Ip can't be empty")); + mErrorText->setErrorText(tr("Server Ip can't be empty")); return false; } if(serverPort.isEmpty()) { - mErrorText->setText(tr("Server Port can't be empty")); + mErrorText->setErrorText(tr("Server Port can't be empty")); return false; } if(!mSettingsArea->isIpAddressValid()) { - mErrorText->setText(tr("Ip Address is not valid")); + mErrorText->setErrorText(tr("Ip Address is not valid")); return false; } if(!mSettingsArea->isPortValid()) { - mErrorText->setText(tr("Port is not valid")); + mErrorText->setErrorText(tr("Port is not valid")); return false; } diff --git a/src/dialogs/PacsSettingsDialog.h b/src/dialogs/PacsSettingsDialog.h index 140c085..b22c461 100644 --- a/src/dialogs/PacsSettingsDialog.h +++ b/src/dialogs/PacsSettingsDialog.h @@ -5,7 +5,7 @@ #include "dialogs/GUIFormBaseDialog.h" class DicomSettingsArea; -class QLabel; +class ErrorLabel; class PacsSettingsDialog : public GUIFormBaseDialog { @@ -22,7 +22,7 @@ private: private: DicomSettingsArea* mSettingsArea; - QLabel* mErrorText; + ErrorLabel* mErrorText; }; #endif // PACSSETTINGSDIALOG_H diff --git a/src/dialogs/ReconSettingsDialog.cpp b/src/dialogs/ReconSettingsDialog.cpp index 122ca9a..b8ebd0e 100644 --- a/src/dialogs/ReconSettingsDialog.cpp +++ b/src/dialogs/ReconSettingsDialog.cpp @@ -1,12 +1,12 @@ #include "ReconSettingsDialog.h" #include "components/ULineEdit.h" +#include "components/ErrorLabel.h" #include "dialogs/DicomSettingsArea.h" #include "json/jsonobject.h" #include "recon/ReconManager.h" #include "log/UserOperationLog.h" #include -#include namespace { @@ -16,7 +16,7 @@ namespace ReconSettingsDialog::ReconSettingsDialog(QWidget* aParent, Qt::WindowFlags aWindowFlag) : GUIFormBaseDialog(aParent, aWindowFlag) , mSettingsArea(new DicomSettingsArea(this)) - , mErrorText(new QLabel(this)) + , mErrorText(new ErrorLabel(this)) { QVBoxLayout* layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); @@ -33,7 +33,6 @@ ReconSettingsDialog::ReconSettingsDialog(QWidget* aParent, Qt::WindowFlags aWind endline->setObjectName("endline"); layout->addWidget(endline); layout->addWidget(mErrorText); - mErrorText->setObjectName("warn"); mErrorText->hide(); initConfig(); @@ -64,37 +63,37 @@ bool ReconSettingsDialog::updateReferenceData() if(myAETitle.isEmpty()) { - mErrorText->setText(tr("AE can't be empty")); + mErrorText->setErrorText(tr("AE can't be empty")); return false; } if(serverAETitle.isEmpty()) { - mErrorText->setText(tr("Server AE can't be empty")); + mErrorText->setErrorText(tr("Server AE can't be empty")); return false; } if(serverIp.isEmpty()) { - mErrorText->setText(tr("Server Ip can't be empty")); + mErrorText->setErrorText(tr("Server Ip can't be empty")); return false; } if(serverPort.isEmpty()) { - mErrorText->setText(tr("Server Port can't be empty")); + mErrorText->setErrorText(tr("Server Port can't be empty")); return false; } if(!mSettingsArea->isIpAddressValid()) { - mErrorText->setText(tr("Ip Address is not valid")); + mErrorText->setErrorText(tr("Ip Address is not valid")); return false; } if(!mSettingsArea->isPortValid()) { - mErrorText->setText(tr("Port is not valid")); + mErrorText->setErrorText(tr("Port is not valid")); return false; } diff --git a/src/dialogs/ReconSettingsDialog.h b/src/dialogs/ReconSettingsDialog.h index 6359668..c5d0f76 100644 --- a/src/dialogs/ReconSettingsDialog.h +++ b/src/dialogs/ReconSettingsDialog.h @@ -5,7 +5,7 @@ #include "dialogs/GUIFormBaseDialog.h" class DicomSettingsArea; -class QLabel; +class ErrorLabel; class ReconSettingsDialog : public GUIFormBaseDialog { @@ -22,7 +22,7 @@ private: private: DicomSettingsArea* mSettingsArea; - QLabel* mErrorText; + ErrorLabel* mErrorText; }; #endif // RECONSETTINGSDIALOG_H diff --git a/src/dialogs/WorklistSettingsDialog.cpp b/src/dialogs/WorklistSettingsDialog.cpp index 9f04345..c7c25ec 100644 --- a/src/dialogs/WorklistSettingsDialog.cpp +++ b/src/dialogs/WorklistSettingsDialog.cpp @@ -1,5 +1,6 @@ #include "WorklistSettingsDialog.h" #include "components/ULineEdit.h" +#include "components/ErrorLabel.h" #include "dialogs/DicomSettingsArea.h" #include "json/jsonobject.h" #include "log/UserOperationLog.h" @@ -15,7 +16,7 @@ namespace WorklistSettingsDialog::WorklistSettingsDialog(QWidget* aParent, Qt::WindowFlags aWindowFlag) : GUIFormBaseDialog(aParent, aWindowFlag) , mSettingsArea(new DicomSettingsArea(this)) - , mErrorText(new QLabel(this)) + , mErrorText(new ErrorLabel(this)) { QVBoxLayout* layout = new QVBoxLayout(mFormWidget); layout->setSpacing(10); @@ -32,7 +33,6 @@ WorklistSettingsDialog::WorklistSettingsDialog(QWidget* aParent, Qt::WindowFlags endline->setObjectName("endline"); layout->addWidget(endline); layout->addWidget(mErrorText); - mErrorText->setObjectName("warn"); mErrorText->hide(); initConfig(); @@ -63,37 +63,37 @@ bool WorklistSettingsDialog::updateReferenceData() if(myAETitle.isEmpty()) { - mErrorText->setText(tr("AE can't be empty")); + mErrorText->setErrorText(tr("AE can't be empty")); return false; } if(serverAETitle.isEmpty()) { - mErrorText->setText(tr("Server AE can't be empty")); + mErrorText->setErrorText(tr("Server AE can't be empty")); return false; } if(serverIp.isEmpty()) { - mErrorText->setText(tr("Server Ip can't be empty")); + mErrorText->setErrorText(tr("Server Ip can't be empty")); return false; } if(serverPort.isEmpty()) { - mErrorText->setText(tr("Server Port can't be empty")); + mErrorText->setErrorText(tr("Server Port can't be empty")); return false; } if(!mSettingsArea->isIpAddressValid()) { - mErrorText->setText(tr("Ip Address is not valid")); + mErrorText->setErrorText(tr("Ip Address is not valid")); return false; } if(!mSettingsArea->isPortValid()) { - mErrorText->setText(tr("Port is not valid")); + mErrorText->setErrorText(tr("Port is not valid")); return false; } diff --git a/src/dialogs/WorklistSettingsDialog.h b/src/dialogs/WorklistSettingsDialog.h index 28a73d8..3c520e7 100644 --- a/src/dialogs/WorklistSettingsDialog.h +++ b/src/dialogs/WorklistSettingsDialog.h @@ -4,7 +4,7 @@ #include "dialogs/GUIFormBaseDialog.h" class DicomSettingsArea; -class QLabel; +class ErrorLabel; class WorklistSettingsDialog : public GUIFormBaseDialog { @@ -21,7 +21,7 @@ private: private: DicomSettingsArea* mSettingsArea; - QLabel* mErrorText; + ErrorLabel* mErrorText; }; #endif // WORKLISTSETTINGSDIALOG_H