QGIS API Documentation  3.0.2-Girona (307d082)
qgstextformatwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextformatwidget.h
3  ---------------------
4  begin : June 2009
5  copyright : (C) Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #ifndef QGSTEXTFORMATWIDGET_H
18 #define QGSTEXTFORMATWIDGET_H
19 
20 #include "ui_qgstextformatwidgetbase.h"
21 #include "qgis.h"
22 #include "qgstextrenderer.h"
23 #include "qgsstringutils.h"
24 #include "qgsguiutils.h"
25 #include <QFontDatabase>
26 #include "qgis_gui.h"
27 
28 class QgsMapCanvas;
30 
31 
49 class GUI_EXPORT QgsTextFormatWidget : public QWidget, protected Ui::QgsTextFormatWidgetBase
50 {
51  Q_OBJECT
52  Q_PROPERTY( QgsTextFormat format READ format )
53 
54  public:
55 
62  QgsTextFormatWidget( const QgsTextFormat &format = QgsTextFormat(), QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
63 
64  ~QgsTextFormatWidget() override;
65 
69  QgsTextFormat format() const;
70 
71  public slots:
72 
77  void setDockMode( bool enabled );
78 
79  signals:
80 
82  void widgetChanged();
83 
84  protected:
85 
87  enum Mode
88  {
89  Text = 0,
91  };
92 
99  QgsTextFormatWidget( QgsMapCanvas *mapCanvas, QWidget *parent SIP_TRANSFERTHIS, Mode mode );
100 
105  void updateWidgetForFormat( const QgsTextFormat &format );
106 
111  void setPreviewBackground( const QColor &color );
112 
117  void enableDataDefinedAlignment( bool enable );
118 
122  QButtonGroup *mQuadrantBtnGrp = nullptr;
124  QButtonGroup *mDirectSymbBtnGrp = nullptr;
126  QButtonGroup *mUpsidedownBtnGrp = nullptr;
128  QButtonGroup *mPlacePointBtnGrp = nullptr;
130  QButtonGroup *mPlaceLineBtnGrp = nullptr;
132  QButtonGroup *mPlacePolygonBtnGrp = nullptr;
134  int mMinPixelLimit = 0;
135 
136  protected slots:
137 
139  void updateLinePlacementOptions();
140 
142  void updatePlacementWidgets();
143 
144  private:
145  Mode mWidgetMode = Text;
146  QgsMapCanvas *mMapCanvas = nullptr;
147  QgsCharacterSelectorDialog *mCharDlg = nullptr;
148  std::unique_ptr< QgsPaintEffect > mBufferEffect;
149  std::unique_ptr< QgsPaintEffect > mBackgroundEffect;
150 
151  QFontDatabase mFontDB;
152 
153  // background reference font
154  QFont mRefFont;
155  bool mDockMode;
156 
157  bool mLoadSvgParams = false;
158 
159  void initWidget();
160  void setWidgetMode( Mode mode );
161  void toggleDDButtons( bool visible );
162  void blockFontChangeSignals( bool blk );
163  void populateFontCapitalsComboBox();
164  void populateFontStyleComboBox();
165  void updateFont( const QFont &font );
166  void connectValueChanged( const QList<QWidget *> &widgets, const char *slot );
167 
168  private slots:
169  void optionsStackedWidget_CurrentChanged( int indx );
170  void showBackgroundRadius( bool show );
171  void showBackgroundPenStyle( bool show );
172  void mShapeSVGPathLineEdit_textChanged( const QString &text );
173  void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
174  void previewScaleChanged( double scale );
175  void mFontSizeSpinBox_valueChanged( double d );
176  void mFontCapitalsComboBox_currentIndexChanged( int index );
177  void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
178  void mFontStyleComboBox_currentIndexChanged( const QString &text );
179  void mFontUnderlineBtn_toggled( bool ckd );
180  void mFontStrikethroughBtn_toggled( bool ckd );
181  void mFontWordSpacingSpinBox_valueChanged( double spacing );
182  void mFontLetterSpacingSpinBox_valueChanged( double spacing );
183  void mFontSizeUnitWidget_changed();
184  void mFontMinPixelSpinBox_valueChanged( int px );
185  void mFontMaxPixelSpinBox_valueChanged( int px );
186  void mBufferUnitWidget_changed();
187  void mCoordXDDBtn_activated( bool active );
188  void mCoordYDDBtn_activated( bool active );
189  void mShapeTypeCmbBx_currentIndexChanged( int index );
190  void mShapeRotationCmbBx_currentIndexChanged( int index );
191  void mShapeSVGParamsBtn_clicked();
192  void mShapeSVGSelectorBtn_clicked();
193  void mPreviewTextEdit_textChanged( const QString &text );
194  void mPreviewTextBtn_clicked();
195  void mPreviewBackgroundBtn_colorChanged( const QColor &color );
196  void mDirectSymbLeftToolBtn_clicked();
197  void mDirectSymbRightToolBtn_clicked();
198  void mChkNoObstacle_toggled( bool active );
199  void chkLineOrientationDependent_toggled( bool active );
200  void mToolButtonConfigureSubstitutes_clicked();
201  void collapseSample( bool collapse );
202  void changeTextColor( const QColor &color );
203  void changeBufferColor( const QColor &color );
204  void updatePreview();
205  void scrollPreview();
206  void updateSvgWidgets( const QString &svgPath );
207 };
208 
209 
222 class GUI_EXPORT QgsTextFormatDialog : public QDialog
223 {
224  Q_OBJECT
225 
226  public:
227 
235  QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
236 
237  ~QgsTextFormatDialog() override;
238 
242  QgsTextFormat format() const;
243 
244  private:
245 
246  QgsTextFormatWidget *mFormatWidget = nullptr;
247 };
248 
262 {
263  Q_OBJECT
264 
265  public:
266 
273  QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
274 
278  QgsTextFormat format() const;
279 
280  void setDockMode( bool dockMode ) override;
281 
282  private:
283 
284  QgsTextFormatWidget *mFormatWidget = nullptr;
285 };
286 
287 #endif //QGSTEXTFORMATWIDGET_H
288 
289 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A dialog for selecting a single character from a single font.
A widget for customising text formatting settings.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
Show labeling settings in addition to text formatting settings.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs...
QgsStringReplacementCollection mSubstitutions
Text substitution list.
A collection of string replacements (specified using QgsStringReplacement objects).
A panel widget for customising text formatting settings.
Container for all settings relating to text rendering.
A simple dialog for customising text formatting settings.
Wrapper widget for existing widgets which can&#39;t have the inheritance tree changed, e.g dialogs.