fix: Alert dialog render bug

This commit is contained in:
chenhuijun
2024-07-19 16:09:19 +08:00
parent d9b903e1e3
commit 3cd25d8fbc
6 changed files with 59 additions and 4 deletions

View File

@@ -2,6 +2,10 @@
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>
#include <qdebug.h>
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()<<aFormat;
qDebug()<<aValue;
QString message = aFormat.arg(aValue);
QFont font = mLblMsg->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)

View File

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

View File

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

View File

@@ -50,6 +50,7 @@ public:
int requestEditAdminAccount(const QMap<QString, QVariant>& 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();

View File

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

View File

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