Skip to content

Commit

Permalink
Fix SignatureItem redraw bug and use correct font with function (open…
Browse files Browse the repository at this point in the history
…-eid#1040)

IB-7280

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Mar 24, 2022
1 parent adf6ea9 commit 323fd86
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
6 changes: 1 addition & 5 deletions client/Styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ class FontDatabase

for(; fontSize >= MIN_FONT_SIZE; fontSize--)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
width = QFontMetrics(QFont(font, fontSize)).horizontalAdvance(sample.sample);
#else
width = QFontMetrics(QFont(font, fontSize)).width(sample.sample);
#endif
width = QFontMetrics(QFont(font, fontSize)).boundingRect(sample.sample).width();
if (width <= sample.width)
break;
prevWidth = width;
Expand Down
6 changes: 1 addition & 5 deletions client/dialogs/WarningDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ void WarningDialog::addButton(const QString& label, int ret, bool red)
button->setAccessibleName(label.toLower());
button->setCursor(ui->cancel->cursor());
button->setFont(ui->cancel->font());
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
button->setMinimumSize(std::max<int>(ui->cancel->minimumWidth(), ui->cancel->fontMetrics().horizontalAdvance(label) + 16), 34);
#else
button->setMinimumSize(std::max<int>(ui->cancel->minimumWidth(), ui->cancel->fontMetrics().width(label) + 16), 34);
#endif
button->setMinimumSize(std::max<int>(ui->cancel->minimumWidth(), ui->cancel->fontMetrics().boundingRect(label).width() + 16), 34);

if(red) {
button->setStyleSheet(QStringLiteral(
Expand Down
16 changes: 6 additions & 10 deletions client/widgets/SignatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ bool SignatureItem::isSelfSigned(const QString& cardCode, const QString& mobileC
return !ui->serial.isEmpty() && (ui->serial == cardCode || ui->serial == mobileCode);
}

QString SignatureItem::red(const QString &text)
QString SignatureItem::red(const QString &text, bool paint) const
{
return "<font color=\"red\">" + text + "</font>";
return paint ? QStringLiteral("<font color=\"red\">%1</font>").arg(text) : text;
}

void SignatureItem::removeSignature()
Expand All @@ -247,16 +247,12 @@ void SignatureItem::removeSignature()
void SignatureItem::updateNameField()
{
QTextDocument doc;
doc.setHtml(ui->name->text());
doc.setHtml(ui->status);
QString plain = doc.toPlainText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
if(ui->name->fontMetrics().horizontalAdvance(ui->nameText + " - " + plain) < ui->name->width())
#else
if(ui->name->fontMetrics().width(ui->nameText + " - " + plain) < ui->name->width())
#endif
ui->name->setText((ui->invalid ? red(ui->nameText + " - ") : ui->nameText + " - ") + ui->status);
if(ui->name->fontMetrics().boundingRect(ui->nameText + " - " + plain).width() < ui->name->width())
ui->name->setText(red(ui->nameText + " - ", ui->invalid) + ui->status);
else
ui->name->setText((ui->invalid ? red(ui->nameText) : ui->nameText) + "<br/>" + ui->status);
ui->name->setText(QStringLiteral("%1<br />%2").arg(red(ui->nameText, ui->invalid), ui->status));
ui->name->setAccessibleName(QStringLiteral("%1. %2 %3").arg(plain, ui->role->text(), ui->idSignTime->text()));
ui->role->setText(ui->role->fontMetrics().elidedText(
ui->roleText, Qt::ElideRight, ui->role->width() - 10, Qt::TextShowMnemonic));
Expand Down
2 changes: 1 addition & 1 deletion client/widgets/SignatureItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public slots:

private:
void init();
QString red(const QString &text);
QString red(const QString &text, bool paint = true) const;
void removeSignature();
void updateNameField();

Expand Down

0 comments on commit 323fd86

Please sign in to comment.