From cd4a66f90ca0b4f0ff4a71a40363f263db1db0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Mon, 21 Jun 2021 15:44:04 +0200 Subject: [PATCH] fixed an issue where font style would not be persisted correctly --- src/core/UBSettings.cpp | 12 ++++++++++++ src/core/UBSettings.h | 3 +++ src/domain/UBGraphicsTextItemDelegate.cpp | 16 +++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 2e3c5839..e9620107 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -72,6 +72,7 @@ QString UBSettings::undoCommandTransactionName = "UndoTransaction"; const int UBSettings::sDefaultFontPixelSize = 36; const char *UBSettings::sDefaultFontFamily = "Arial"; +const char *UBSettings::sDefaultFontStyleName = "Regular"; QString UBSettings::currentFileVersion = "4.8.0"; @@ -870,6 +871,17 @@ void UBSettings::setFontFamily(const QString &family) } +QString UBSettings::fontStyleName() +{ + return value("Board/FontStyleName", sDefaultFontStyleName).toString(); +} + + +void UBSettings::setFontStyleName(const QString &styleName) +{ + setValue("Board/FontStyleName", styleName); +} + int UBSettings::fontPixelSize() { return value("Board/FontPixelSize", sDefaultFontPixelSize).toInt(); diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 9cba7a10..31575e43 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -97,6 +97,8 @@ class UBSettings : public QObject // Text related QString fontFamily(); void setFontFamily(const QString &family); + QString fontStyleName(); + void setFontStyleName(const QString &family); int fontPixelSize(); void setFontPixelSize(int pixelSize); int fontPointSize(); @@ -465,6 +467,7 @@ class UBSettings : public QObject static const int sDefaultFontPixelSize; static const char *sDefaultFontFamily; + static const char *sDefaultFontStyleName; static QSettings* getAppSettings(); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index a385b3ac..08f705b0 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -148,21 +148,25 @@ UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate() QFont UBGraphicsTextItemDelegate::createDefaultFont() { - QTextCharFormat textFormat; + QFont font; QString fFamily = UBSettings::settings()->fontFamily(); if (!fFamily.isEmpty()) - textFormat.setFontFamily(fFamily); + font.setFamily(fFamily); + + QString fStyleName = UBSettings::settings()->fontStyleName(); + if (!fStyleName .isEmpty()) + font.setStyleName(fStyleName); bool bold = UBSettings::settings()->isBoldFont(); if (bold) - textFormat.setFontWeight(QFont::Bold); + font.setWeight(QFont::Bold); bool italic = UBSettings::settings()->isItalicFont(); if (italic) - textFormat.setFontItalic(true); + font.setItalic(true); + - QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic); int pointSize = UBSettings::settings()->fontPointSize(); if (pointSize > 0) { font.setPointSize(pointSize); @@ -336,6 +340,7 @@ void UBGraphicsTextItemDelegate::pickFont() QFontDialog fontDialog(static_cast(UBApplication::boardController->controlView())); fontDialog.setOption(QFontDialog::DontUseNativeDialog); + fontDialog.setCurrentFont(delegated()->textCursor().charFormat().font()); customize(fontDialog); @@ -343,6 +348,7 @@ void UBGraphicsTextItemDelegate::pickFont() { QFont selectedFont = fontDialog.selectedFont(); UBSettings::settings()->setFontFamily(selectedFont.family()); + UBSettings::settings()->setFontStyleName(selectedFont.styleName()); UBSettings::settings()->setBoldFont(selectedFont.bold()); UBSettings::settings()->setItalicFont(selectedFont.italic()); UBSettings::settings()->setFontPointSize(selectedFont.pointSize());