diff --git a/src/dialogs/AlertDialog.cpp b/src/dialogs/AlertDialog.cpp index 00fe2be..bcb01a7 100644 --- a/src/dialogs/AlertDialog.cpp +++ b/src/dialogs/AlertDialog.cpp @@ -2,6 +2,10 @@ #include #include +#include +namespace{ + const char* MESSAGE_PLACEHOLDER = "ABCDE..."; +} AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) @@ -26,11 +30,36 @@ AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) void AlertDialog::setAlertMessage(const QString &msg) { - mLblMsg->setText(msg); QFont font = mLblMsg->font(); QFontMetrics metrics(font); + + mLblMsg->setText(msg); + int width = metrics.width(mLblMsg->text()); - mLblMsg->setFixedHeight(metrics.lineSpacing() * (width / this->width()) + 30 );; + mLblMsg->setFixedHeight(metrics.lineSpacing() * (width / this->width()) + metrics.lineSpacing() ); +} + +void AlertDialog::setAlertMessage(const QString& aFormat,const QString& aValue) +{ + qDebug()<font(); + QFontMetrics metrics(font); + if (metrics.boundingRect(message).width()<470) + { + mLblMsg->setText(message); + return; + } + QString elideValue =metrics.elidedText(aValue,Qt::ElideRight, metrics.width(MESSAGE_PLACEHOLDER)); + message = aFormat.arg(elideValue); + if (metrics.boundingRect(message).width()<470) + { + mLblMsg->setText(message); + return; + } + mLblMsg->setText(message); } void AlertDialog::setTitle(const QString &msg) diff --git a/src/dialogs/AlertDialog.h b/src/dialogs/AlertDialog.h index fe53150..a274b0f 100644 --- a/src/dialogs/AlertDialog.h +++ b/src/dialogs/AlertDialog.h @@ -8,6 +8,8 @@ public: explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~AlertDialog() override = default; void setAlertMessage(const QString& msg); + void setAlertMessage(const QString& aFormat,const QString& aValue); + void setTitle(const QString& msg); protected: bool updateReferenceData() override{return true;} diff --git a/src/dialogs/DialogManager.cpp b/src/dialogs/DialogManager.cpp index eb69d7a..d8e6fe3 100644 --- a/src/dialogs/DialogManager.cpp +++ b/src/dialogs/DialogManager.cpp @@ -205,6 +205,29 @@ int DialogManager::requestAlertMessage(const QString& aMessage, DialogButtonMode } +int DialogManager::requestAlertMessage(const QString& aFormat,const QString & aValue, DialogButtonMode aButtonMode, const QString& aTitle) +{ + AlertDialog dialog(mTopWidget); + setTopWidget(&dialog); + dialog.setAlertMessage(aFormat, aValue); + if (!aTitle.isEmpty()) + { + dialog.setTitle(aTitle); + } + dialog.setButtonMode(aButtonMode); + dialog.setWindowModality(Qt::WindowModal); + if(dialog.parentWidget()->inherits("LoginDialog")) + { + dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint | Qt::BypassWindowManagerHint ); + } + + int ret = dialog.exec(); + releaseTopWidget(&dialog); + return ret; + +} + + DialogResult DialogManager::requestSelectDate(const QString& aDate) { DateSelectDialog dialog(mTopWidget); diff --git a/src/dialogs/DialogManager.h b/src/dialogs/DialogManager.h index 114dcc7..7468c66 100644 --- a/src/dialogs/DialogManager.h +++ b/src/dialogs/DialogManager.h @@ -50,6 +50,7 @@ public: int requestEditAdminAccount(const QMap& values); int requestEditPatientInfo(PatientInformation* aPatientFrom, QSqlTableModel* aModel); int requestAlertMessage(const QString& aMessage, DialogButtonMode aButtonMode,const QString& aTitle = QString()); + int requestAlertMessage(const QString& aFormat,const QString& aValue, DialogButtonMode aButtonMode,const QString& aTitle = QString()); DialogResult requestSelectDate(const QString& aDate); DialogResult requestSelectTime(const int& aSeconds); DialogResult requestSelectLanguage(); diff --git a/src/forms/select/SelectFormWidget.cpp b/src/forms/select/SelectFormWidget.cpp index 8448c45..35326c1 100644 --- a/src/forms/select/SelectFormWidget.cpp +++ b/src/forms/select/SelectFormWidget.cpp @@ -159,7 +159,7 @@ void SelectFormWidget::delPatient() { } // not the selected one, confirm! QString pat_name = mModel->index(mPatTable->currentIndex().row(), Name).data().toString(); - if (DialogManager::Default()->requestAlertMessage(QString(tr("Delete Patient \"%1\" ?")).arg(pat_name),DialogButtonMode::OkAndCancel,tr("Confirm")) != QDialog::Accepted) return; + if (DialogManager::Default()->requestAlertMessage(QString(tr("Delete Patient \"%1\" ?")),pat_name,DialogButtonMode::OkAndCancel,tr("Confirm")) != QDialog::Accepted) return; // need delete clear edit panel detail patientDetailForm->clearPatientInformation(); //mModel->setData(mModel->index(mPatTable->currentIndex().row(), Flag), 9); diff --git a/src/forms/settings/AccountTableForm.cpp b/src/forms/settings/AccountTableForm.cpp index c3bd32c..34cbc1e 100644 --- a/src/forms/settings/AccountTableForm.cpp +++ b/src/forms/settings/AccountTableForm.cpp @@ -127,7 +127,7 @@ AccountTableForm::AccountTableForm(QWidget* aParent) return; } - if ( DialogManager::Default()->requestAlertMessage(QString(tr("Delete account with ID:\"%1\"!")).arg(id), DialogButtonMode::OkAndCancel) != QDialog::Accepted) return; + if ( DialogManager::Default()->requestAlertMessage(QString(tr("Delete account with ID:\"%1\"!")), id, DialogButtonMode::OkAndCancel) != QDialog::Accepted) return; model->removeRow(mCurrentRow); model->select(); mCurrentRow = model->rowCount() > mCurrentRow + 1 ? mCurrentRow : mCurrentRow - 1;