fixed an issue where font style would not be persisted correctly

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent b3692061a5
commit cd4a66f90c
  1. 12
      src/core/UBSettings.cpp
  2. 3
      src/core/UBSettings.h
  3. 16
      src/domain/UBGraphicsTextItemDelegate.cpp

@ -72,6 +72,7 @@ QString UBSettings::undoCommandTransactionName = "UndoTransaction";
const int UBSettings::sDefaultFontPixelSize = 36; const int UBSettings::sDefaultFontPixelSize = 36;
const char *UBSettings::sDefaultFontFamily = "Arial"; const char *UBSettings::sDefaultFontFamily = "Arial";
const char *UBSettings::sDefaultFontStyleName = "Regular";
QString UBSettings::currentFileVersion = "4.8.0"; 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() int UBSettings::fontPixelSize()
{ {
return value("Board/FontPixelSize", sDefaultFontPixelSize).toInt(); return value("Board/FontPixelSize", sDefaultFontPixelSize).toInt();

@ -97,6 +97,8 @@ class UBSettings : public QObject
// Text related // Text related
QString fontFamily(); QString fontFamily();
void setFontFamily(const QString &family); void setFontFamily(const QString &family);
QString fontStyleName();
void setFontStyleName(const QString &family);
int fontPixelSize(); int fontPixelSize();
void setFontPixelSize(int pixelSize); void setFontPixelSize(int pixelSize);
int fontPointSize(); int fontPointSize();
@ -465,6 +467,7 @@ class UBSettings : public QObject
static const int sDefaultFontPixelSize; static const int sDefaultFontPixelSize;
static const char *sDefaultFontFamily; static const char *sDefaultFontFamily;
static const char *sDefaultFontStyleName;
static QSettings* getAppSettings(); static QSettings* getAppSettings();

@ -148,21 +148,25 @@ UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate()
QFont UBGraphicsTextItemDelegate::createDefaultFont() QFont UBGraphicsTextItemDelegate::createDefaultFont()
{ {
QTextCharFormat textFormat; QFont font;
QString fFamily = UBSettings::settings()->fontFamily(); QString fFamily = UBSettings::settings()->fontFamily();
if (!fFamily.isEmpty()) 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(); bool bold = UBSettings::settings()->isBoldFont();
if (bold) if (bold)
textFormat.setFontWeight(QFont::Bold); font.setWeight(QFont::Bold);
bool italic = UBSettings::settings()->isItalicFont(); bool italic = UBSettings::settings()->isItalicFont();
if (italic) if (italic)
textFormat.setFontItalic(true); font.setItalic(true);
QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic);
int pointSize = UBSettings::settings()->fontPointSize(); int pointSize = UBSettings::settings()->fontPointSize();
if (pointSize > 0) { if (pointSize > 0) {
font.setPointSize(pointSize); font.setPointSize(pointSize);
@ -336,6 +340,7 @@ void UBGraphicsTextItemDelegate::pickFont()
QFontDialog fontDialog(static_cast<QGraphicsView*>(UBApplication::boardController->controlView())); QFontDialog fontDialog(static_cast<QGraphicsView*>(UBApplication::boardController->controlView()));
fontDialog.setOption(QFontDialog::DontUseNativeDialog); fontDialog.setOption(QFontDialog::DontUseNativeDialog);
fontDialog.setCurrentFont(delegated()->textCursor().charFormat().font()); fontDialog.setCurrentFont(delegated()->textCursor().charFormat().font());
customize(fontDialog); customize(fontDialog);
@ -343,6 +348,7 @@ void UBGraphicsTextItemDelegate::pickFont()
{ {
QFont selectedFont = fontDialog.selectedFont(); QFont selectedFont = fontDialog.selectedFont();
UBSettings::settings()->setFontFamily(selectedFont.family()); UBSettings::settings()->setFontFamily(selectedFont.family());
UBSettings::settings()->setFontStyleName(selectedFont.styleName());
UBSettings::settings()->setBoldFont(selectedFont.bold()); UBSettings::settings()->setBoldFont(selectedFont.bold());
UBSettings::settings()->setItalicFont(selectedFont.italic()); UBSettings::settings()->setItalicFont(selectedFont.italic());
UBSettings::settings()->setFontPointSize(selectedFont.pointSize()); UBSettings::settings()->setFontPointSize(selectedFont.pointSize());

Loading…
Cancel
Save