Guard font size to prevent a warning show.

This commit is contained in:
Roman Telezhynskyi 2023-08-26 09:51:55 +03:00
parent e2c6fe5124
commit 9fa969cbb1
13 changed files with 22 additions and 21 deletions

View File

@ -125,7 +125,7 @@ void VPDialogAbout::FontPointSize(QWidget *w, int pointSize)
SCASSERT(w != nullptr) SCASSERT(w != nullptr)
QFont font = w->font(); QFont font = w->font();
font.setPointSize(pointSize); font.setPointSize(qMax(pointSize, 1));
w->setFont(font); w->setFont(font);
} }

View File

@ -53,6 +53,7 @@
#include "../vmisc/theme/vscenestylesheet.h" #include "../vmisc/theme/vscenestylesheet.h"
#include "../vpapplication.h" #include "../vpapplication.h"
#include "compatibility.h" #include "compatibility.h"
#include "qminmax.h"
#include "undocommands/vpundomovepieceonsheet.h" #include "undocommands/vpundomovepieceonsheet.h"
#include "undocommands/vpundopiecemove.h" #include "undocommands/vpundopiecemove.h"
#include "vpiecegrainline.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 inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont
{ {
QFont fnt = base; 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.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);
return fnt; return fnt;

View File

@ -126,7 +126,7 @@ void DialogAboutTape::FontPointSize(QWidget *w, int pointSize)
SCASSERT(w != nullptr) SCASSERT(w != nullptr)
QFont font = w->font(); QFont font = w->font();
font.setPointSize(pointSize); font.setPointSize(qMax(pointSize, 1));
w->setFont(font); w->setFont(font);
} }

View File

@ -125,7 +125,7 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
QFont labelFont = settings->GetLabelFont(); QFont labelFont = settings->GetLabelFont();
int pointSize = settings->GetPieceLabelFontPointSize(); int pointSize = settings->GetPieceLabelFontPointSize();
labelFont.setPointSize(pointSize); labelFont.setPointSize(qMax(pointSize, 1));
ui->fontComboBoxLabelFont->setCurrentFont(labelFont); ui->fontComboBoxLabelFont->setCurrentFont(labelFont);

View File

@ -123,6 +123,6 @@ void DialogAboutApp::FontPointSize(QWidget *w, int pointSize)
SCASSERT(w != nullptr) SCASSERT(w != nullptr)
QFont font = w->font(); QFont font = w->font();
font.setPointSize(pointSize); font.setPointSize(qMax(pointSize, 1));
w->setFont(font); w->setFont(font);
} }

View File

@ -454,7 +454,7 @@ MainWindow::MainWindow(QWidget *parent)
QFont f = ui->plainTextEditPatternMessages->font(); QFont f = ui->plainTextEditPatternMessages->font();
if (f.pointSize() < VValentinaSettings::GetDefMaxPatternMessageFontSize()) if (f.pointSize() < VValentinaSettings::GetDefMaxPatternMessageFontSize())
{ {
f.setPointSize(f.pointSize() + 1); f.setPointSize(qMax(f.pointSize() + 1, 1));
ui->plainTextEditPatternMessages->setFont(f); ui->plainTextEditPatternMessages->setFont(f);
settings->SetPatternMessageFontSize(f.pointSize()); settings->SetPatternMessageFontSize(f.pointSize());
} }
@ -467,7 +467,7 @@ MainWindow::MainWindow(QWidget *parent)
QFont f = ui->plainTextEditPatternMessages->font(); QFont f = ui->plainTextEditPatternMessages->font();
if (f.pointSize() > VValentinaSettings::GetDefMinPatternMessageFontSize()) if (f.pointSize() > VValentinaSettings::GetDefMinPatternMessageFontSize())
{ {
f.setPointSize(f.pointSize() - 1); f.setPointSize(qMax(f.pointSize() - 1, 1));
ui->plainTextEditPatternMessages->setFont(f); ui->plainTextEditPatternMessages->setFont(f);
settings->SetPatternMessageFontSize(f.pointSize()); settings->SetPatternMessageFontSize(f.pointSize());
} }
@ -5506,7 +5506,7 @@ void MainWindow::ReadSettings()
ToolboxIconSize(); ToolboxIconSize();
QFont f = ui->plainTextEditPatternMessages->font(); QFont f = ui->plainTextEditPatternMessages->font();
f.setPointSize(settings->GetPatternMessageFontSize(f.pointSize())); f.setPointSize(qMax(settings->GetPatternMessageFontSize(f.pointSize()), 1));
ui->plainTextEditPatternMessages->setFont(f); ui->plainTextEditPatternMessages->setFont(f);
} }
else else

View File

@ -191,7 +191,7 @@ auto LineFont(const TextLine &tl, const VSvgFont &base) -> VSvgFont
inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont
{ {
QFont fnt = base; 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.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);
return fnt; return fnt;

View File

@ -1677,7 +1677,7 @@ void VLayoutPiece::LabelStringsOutlineFont(QGraphicsItem *parent, const QVector<
for (const auto &tl : labelLines) for (const auto &tl : labelLines)
{ {
QFont fnt = tm.GetFont(); 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.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);

View File

@ -610,8 +610,8 @@ auto VTextManager::GetSVGFontPointSize() const -> int
void VTextManager::SetFontSize(int iFS) void VTextManager::SetFontSize(int iFS)
{ {
iFS < VCommonSettings::MinPieceLabelFontPointSize() iFS < VCommonSettings::MinPieceLabelFontPointSize()
? m_font.setPointSize(VCommonSettings::MinPieceLabelFontPointSize()) ? m_font.setPointSize(qMax(VCommonSettings::MinPieceLabelFontPointSize(), 1))
: m_font.setPointSize(iFS); : 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) 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.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);
@ -740,7 +740,7 @@ auto VTextManager::MaxLineWidthOutlineFont(int width) const -> int
const TextLine &tl = m_liLines.at(i); const TextLine &tl = m_liLines.at(i);
QFont fnt = m_font; 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.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);

View File

@ -413,7 +413,7 @@ void DialogEditLabel::SaveAdditionalFontSize(int i)
if (curLine) if (curLine)
{ {
QFont lineFont = curLine->font(); 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->setFont(lineFont);
curLine->setData(Qt::UserRole, i); curLine->setData(Qt::UserRole, i);
} }
@ -771,7 +771,7 @@ void DialogEditLabel::SetTemplate(const QVector<VLabelTemplateLine> &lines)
QFont font = item->font(); QFont font = item->font();
font.setBold(line.bold); font.setBold(line.bold);
font.setItalic(line.italic); font.setItalic(line.italic);
font.setPointSize(font.pointSize() + line.fontSizeIncrement); font.setPointSize(qMax(font.pointSize() + line.fontSizeIncrement, 1));
item->setFont(font); item->setFont(font);
ui->listWidgetEdit->insertItem(++row, item); ui->listWidgetEdit->insertItem(++row, item);
@ -853,7 +853,7 @@ void DialogEditLabel::InitPreviewLines(const QVector<VLabelTemplateLine> &lines)
QFont font = item->font(); QFont font = item->font();
font.setBold(line.bold); font.setBold(line.bold);
font.setItalic(line.italic); font.setItalic(line.italic);
font.setPointSize(font.pointSize() + line.fontSizeIncrement); font.setPointSize(qMax(font.pointSize() + line.fontSizeIncrement, 1));
item->setFont(font); item->setFont(font);
ui->listWidgetPreview->insertItem(++row, item); ui->listWidgetPreview->insertItem(++row, item);

View File

@ -2127,7 +2127,7 @@ auto VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, co
const int iFS = labelData.GetFontSize() < VCommonSettings::MinPieceLabelFontPointSize() const int iFS = labelData.GetFontSize() < VCommonSettings::MinPieceLabelFontPointSize()
? settings->GetPieceLabelFontPointSize() ? settings->GetPieceLabelFontPointSize()
: labelData.GetFontSize(); : labelData.GetFontSize();
fnt.setPointSize(iFS); fnt.setPointSize(qMax(iFS, 1));
labelItem->SetSVGFontPointSize(iFS); labelItem->SetSVGFontPointSize(iFS);
} }
labelItem->SetFont(fnt); labelItem->SetFont(fnt);

View File

@ -93,7 +93,7 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic
QFont font = this->font(); QFont font = this->font();
if (font.pointSize() != VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize()) if (font.pointSize() != VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize())
{ {
font.setPointSize(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize()); font.setPointSize(qMax(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize(), 1));
setFont(font); setFont(font);
} }
@ -360,7 +360,7 @@ void VGraphicsSimpleTextItem::Init()
this->setFlag(QGraphicsItem::ItemIsFocusable, true); // For keyboard input focus this->setFlag(QGraphicsItem::ItemIsFocusable, true); // For keyboard input focus
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
QFont font = this->font(); QFont font = this->font();
font.setPointSize(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize()); font.setPointSize(qMax(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize(), 1));
setFont(font); setFont(font);
m_oldScale = minVisibleFontSize / VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize(); m_oldScale = minVisibleFontSize / VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize();
setScale(m_oldScale); setScale(m_oldScale);

View File

@ -766,7 +766,7 @@ void VTextGraphicsItem::PaintLabelOutlineFont(QPainter *painter)
for (const auto &tl : labelLines) 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.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);