From 51f4917c24c3d628ac6ca3aeecd16db7015f16d2 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Thu, 27 Mar 2025 13:11:47 +0100 Subject: [PATCH] Draft: add font name dropdown to preferences (#20400) Fixes #20330. --- .../Resources/ui/preferences-drafttexts.ui | 39 ++++++++++--------- src/Mod/Draft/draftutils/params.py | 26 +++++++++++++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/Mod/Draft/Resources/ui/preferences-drafttexts.ui b/src/Mod/Draft/Resources/ui/preferences-drafttexts.ui index 2191e02e2c..0dfb1dfcfc 100644 --- a/src/Mod/Draft/Resources/ui/preferences-drafttexts.ui +++ b/src/Mod/Draft/Resources/ui/preferences-drafttexts.ui @@ -75,22 +75,20 @@ in the Annotation scale widget. If the scale is 1:100 the multiplier is 100. - Font name or family + Font name - + + + + 280 + 0 + + - The default font for texts, dimensions and labels. It can be a font name such -as "Arial", a style such as "sans", "serif" or "mono", or a family such as -"Arial,Helvetica,sans", or a name with a style such as "Arial:Bold". - - - - - - Internal font + The default font for texts, dimensions and labels textfont @@ -100,6 +98,13 @@ as "Arial", a style such as "sans", "serif" or &qu + + + + Qt::Horizontal + + + @@ -138,13 +143,6 @@ as "Arial", a style such as "sans", "serif" or &qu - - - - Qt::Horizontal - - - @@ -695,6 +693,11 @@ used for linear dimensions. QComboBox
Gui/PrefWidgets.h
+ + Gui::PrefFontBox + QFontComboBox +
Gui/PrefWidgets.h
+
Gui::PrefSpinBox QSpinBox diff --git a/src/Mod/Draft/draftutils/params.py b/src/Mod/Draft/draftutils/params.py index 70d86a19fb..a08f2bec32 100644 --- a/src/Mod/Draft/draftutils/params.py +++ b/src/Mod/Draft/draftutils/params.py @@ -367,6 +367,29 @@ def _param_from_PrefFileChooser(widget): return path, entry, "" +def _param_from_PrefFontBox(widget): + if App.GuiUp: + from PySide import QtGui + font = QtGui.QFont() + font.setStyleHint(QtGui.QFont.StyleHint.SansSerif) + value = font.defaultFamily() + else: + value = "" + for elem in list(widget): + if "name" in elem.keys(): + att_name = elem.attrib["name"] + if att_name == "prefEntry": + entry = elem.find("cstring").text + elif att_name == "prefPath": + path = elem.find("cstring").text + # We must set the parameter if it does not exist, else + # the Gui::PrefFontBox will show the wrong value. + param_grp = App.ParamGet("User parameter:BaseApp/Preferences/" + path) + if entry not in param_grp.GetStrings(): + param_grp.SetString(entry, value) + return path, entry, value + + def _get_param_dictionary(): # print("Creating preferences dictionary...") @@ -595,6 +618,9 @@ def _get_param_dictionary(): elif att_class == "Gui::PrefFileChooser": path, entry, value = _param_from_PrefFileChooser(widget) typ = "string" + elif att_class == "Gui::PrefFontBox": + path, entry, value = _param_from_PrefFontBox(widget) + typ = "string" if path is not None: if path in param_dict: