fix: Alert dialog render bug
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
#include <QtWidgets/QVBoxLayout>
|
#include <QtWidgets/QVBoxLayout>
|
||||||
#include <QtWidgets/QLabel>
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <qdebug.h>
|
||||||
|
namespace{
|
||||||
|
const char* MESSAGE_PLACEHOLDER = "ABCDE...";
|
||||||
|
}
|
||||||
|
|
||||||
AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f)
|
AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f)
|
||||||
: GUIFormBaseDialog(parent, f)
|
: GUIFormBaseDialog(parent, f)
|
||||||
@@ -26,11 +30,36 @@ AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f)
|
|||||||
|
|
||||||
void AlertDialog::setAlertMessage(const QString &msg)
|
void AlertDialog::setAlertMessage(const QString &msg)
|
||||||
{
|
{
|
||||||
mLblMsg->setText(msg);
|
|
||||||
QFont font = mLblMsg->font();
|
QFont font = mLblMsg->font();
|
||||||
QFontMetrics metrics(font);
|
QFontMetrics metrics(font);
|
||||||
|
|
||||||
|
mLblMsg->setText(msg);
|
||||||
|
|
||||||
int width = metrics.width(mLblMsg->text());
|
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)
|
void AlertDialog::setTitle(const QString &msg)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ public:
|
|||||||
explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||||
~AlertDialog() override = default;
|
~AlertDialog() override = default;
|
||||||
void setAlertMessage(const QString& msg);
|
void setAlertMessage(const QString& msg);
|
||||||
|
void setAlertMessage(const QString& aFormat,const QString& aValue);
|
||||||
|
|
||||||
void setTitle(const QString& msg);
|
void setTitle(const QString& msg);
|
||||||
protected:
|
protected:
|
||||||
bool updateReferenceData() override{return true;}
|
bool updateReferenceData() override{return true;}
|
||||||
|
|||||||
@@ -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)
|
DialogResult DialogManager::requestSelectDate(const QString& aDate)
|
||||||
{
|
{
|
||||||
DateSelectDialog dialog(mTopWidget);
|
DateSelectDialog dialog(mTopWidget);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
int requestEditAdminAccount(const QMap<QString, QVariant>& values);
|
int requestEditAdminAccount(const QMap<QString, QVariant>& values);
|
||||||
int requestEditPatientInfo(PatientInformation* aPatientFrom, QSqlTableModel* aModel);
|
int requestEditPatientInfo(PatientInformation* aPatientFrom, QSqlTableModel* aModel);
|
||||||
int requestAlertMessage(const QString& aMessage, DialogButtonMode aButtonMode,const QString& aTitle = QString());
|
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 requestSelectDate(const QString& aDate);
|
||||||
DialogResult requestSelectTime(const int& aSeconds);
|
DialogResult requestSelectTime(const int& aSeconds);
|
||||||
DialogResult requestSelectLanguage();
|
DialogResult requestSelectLanguage();
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ void SelectFormWidget::delPatient() {
|
|||||||
}
|
}
|
||||||
// not the selected one, confirm!
|
// not the selected one, confirm!
|
||||||
QString pat_name = mModel->index(mPatTable->currentIndex().row(), Name).data().toString();
|
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
|
// need delete clear edit panel detail
|
||||||
patientDetailForm->clearPatientInformation();
|
patientDetailForm->clearPatientInformation();
|
||||||
//mModel->setData(mModel->index(mPatTable->currentIndex().row(), Flag), 9);
|
//mModel->setData(mModel->index(mPatTable->currentIndex().row(), Flag), 9);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ AccountTableForm::AccountTableForm(QWidget* aParent)
|
|||||||
return;
|
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->removeRow(mCurrentRow);
|
||||||
model->select();
|
model->select();
|
||||||
mCurrentRow = model->rowCount() > mCurrentRow + 1 ? mCurrentRow : mCurrentRow - 1;
|
mCurrentRow = model->rowCount() > mCurrentRow + 1 ? mCurrentRow : mCurrentRow - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user