From 9fa969cbb1cbe1de3cd5f78c33a8278c067443a5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 26 Aug 2023 09:51:55 +0300 Subject: [PATCH] Guard font size to prevent a warning show. --- src/app/puzzle/dialogs/vpdialogabout.cpp | 2 +- src/app/puzzle/scene/vpgraphicspiece.cpp | 3 ++- src/app/tape/dialogs/dialogabouttape.cpp | 2 +- .../dialogs/configpages/preferencespatternpage.cpp | 2 +- src/app/valentina/dialogs/dialogaboutapp.cpp | 2 +- src/app/valentina/mainwindow.cpp | 6 +++--- src/libs/vhpgl/vhpglengine.cpp | 2 +- src/libs/vlayout/vlayoutpiece.cpp | 2 +- src/libs/vlayout/vtextmanager.cpp | 8 ++++---- src/libs/vtools/dialogs/support/dialogeditlabel.cpp | 6 +++--- src/libs/vtools/tools/vtoolseamallowance.cpp | 2 +- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 4 ++-- src/libs/vwidgets/vtextgraphicsitem.cpp | 2 +- 13 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/app/puzzle/dialogs/vpdialogabout.cpp b/src/app/puzzle/dialogs/vpdialogabout.cpp index 71f65ba89..2f3f48bfa 100644 --- a/src/app/puzzle/dialogs/vpdialogabout.cpp +++ b/src/app/puzzle/dialogs/vpdialogabout.cpp @@ -125,7 +125,7 @@ void VPDialogAbout::FontPointSize(QWidget *w, int pointSize) SCASSERT(w != nullptr) QFont font = w->font(); - font.setPointSize(pointSize); + font.setPointSize(qMax(pointSize, 1)); w->setFont(font); } diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index fcb84f138..3d7f9a0fb 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -53,6 +53,7 @@ #include "../vmisc/theme/vscenestylesheet.h" #include "../vpapplication.h" #include "compatibility.h" +#include "qminmax.h" #include "undocommands/vpundomovepieceonsheet.h" #include "undocommands/vpundopiecemove.h" #include "vpiecegrainline.h" @@ -102,7 +103,7 @@ inline auto LineMatrix(const VPPiecePtr &piece, const QPointF &topLeft, qreal an inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont { QFont fnt = base; - fnt.setPointSize(base.pointSize() + tl.m_iFontSize); + fnt.setPointSize(qMax(base.pointSize() + tl.m_iFontSize, 1)); fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic); return fnt; diff --git a/src/app/tape/dialogs/dialogabouttape.cpp b/src/app/tape/dialogs/dialogabouttape.cpp index 72a2dc9fa..267c8ebf1 100644 --- a/src/app/tape/dialogs/dialogabouttape.cpp +++ b/src/app/tape/dialogs/dialogabouttape.cpp @@ -126,7 +126,7 @@ void DialogAboutTape::FontPointSize(QWidget *w, int pointSize) SCASSERT(w != nullptr) QFont font = w->font(); - font.setPointSize(pointSize); + font.setPointSize(qMax(pointSize, 1)); w->setFont(font); } diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp index 231d1d910..b6a993fbc 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -125,7 +125,7 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) QFont labelFont = settings->GetLabelFont(); int pointSize = settings->GetPieceLabelFontPointSize(); - labelFont.setPointSize(pointSize); + labelFont.setPointSize(qMax(pointSize, 1)); ui->fontComboBoxLabelFont->setCurrentFont(labelFont); diff --git a/src/app/valentina/dialogs/dialogaboutapp.cpp b/src/app/valentina/dialogs/dialogaboutapp.cpp index ddcd00b8f..9a14ff4e8 100644 --- a/src/app/valentina/dialogs/dialogaboutapp.cpp +++ b/src/app/valentina/dialogs/dialogaboutapp.cpp @@ -123,6 +123,6 @@ void DialogAboutApp::FontPointSize(QWidget *w, int pointSize) SCASSERT(w != nullptr) QFont font = w->font(); - font.setPointSize(pointSize); + font.setPointSize(qMax(pointSize, 1)); w->setFont(font); } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 39f0c31ad..afb3f53c5 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -454,7 +454,7 @@ MainWindow::MainWindow(QWidget *parent) QFont f = ui->plainTextEditPatternMessages->font(); if (f.pointSize() < VValentinaSettings::GetDefMaxPatternMessageFontSize()) { - f.setPointSize(f.pointSize() + 1); + f.setPointSize(qMax(f.pointSize() + 1, 1)); ui->plainTextEditPatternMessages->setFont(f); settings->SetPatternMessageFontSize(f.pointSize()); } @@ -467,7 +467,7 @@ MainWindow::MainWindow(QWidget *parent) QFont f = ui->plainTextEditPatternMessages->font(); if (f.pointSize() > VValentinaSettings::GetDefMinPatternMessageFontSize()) { - f.setPointSize(f.pointSize() - 1); + f.setPointSize(qMax(f.pointSize() - 1, 1)); ui->plainTextEditPatternMessages->setFont(f); settings->SetPatternMessageFontSize(f.pointSize()); } @@ -5506,7 +5506,7 @@ void MainWindow::ReadSettings() ToolboxIconSize(); QFont f = ui->plainTextEditPatternMessages->font(); - f.setPointSize(settings->GetPatternMessageFontSize(f.pointSize())); + f.setPointSize(qMax(settings->GetPatternMessageFontSize(f.pointSize()), 1)); ui->plainTextEditPatternMessages->setFont(f); } else diff --git a/src/libs/vhpgl/vhpglengine.cpp b/src/libs/vhpgl/vhpglengine.cpp index ae722c49a..775d01ab6 100644 --- a/src/libs/vhpgl/vhpglengine.cpp +++ b/src/libs/vhpgl/vhpglengine.cpp @@ -191,7 +191,7 @@ auto LineFont(const TextLine &tl, const VSvgFont &base) -> VSvgFont inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont { QFont fnt = base; - fnt.setPointSize(base.pointSize() + tl.m_iFontSize); + fnt.setPointSize(qMax(base.pointSize() + tl.m_iFontSize, 1)); fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic); return fnt; diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index c6ee8483b..b0f2dfb29 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1677,7 +1677,7 @@ void VLayoutPiece::LabelStringsOutlineFont(QGraphicsItem *parent, const QVector< for (const auto &tl : labelLines) { QFont fnt = tm.GetFont(); - fnt.setPointSize(tm.GetFont().pointSize() + tl.m_iFontSize); + fnt.setPointSize(qMax(tm.GetFont().pointSize() + tl.m_iFontSize, 1)); fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic); diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index ae1637ee2..4ef60c91b 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -610,8 +610,8 @@ auto VTextManager::GetSVGFontPointSize() const -> int void VTextManager::SetFontSize(int iFS) { iFS < VCommonSettings::MinPieceLabelFontPointSize() - ? m_font.setPointSize(VCommonSettings::MinPieceLabelFontPointSize()) - : m_font.setPointSize(iFS); + ? m_font.setPointSize(qMax(VCommonSettings::MinPieceLabelFontPointSize(), 1)) + : m_font.setPointSize(qMax(iFS, 1)); } //--------------------------------------------------------------------------------------------------------------------- @@ -659,7 +659,7 @@ auto VTextManager::GetLabelSourceLines(int width, const QFont &font) const -> QV for (const auto &tl : m_liLines) { - fnt.setPointSize(fSize + tl.m_iFontSize); + fnt.setPointSize(qMax(fSize + tl.m_iFontSize, 1)); fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic); @@ -740,7 +740,7 @@ auto VTextManager::MaxLineWidthOutlineFont(int width) const -> int const TextLine &tl = m_liLines.at(i); QFont fnt = m_font; - fnt.setPointSize(fnt.pointSize() + tl.m_iFontSize); + fnt.setPointSize(qMax(fnt.pointSize() + tl.m_iFontSize, 1)); fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic); diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index be70dbef5..eebcd7909 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -413,7 +413,7 @@ void DialogEditLabel::SaveAdditionalFontSize(int i) if (curLine) { QFont lineFont = curLine->font(); - lineFont.setPointSize(lineFont.pointSize() - curLine->data(Qt::UserRole).toInt() + i); + lineFont.setPointSize(qMax(lineFont.pointSize() - curLine->data(Qt::UserRole).toInt() + i, 1)); curLine->setFont(lineFont); curLine->setData(Qt::UserRole, i); } @@ -771,7 +771,7 @@ void DialogEditLabel::SetTemplate(const QVector &lines) QFont font = item->font(); font.setBold(line.bold); font.setItalic(line.italic); - font.setPointSize(font.pointSize() + line.fontSizeIncrement); + font.setPointSize(qMax(font.pointSize() + line.fontSizeIncrement, 1)); item->setFont(font); ui->listWidgetEdit->insertItem(++row, item); @@ -853,7 +853,7 @@ void DialogEditLabel::InitPreviewLines(const QVector &lines) QFont font = item->font(); font.setBold(line.bold); font.setItalic(line.italic); - font.setPointSize(font.pointSize() + line.fontSizeIncrement); + font.setPointSize(qMax(font.pointSize() + line.fontSizeIncrement, 1)); item->setFont(font); ui->listWidgetPreview->insertItem(++row, item); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 759e041cb..438a42c5b 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -2127,7 +2127,7 @@ auto VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, co const int iFS = labelData.GetFontSize() < VCommonSettings::MinPieceLabelFontPointSize() ? settings->GetPieceLabelFontPointSize() : labelData.GetFontSize(); - fnt.setPointSize(iFS); + fnt.setPointSize(qMax(iFS, 1)); labelItem->SetSVGFontPointSize(iFS); } labelItem->SetFont(fnt); diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 38d16c6c4..c2fc6858a 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -93,7 +93,7 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic QFont font = this->font(); if (font.pointSize() != VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize()) { - font.setPointSize(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize()); + font.setPointSize(qMax(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize(), 1)); setFont(font); } @@ -360,7 +360,7 @@ void VGraphicsSimpleTextItem::Init() this->setFlag(QGraphicsItem::ItemIsFocusable, true); // For keyboard input focus this->setAcceptHoverEvents(true); QFont font = this->font(); - font.setPointSize(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize()); + font.setPointSize(qMax(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize(), 1)); setFont(font); m_oldScale = minVisibleFontSize / VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize(); setScale(m_oldScale); diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index cc6b88671..485b1865c 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -766,7 +766,7 @@ void VTextGraphicsItem::PaintLabelOutlineFont(QPainter *painter) for (const auto &tl : labelLines) { - fnt.setPointSize(m_tm.GetFont().pointSize() + tl.m_iFontSize); + fnt.setPointSize(qMax(m_tm.GetFont().pointSize() + tl.m_iFontSize, 1)); fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic);