From f3329fb1304214c5345f9010d3e8fbfa4433717d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 7 Jul 2024 16:42:55 +0300 Subject: [PATCH] Calculate image size according to screen scale factor. --- src/app/valentina/mainwindow.cpp | 2 +- src/libs/vtools/dialogs/dialogtoolbox.cpp | 13 +++++-- src/libs/vtools/dialogs/dialogtoolbox.h | 2 +- .../dialogs/tools/piece/dialogpiecepath.cpp | 21 +++++------ .../tools/piece/dialogseamallowance.cpp | 36 +++++++++++-------- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b521511fe..49ce05800 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -7890,7 +7890,7 @@ void MainWindow::PrintPatternMessage(QEvent *event) ui->plainTextEditPatternMessages->appendPlainText(message); if (not m_unreadPatternMessage.isNull()) { - m_unreadPatternMessage->setText(DialogWarningIcon() + tr("Pattern messages")); + m_unreadPatternMessage->setText(DialogWarningIcon(m_unreadPatternMessage) + tr("Pattern messages")); } } diff --git a/src/libs/vtools/dialogs/dialogtoolbox.cpp b/src/libs/vtools/dialogs/dialogtoolbox.cpp index b45cb2f08..7f879cc12 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.cpp +++ b/src/libs/vtools/dialogs/dialogtoolbox.cpp @@ -608,11 +608,20 @@ auto EachPointLabelIsUnique(QListWidget *listWidget) -> bool } //--------------------------------------------------------------------------------------------------------------------- -auto DialogWarningIcon() -> QString +auto DialogWarningIcon(QWidget *w) -> QString { const QIcon icon = FromTheme(VThemeIcon::DialogWarning); - const QPixmap pixmap = icon.pixmap(QSize(16, 16)); + qreal scaleFactor = 1; + if (w != nullptr) + { + if (QScreen *wScreen = w->screen()) + { + scaleFactor = wScreen->devicePixelRatio(); + } + } + + const QPixmap pixmap = icon.pixmap(QSize(qRound(16 / scaleFactor), qRound(16 / scaleFactor))); QByteArray byteArray; QBuffer buffer(&byteArray); pixmap.save(&buffer, "PNG"); diff --git a/src/libs/vtools/dialogs/dialogtoolbox.h b/src/libs/vtools/dialogs/dialogtoolbox.h index 77b0102e5..e64132980 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.h +++ b/src/libs/vtools/dialogs/dialogtoolbox.h @@ -92,7 +92,7 @@ auto DoublePoints(QListWidget *listWidget, const VContainer *data, QString &erro auto DoubleCurves(QListWidget *listWidget, const VContainer *data, QString &error) -> bool; auto EachPointLabelIsUnique(QListWidget *listWidget) -> bool; auto InvalidSegment(QListWidget *listWidget, const VContainer *data, QString &error) -> bool; -auto DialogWarningIcon() -> QString; +auto DialogWarningIcon(QWidget* w) -> QString; auto NodeFont(QFont font, bool nodeExcluded = false) -> QFont; void CurrentCurveLength(vidtype curveId, VContainer *data); void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar = 4); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp index df6343604..99c2e9cc5 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp @@ -1842,7 +1842,7 @@ auto DialogPiecePath::PathIsValid() const -> bool { if (CreatePath().PathPoints(data).count() < 2) { - ui->helpLabel->setText(DialogWarningIcon() + tr("You need more points!")); + ui->helpLabel->setText(DialogWarningIcon(ui->helpLabel) + tr("You need more points!")); return false; } @@ -1850,8 +1850,8 @@ auto DialogPiecePath::PathIsValid() const -> bool if (GetType() == PiecePathType::CustomSeamAllowance && FirstPointEqualLast(ui->listWidget, data, error)) { ui->helpLabel->setText(QStringLiteral("%1%2 %3").arg( - DialogWarningIcon(), tr("First point of custom seam allowance cannot be equal to the last point!"), - error)); + DialogWarningIcon(ui->helpLabel), + tr("First point of custom seam allowance cannot be equal to the last point!"), error)); return false; } @@ -1859,41 +1859,42 @@ auto DialogPiecePath::PathIsValid() const -> bool if (DoublePoints(ui->listWidget, data, error)) { ui->helpLabel->setText( - QStringLiteral("%1%2 %3").arg(DialogWarningIcon(), tr("You have double points!"), error)); + QStringLiteral("%1%2 %3").arg(DialogWarningIcon(ui->helpLabel), tr("You have double points!"), error)); return false; } error.clear(); if (DoubleCurves(ui->listWidget, data, error)) { - ui->helpLabel->setText( - QStringLiteral("%1%2 %3").arg(DialogWarningIcon(), tr("The same curve repeats twice!"), error)); + ui->helpLabel->setText(QStringLiteral("%1%2 %3").arg(DialogWarningIcon(ui->helpLabel), + tr("The same curve repeats twice!"), error)); return false; } if (GetType() == PiecePathType::CustomSeamAllowance && not EachPointLabelIsUnique(ui->listWidget)) { - ui->helpLabel->setText(DialogWarningIcon() + + ui->helpLabel->setText(DialogWarningIcon(ui->helpLabel) + tr("Each point in the custom seam allowance path must be unique!")); return false; } if (not m_showMode && ui->comboBoxPiece->count() <= 0) { - ui->helpLabel->setText(DialogWarningIcon() + tr("List of details is empty!")); + ui->helpLabel->setText(DialogWarningIcon(ui->helpLabel) + tr("List of details is empty!")); return false; } if (not m_showMode && ui->comboBoxPiece->currentIndex() == -1) { - ui->helpLabel->setText(DialogWarningIcon() + tr("Please, select a detail to insert into!")); + ui->helpLabel->setText(DialogWarningIcon(ui->helpLabel) + tr("Please, select a detail to insert into!")); return false; } error.clear(); if (InvalidSegment(ui->listWidget, data, error)) { - ui->helpLabel->setText(QStringLiteral("%1%2 %3").arg(DialogWarningIcon(), tr("Invalid segment!"), error)); + ui->helpLabel->setText( + QStringLiteral("%1%2 %3").arg(DialogWarningIcon(ui->helpLabel), tr("Invalid segment!"), error)); return false; } diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index c5d300d1e..86b3cc8a2 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -3388,13 +3388,14 @@ auto DialogSeamAllowance::MainPathIsValid() const -> bool { if (CreatePiece().MainPathPoints(data).count() < 3) { - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("You need more points!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + tr("You need more points!")); return false; } if (not MainPathIsClockwise()) { - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("You have to choose points in a clockwise direction!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + + tr("You have to choose points in a clockwise direction!")); return false; } @@ -3402,29 +3403,30 @@ auto DialogSeamAllowance::MainPathIsValid() const -> bool if (FirstPointEqualLast(uiTabPaths->listWidgetMainPath, data, error)) { uiTabPaths->helpLabel->setText(QStringLiteral("%1%2 %3").arg( - DialogWarningIcon(), tr("First point cannot be equal to the last point!"), error)); + DialogWarningIcon(uiTabPaths->helpLabel), tr("First point cannot be equal to the last point!"), error)); return false; } error.clear(); if (DoublePoints(uiTabPaths->listWidgetMainPath, data, error)) { - uiTabPaths->helpLabel->setText( - QStringLiteral("%1%2 %3").arg(DialogWarningIcon(), tr("You have double points!"), error)); + uiTabPaths->helpLabel->setText(QStringLiteral("%1%2 %3").arg(DialogWarningIcon(uiTabPaths->helpLabel), + tr("You have double points!"), error)); return false; } error.clear(); if (DoubleCurves(uiTabPaths->listWidgetMainPath, data, error)) { - uiTabPaths->helpLabel->setText( - QStringLiteral("%1%2 %3").arg(DialogWarningIcon(), tr("The same curve repeats twice!"), error)); + uiTabPaths->helpLabel->setText(QStringLiteral("%1%2 %3").arg(DialogWarningIcon(uiTabPaths->helpLabel), + tr("The same curve repeats twice!"), error)); return false; } if (not EachPointLabelIsUnique(uiTabPaths->listWidgetMainPath)) { - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Each point in the path must be unique!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + + tr("Each point in the path must be unique!")); return false; } @@ -3432,7 +3434,7 @@ auto DialogSeamAllowance::MainPathIsValid() const -> bool if (InvalidSegment(uiTabPaths->listWidgetMainPath, data, error)) { uiTabPaths->helpLabel->setText( - QStringLiteral("%1%2 %3").arg(DialogWarningIcon(), tr("Invalid segment!"), error)); + QStringLiteral("%1%2 %3").arg(DialogWarningIcon(uiTabPaths->helpLabel), tr("Invalid segment!"), error)); return false; } @@ -3456,14 +3458,15 @@ auto DialogSeamAllowance::MirrorLineIsValid() const -> bool if (startPoint == NULL_ID && endPoint != NULL_ID) { ChangeColor(uiTabPaths->labelMLStartPoint, errorColor); - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Invalid mirror line start point!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + + tr("Invalid mirror line start point!")); return false; } if (startPoint != NULL_ID && endPoint == NULL_ID) { ChangeColor(uiTabPaths->labelMLEndPoint, errorColor); - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Invalid mirror line end point!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + tr("Invalid mirror line end point!")); return false; } @@ -3471,7 +3474,8 @@ auto DialogSeamAllowance::MirrorLineIsValid() const -> bool { ChangeColor(uiTabPaths->labelMLStartPoint, errorColor); ChangeColor(uiTabPaths->labelMLEndPoint, errorColor); - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Start and end mirror line points must be unique!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + + tr("Start and end mirror line points must be unique!")); return false; } @@ -3490,14 +3494,15 @@ auto DialogSeamAllowance::MirrorLineIsValid() const -> bool if (!uniquePoints.contains(startPoint)) { ChangeColor(uiTabPaths->labelMLStartPoint, errorColor); - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Invalid mirror line start point!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + + tr("Invalid mirror line start point!")); return false; } if (!uniquePoints.contains(endPoint)) { ChangeColor(uiTabPaths->labelMLEndPoint, errorColor); - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Invalid mirror line end point!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + tr("Invalid mirror line end point!")); return false; } @@ -3505,7 +3510,8 @@ auto DialogSeamAllowance::MirrorLineIsValid() const -> bool { ChangeColor(uiTabPaths->labelMLStartPoint, errorColor); ChangeColor(uiTabPaths->labelMLEndPoint, errorColor); - uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("Mirror points must be neighbors!")); + uiTabPaths->helpLabel->setText(DialogWarningIcon(uiTabPaths->helpLabel) + + tr("Mirror points must be neighbors!")); return false; }