Skip to content

Commit

Permalink
Merge pull request #1335 from WandererFan/Fixes
Browse files Browse the repository at this point in the history
Use Font Selector Widget for Preferences
  • Loading branch information
yorikvanhavre committed Feb 28, 2018
2 parents 29864ff + 1700f36 commit bf6917a
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 49 deletions.
41 changes: 41 additions & 0 deletions src/Gui/PrefWidgets.cpp
Expand Up @@ -640,4 +640,45 @@ void PrefQuantitySpinBox::setHistorySize(int i)
d->historySize = i;
}

// --------------------------------------------------------------------

PrefFontBox::PrefFontBox ( QWidget * parent )
: QFontComboBox(parent), PrefWidget()
{
}

PrefFontBox::~PrefFontBox()
{
}

void PrefFontBox::restorePreferences()
{
if ( getWindowParameter().isNull() )
{
Console().Warning("Cannot restore!\n");
return;
}

QFont currFont = currentFont(); //QFont from selector widget
QString currName = currFont.family();

std::string prefName = getWindowParameter()->GetASCII(entryName(), currName.toUtf8()); //font name from cfg file

currFont.setFamily(QString::fromStdString(prefName));
setCurrentFont(currFont); //set selector widget to name from cfg file
}

void PrefFontBox::savePreferences()
{
if (getWindowParameter().isNull())
{
Console().Warning("Cannot save!\n");
return;
}

QFont currFont = currentFont();
QString currName = currFont.family();
getWindowParameter()->SetASCII( entryName() , currName.toUtf8() );
}

#include "moc_PrefWidgets.cpp"
22 changes: 22 additions & 0 deletions src/Gui/PrefWidgets.h
Expand Up @@ -27,6 +27,8 @@
#include <QCheckBox>
#include <QComboBox>
#include <QRadioButton>
#include <QFontComboBox>
#include <QFont>
#include <Base/Parameter.h>
#include "Widgets.h"
#include "Window.h"
Expand Down Expand Up @@ -322,6 +324,26 @@ class GuiExport PrefQuantitySpinBox : public QuantitySpinBox
Q_DECLARE_PRIVATE(PrefQuantitySpinBox)
};

/** The PrefFontBox class.
* \author wandererfan
*/
class GuiExport PrefFontBox : public QFontComboBox, public PrefWidget
{
Q_OBJECT

Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )

public:
PrefFontBox ( QWidget * parent = 0 );
virtual ~PrefFontBox();

protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};

} // namespace Gui

#endif // GUI_PREFWIDGETS_H
130 changes: 83 additions & 47 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui
Expand Up @@ -159,29 +159,6 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_TemplateDot">
<property name="text">
<string>Template Dot Size</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="Gui::PrefDoubleSpinBox" name="dsb_TemplateDot">
<property name="toolTip">
<string>EditableText Dot Size in mm</string>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>TemplateDotSize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -603,7 +580,23 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0">
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,0,0" columnstretch="0,0,0">
<item row="0" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="Gui::PrefDoubleSpinBox" name="dsb_LabelSize">
<property name="toolTip">
Expand All @@ -623,49 +616,87 @@
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_LabelFont">
<property name="text">
<string>Label Font</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::PrefLineEdit" name="le_LabelFont">
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>osifont</string>
<string>Label Size</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::PrefFontBox" name="pfb_LabelFont">
<property name="toolTip">
<string>Font for View Labels</string>
</property>
<property name="currentFont">
<font>
<family>osifont</family>
</font>
</property>
<property name="prefEntry" stdset="0">
<cstring>LabelFont</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Labels</cstring>
<cstring>/Mod/TechDraw/Labels</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<item row="2" column="0">
<widget class="QLabel" name="lbl_TemplateDot">
<property name="text">
<string>Label Size</string>
<string>Template Dot Size</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="Gui::PrefDoubleSpinBox" name="dsb_TemplateDot">
<property name="toolTip">
<string>EditableText Dot Size in mm</string>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>TemplateDotSize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -740,6 +771,11 @@
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefFontBox</class>
<extends>QFontComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp
Expand Up @@ -58,7 +58,7 @@ void DlgPrefsTechDrawImp::saveSettings()
pcb_Background->onSave();
pcb_Hatch->onSave();

le_LabelFont->onSave();
pfb_LabelFont->onSave();
dsb_LabelSize->onSave();

pfc_DefTemp->onSave();
Expand All @@ -85,7 +85,7 @@ void DlgPrefsTechDrawImp::loadSettings()
pcb_Background->onRestore();
pcb_Hatch->onRestore();

le_LabelFont->onRestore();
pfb_LabelFont->onRestore();
dsb_LabelSize->onRestore();

pfc_DefTemp->onRestore();
Expand Down
32 changes: 32 additions & 0 deletions src/Tools/plugins/widget/customwidgets.cpp
Expand Up @@ -1224,3 +1224,35 @@ void PrefSlider::setParamGrpPath ( const QByteArray& name )
{
m_sPrefGrp = name;
}

// --------------------------------------------------------------------

PrefFontBox::PrefFontBox ( QWidget * parent )
: QFontComboBox(parent)
{
}

PrefFontBox::~PrefFontBox()
{
}

QByteArray PrefFontBox::entryName () const
{
return m_sPrefName;
}

QByteArray PrefFontBox::paramGrpPath () const
{
return m_sPrefGrp;
}

void PrefFontBox::setEntryName ( const QByteArray& name )
{
m_sPrefName = name;
}

void PrefFontBox::setParamGrpPath ( const QByteArray& name )
{
m_sPrefGrp = name;
}

23 changes: 23 additions & 0 deletions src/Tools/plugins/widget/customwidgets.h
Expand Up @@ -38,6 +38,7 @@
#include <QGroupBox>
#include <QGridLayout>
#include <QTreeWidget>
#include <QFontComboBox>

namespace Base {
class Quantity{};
Expand Down Expand Up @@ -581,6 +582,28 @@ class PrefSlider : public QSlider
QByteArray m_sPrefGrp;
};

// ------------------------------------------------------------------------------

class PrefFontBox : public QFontComboBox
{
Q_OBJECT

Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )

public:
PrefFontBox ( QWidget * parent = 0 );
virtual ~PrefFontBox();

QByteArray entryName () const;
QByteArray paramGrpPath () const;
void setEntryName ( const QByteArray& name );
void setParamGrpPath ( const QByteArray& name );

private:
QByteArray m_sPrefName;
QByteArray m_sPrefGrp;
};
} // namespace Gui

#endif // GUI_CUSTOMWIDGETS_H

0 comments on commit bf6917a

Please sign in to comment.