Skip to content
Permalink
Browse files

Merge pull request #4736 from nyalldawson/text_button

New gui widget QgsFontButton
  • Loading branch information
nyalldawson committed Jul 6, 2017
2 parents 536f643 + e2acf53 commit 014b0400da7b771a9ba02e0b7efbf477e19f8215
Showing with 2,406 additions and 313 deletions.
  1. +34 −0 python/core/qgsfontutils.sip
  2. +16 −0 python/core/qgstextrenderer.sip
  3. +1 −0 python/gui/gui_auto.sip
  4. +202 −0 python/gui/qgsfontbutton.sip
  5. +24 −24 src/app/composer/qgscomposerattributetablewidget.cpp
  6. +2 −2 src/app/composer/qgscomposerattributetablewidget.h
  7. +12 −12 src/app/composer/qgscomposerlabelwidget.cpp
  8. +1 −1 src/app/composer/qgscomposerlabelwidget.h
  9. +42 −44 src/app/composer/qgscomposerlegendwidget.cpp
  10. +4 −4 src/app/composer/qgscomposerlegendwidget.h
  11. +10 −11 src/app/composer/qgscomposermapgridwidget.cpp
  12. +1 −1 src/app/composer/qgscomposermapgridwidget.h
  13. +12 −11 src/app/composer/qgscomposerscalebarwidget.cpp
  14. +1 −1 src/app/composer/qgscomposerscalebarwidget.h
  15. +7 −8 src/app/qgsdecorationgriddialog.cpp
  16. +1 −1 src/app/qgsdecorationgriddialog.h
  17. +2 −11 src/app/qgsdecorationlayoutextentdialog.cpp
  18. +0 −2 src/app/qgsdecorationlayoutextentdialog.h
  19. +4 −9 src/app/qgsdiagramproperties.cpp
  20. +0 −2 src/app/qgsdiagramproperties.h
  21. +76 −1 src/core/qgsfontutils.cpp
  22. +33 −0 src/core/qgsfontutils.h
  23. +43 −0 src/core/qgstextrenderer.cpp
  24. +14 −0 src/core/qgstextrenderer.h
  25. +2 −0 src/customwidgets/CMakeLists.txt
  26. +2 −0 src/customwidgets/qgiscustomwidgets.cpp
  27. +97 −0 src/customwidgets/qgsfontbuttonplugin.cpp
  28. +51 −0 src/customwidgets/qgsfontbuttonplugin.h
  29. +2 −0 src/gui/CMakeLists.txt
  30. +870 −0 src/gui/qgsfontbutton.cpp
  31. +276 −0 src/gui/qgsfontbutton.h
  32. +5 −1 src/gui/qgsguiutils.h
  33. +6 −8 src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
  34. +1 −1 src/gui/symbology-ng/qgspointdisplacementrendererwidget.h
  35. +87 −38 src/ui/composer/qgscomposerattributetablewidgetbase.ui
  36. +30 −16 src/ui/composer/qgscomposerlabelwidgetbase.ui
  37. +57 −11 src/ui/composer/qgscomposerlegendwidgetbase.ui
  38. +44 −10 src/ui/composer/qgscomposermapgridwidgetbase.ui
  39. +21 −16 src/ui/composer/qgscomposerscalebarwidgetbase.ui
  40. +20 −7 src/ui/qgsdecorationgriddialog.ui
  41. +20 −7 src/ui/qgsdecorationlayoutextentdialog.ui
  42. +64 −30 src/ui/qgsdiagrampropertiesbase.ui
  43. +31 −20 src/ui/qgspointdisplacementrendererwidgetbase.ui
  44. +1 −0 tests/src/python/CMakeLists.txt
  45. +110 −0 tests/src/python/test_qgsfontbutton.py
  46. +57 −3 tests/src/python/test_qgsfontutils.py
  47. +10 −0 tests/src/python/test_qgstextrenderer.py
@@ -9,6 +9,7 @@




class QgsFontUtils
{

@@ -136,6 +137,24 @@ class QgsFontUtils
:rtype: bool
%End

static QMimeData *toMimeData( const QFont &font ) /Factory/;
%Docstring
Returns new mime data representing the specified ``font`` settings.
Caller takes responsibility for deleting the returned object.
.. seealso:: fromMimeData()
.. versionadded:: 3.0
:rtype: QMimeData
%End

static QFont fromMimeData( const QMimeData *data, bool *ok /Out/ = 0 );
%Docstring
Attempts to parse the provided mime ``data`` as a QFont.
If data can be parsed as a QFont, ``ok`` will be set to true.
.. seealso:: toMimeData()
.. versionadded:: 3.0
:rtype: QFont
%End

static QString translateNamedStyle( const QString &namedStyle );
%Docstring
Returns the localized named style of a font, if such a translation is available.
@@ -168,6 +187,21 @@ class QgsFontUtils
.. versionadded:: 2.16
:rtype: str
%End

static void addRecentFontFamily( const QString &family );
%Docstring
Adds a font ``family`` to the list of recently used font families.
.. versionadded:: 3.0
.. seealso:: recentFontFamilies()
%End

static QStringList recentFontFamilies();
%Docstring
Returns a list of recently used font families.
.. seealso:: addRecentFontFamily()
.. versionadded:: 3.0
:rtype: list of str
%End
};

/************************************************************************
@@ -1231,6 +1231,22 @@ class QgsTextFormat
:rtype: QDomElement
%End

QMimeData *toMimeData() const /Factory/;
%Docstring
Returns new mime data representing the text format settings.
Caller takes responsibility for deleting the returned object.
.. seealso:: fromMimeData()
:rtype: QMimeData
%End

static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok /Out/ = 0 );
%Docstring
Attempts to parse the provided mime ``data`` as a QgsTextFormat.
If data can be parsed as a text format, ``ok`` will be set to true.
.. seealso:: toMimeData()
:rtype: QgsTextFormat
%End

bool containsAdvancedEffects() const;
%Docstring
Returns true if any component of the font format requires advanced effects
@@ -110,6 +110,7 @@
%Include qgsfilterlineedit.sip
%Include qgsfloatingwidget.sip
%Include qgsfocuswatcher.sip
%Include qgsfontbutton.sip
%Include qgsformannotation.sip
%Include qgsgradientcolorrampdialog.sip
%Include qgsgradientstopeditor.sip
@@ -0,0 +1,202 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsfontbutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsFontButton : QToolButton
{
%Docstring
A button for customising QgsTextFormat settings.

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

%TypeHeaderCode
#include "qgsfontbutton.h"
%End
public:


enum Mode
{
ModeTextRenderer,
ModeQFont,
};

QgsFontButton( QWidget *parent /TransferThis/ = 0, const QString &dialogTitle = QString() );
%Docstring
Construct a new font button.
Use ``parent`` to attach a parent QWidget to the dialog.
Use ``dialogTitle`` string to define the title to show in the text settings dialog.
%End

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.
.. seealso:: dialogTitle()
%End

QString dialogTitle() const;
%Docstring
Returns the title for the text settings dialog window.
.. seealso:: setDialogTitle()
:rtype: str
%End

QgsMapCanvas *mapCanvas() const;
%Docstring
Returns the map canvas associated with the widget.
.. seealso:: setMapCanvas()
:rtype: QgsMapCanvas
%End

void setMapCanvas( QgsMapCanvas *canvas );
%Docstring
Sets a map ``canvas`` to associate with the widget. This allows the
widget to fetch current settings from the map canvas, such as current scale.
.. seealso:: mapCanvas()
%End

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();
%Docstring
Copies the current text format to the clipboard.
.. seealso:: pasteFormat()
%End

void pasteFormat();
%Docstring
Pastes a format from the clipboard. If clipboard does not contain a valid
format then no change is applied.
.. seealso:: copyFormat()
%End

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

signals:

void changed();
%Docstring
Emitted when the widget's text format settings are changed.
%End

protected:

virtual bool event( QEvent *e );

virtual void changeEvent( QEvent *e );

virtual void showEvent( QShowEvent *e );

virtual void resizeEvent( QResizeEvent *event );


virtual void mousePressEvent( QMouseEvent *e );

virtual void mouseMoveEvent( QMouseEvent *e );


virtual void dragEnterEvent( QDragEnterEvent *e );


virtual void dragLeaveEvent( QDragLeaveEvent *e );


virtual void dropEvent( QDropEvent *e );


virtual void wheelEvent( QWheelEvent *event );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsfontbutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -40,6 +40,9 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
setupUi( this );
setPanelTitle( tr( "Table properties" ) );

mContentFontToolButton->setMode( QgsFontButton::ModeQFont );
mHeaderFontToolButton->setMode( QgsFontButton::ModeQFont );

blockAllSignals( true );

mResizeModeComboBox->addItem( tr( "Use existing frames" ), QgsComposerMultiFrame::UseExistingFrames );
@@ -106,6 +109,9 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
QgsComposerItemWidget *itemPropertiesWidget = new QgsComposerItemWidget( this, mFrame );
mainLayout->addWidget( itemPropertiesWidget );
}

connect( mHeaderFontToolButton, &QgsFontButton::changed, this, &QgsComposerAttributeTableWidget::headerFontChanged );
connect( mContentFontToolButton, &QgsFontButton::changed, this, &QgsComposerAttributeTableWidget::contentFontChanged );
}

QgsComposerAttributeTableWidget::~QgsComposerAttributeTableWidget()
@@ -238,24 +244,19 @@ void QgsComposerAttributeTableWidget::on_mMarginSpinBox_valueChanged( double d )
}
}

void QgsComposerAttributeTableWidget::on_mHeaderFontPushButton_clicked()
void QgsComposerAttributeTableWidget::headerFontChanged()
{
if ( !mComposerTable )
return;

bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mComposerTable->headerFont(), tr( "Select Font" ) );
if ( ok )
{
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font" ) );
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font" ) );

mComposerTable->setHeaderFont( newFont );
mComposerTable->setHeaderFont( mHeaderFontToolButton->currentFont() );

if ( composition )
composition->endMultiFrameCommand();
}
if ( composition )
composition->endMultiFrameCommand();
}

void QgsComposerAttributeTableWidget::on_mHeaderFontColorButton_colorChanged( const QColor &newColor )
@@ -277,26 +278,21 @@ void QgsComposerAttributeTableWidget::on_mHeaderFontColorButton_colorChanged( co
}
}

void QgsComposerAttributeTableWidget::on_mContentFontPushButton_clicked()
void QgsComposerAttributeTableWidget::contentFontChanged()
{
if ( !mComposerTable )
{
return;
}

bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mComposerTable->contentFont(), tr( "Select Font" ) );
if ( ok )
{
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font" ) );
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font" ) );

mComposerTable->setContentFont( newFont );
mComposerTable->setContentFont( mContentFontToolButton->currentFont() );

if ( composition )
composition->endMultiFrameCommand();
}
if ( composition )
composition->endMultiFrameCommand();
}

void QgsComposerAttributeTableWidget::on_mContentFontColorButton_colorChanged( const QColor &newColor )
@@ -479,6 +475,8 @@ void QgsComposerAttributeTableWidget::updateGuiElements()

mHeaderFontColorButton->setColor( mComposerTable->headerFontColor() );
mContentFontColorButton->setColor( mComposerTable->contentFontColor() );
mHeaderFontToolButton->setCurrentFont( mComposerTable->headerFont() );
mContentFontToolButton->setCurrentFont( mComposerTable->contentFont() );

if ( mComposerTable->displayOnlyVisibleFeatures() && mShowOnlyVisibleFeaturesCheckBox->isEnabled() )
{
@@ -628,6 +626,8 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mDrawEmptyCheckBox->blockSignals( b );
mWrapStringLineEdit->blockSignals( b );
mWrapBehaviorComboBox->blockSignals( b );
mContentFontToolButton->blockSignals( b );
mHeaderFontToolButton->blockSignals( b );
}

void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )

0 comments on commit 014b040

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