fix: Alert dialog render bug
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user