Skip to content
Permalink
Browse files

Add method to use QgsFontButton in cut down mode for QFont settings only

The button can now be used in two different modes. The default behavior
is to include all settings used for configuring
QgsTextFormat/QgsTextRenderer classes. A cut down mode (without settings
for color/buffer/drop shadow/etc) is also available when the resultant
font is to be used only in a QFont object.
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 5ac9745 commit 99855ea35a8ccb0b7dd685a98fa8b783ceed6416
Showing with 456 additions and 162 deletions.
  1. +50 −0 python/gui/qgsfontbutton.sip
  2. +317 −156 src/gui/qgsfontbutton.cpp
  3. +71 −5 src/gui/qgsfontbutton.h
  4. +18 −1 tests/src/python/test_qgsfontbutton.py
@@ -17,6 +17,12 @@ class QgsFontButton : QToolButton
The button will open a detailed text format settings dialog when clicked. An attached drop down
menu allows for copying and pasting text styles, picking colors for the text, and for dropping
colors from other color widgets.

The button can be used in two different modes(). The default behavior is to include
all settings used for configuring QgsTextFormat/QgsTextRenderer classes. A cut down
mode (without settings for color) is also available when the resultant font is
used only in a QFont object.

.. versionadded:: 3.0
%End

@@ -25,6 +31,13 @@ class QgsFontButton : QToolButton
%End
public:


enum Mode
{
ModeTextRenderer,
ModeQFont,
};

QgsFontButton( QWidget *parent /TransferThis/ = 0, const QString &dialogTitle = QString() );
%Docstring
Construct a new font button.
@@ -34,6 +47,22 @@ class QgsFontButton : QToolButton

virtual QSize sizeHint() const;

QgsFontButton::Mode mode() const;
%Docstring
Returns the current button mode.
.. seealso:: setMode()
:rtype: QgsFontButton.Mode
%End

void setMode( const QgsFontButton::Mode &mode );
%Docstring
Sets the current button ``mode``. This can be used to toggle between
the full capabilities of the button (for configuring QgsTextFormat/QgsTextRenderer objects)
and a cut-back version for configuring QFont object properties (i.e. with
no color settings or the other advanced options QgsTextFormat allows).
.. seealso:: mode()
%End

void setDialogTitle( const QString &title );
%Docstring
Sets the ``title`` for the text settings dialog window.
@@ -64,22 +93,41 @@ class QgsFontButton : QToolButton
QgsTextFormat textFormat() const;
%Docstring
Returns the current text formatting set by the widget.
This is only used when mode() is ModeTextRenderer.
.. seealso:: setTextFormat()
:rtype: QgsTextFormat
%End

QFont currentFont() const;
%Docstring
Returns the current QFont set by the widget.
This is only used when mode() is ModeQFont.
.. seealso:: setCurrentFont()
:rtype: QFont
%End


public slots:

void setTextFormat( const QgsTextFormat &format );
%Docstring
Sets the current text ``format`` to show in the widget.
This is only used when mode() is ModeTextRenderer.
.. seealso:: textFormat()
%End

void setCurrentFont( const QFont &font );
%Docstring
Sets the current text ``font`` to show in the widget.
This is only used when mode() is ModeQFont.
.. seealso:: currentFont()
%End

void setColor( const QColor &color );
%Docstring
Sets the current ``color`` for the text. Will emit a changed signal if the color is different
to the previous text color.
This is only used when mode() is ModeTextRenderer.
%End

void copyFormat();
@@ -98,13 +146,15 @@ class QgsFontButton : QToolButton
void copyColor();
%Docstring
Copies the current text color to the clipboard.
This is only used when mode() is ModeTextRenderer.
.. seealso:: pasteColor()
%End

void pasteColor();
%Docstring
Pastes a color from the clipboard to the text format. If clipboard does not contain a valid
color or string representation of a color, then no change is applied.
This is only used when mode() is ModeTextRenderer.
.. seealso:: copyColor()
%End

0 comments on commit 99855ea

Please sign in to comment.
You can’t perform that action at this time.