fixed an issue where font style would not be persisted correctly

preferencesAboutTextFull
Clément Fauconnier 4 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 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();

@ -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();

@ -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<QGraphicsView*>(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());

Loading…
Cancel
Save