Skip to content

Commit

Permalink
Add Pref Font Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Feb 27, 2018
1 parent 29864ff commit df5a986
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 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
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
82 changes: 82 additions & 0 deletions src/Tools/plugins/widget/plugin.cpp
Expand Up @@ -1372,6 +1372,87 @@ class PrefDoubleSpinBoxPlugin : public QDesignerCustomWidgetInterface
}
};


/* XPM */
static const char *fontbox_pixmap[]={
"22 22 6 1",
"a c #000000",
"# c #000080",
"b c #008080",
"c c #808080",
"d c #c0c0c0",
". c #ffffff",
"...#aaaaaaaaaaaaaa#...",
".baccccccccccccccccab.",
".acccddddddddddddddca.",
"#ccd.................a",
"acc..................a",
"acd..................a",
"acd..................a",
"acd. ................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"acd..................a",
"#cd..................#",
".ac................da.",
".badd............dda#.",
"...#aaaaaaaaaaaaaa#..."};

class PrefFontBoxPlugin : public QDesignerCustomWidgetInterface
{
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
PrefFontBoxPlugin()
{
}
QWidget *createWidget(QWidget *parent)
{
return new Gui::PrefFontBox(parent);
}
QString group() const
{
return QLatin1String("Preference Widgets");
}
QIcon icon() const
{
return QIcon( QPixmap( fontbox_pixmap ) );
}
QString includeFile() const
{
return QLatin1String("Gui/PrefWidgets.h");
}
QString toolTip() const
{
return QLatin1String("Font Box");
}
QString whatsThis() const
{
return QLatin1String("Font box widget (spin button).");
}
bool isContainer() const
{
return false;
}
QString domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"Gui::PrefFontBox\" name=\"fontBox\">\n"
" </widget>\n"
"</ui>";
}
QString name() const
{
return QLatin1String("Gui::PrefFontBox");
}
};

/* XPM */
/*
static char *listbox_pixmap[]={
Expand Down Expand Up @@ -1432,6 +1513,7 @@ QList<QDesignerCustomWidgetInterface *> CustomWidgetPlugin::customWidgets () con
cw.append(new PrefComboBoxPlugin);
cw.append(new PrefLineEditPlugin);
cw.append(new PrefDoubleSpinBoxPlugin);
cw.append(new PrefFontBoxPlugin);
return cw;
}

Expand Down

3 comments on commit df5a986

@normandc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much thanks for adding this, it will make font selection much easier. Not relevant to the commit, but do you think you could add the same thing to the Draft ShapeString settings as well? And would it be possible to add it to the tool parameters in the Tasks panel?

@WandererFan
Copy link
Contributor Author

@WandererFan WandererFan commented on df5a986 Mar 4, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normandc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When creating a Draft Shapestring, while the command is active there is a succession of entry fields in the Tasks panel. The last one is to pick the path of the font to be used.

Please sign in to comment.