QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
75  void setFormat( const QgsTextFormat &format );
76 
77  public slots:
78 
83  void setDockMode( bool enabled );
84 
85  signals:
86 
88  void widgetChanged();
89 
90  protected:
91 
93  enum Mode
94  {
95  Text = 0,
97  };
98 
105  QgsTextFormatWidget( QgsMapCanvas *mapCanvas, QWidget *parent SIP_TRANSFERTHIS, Mode mode );
106 
111  void updateWidgetForFormat( const QgsTextFormat &format );
112 
117  void setPreviewBackground( const QColor &color );
118 
123  void enableDataDefinedAlignment( bool enable );
124 
128  QButtonGroup *mQuadrantBtnGrp = nullptr;
130  QButtonGroup *mDirectSymbBtnGrp = nullptr;
132  QButtonGroup *mUpsidedownBtnGrp = nullptr;
134  QButtonGroup *mPlacePointBtnGrp = nullptr;
136  QButtonGroup *mPlaceLineBtnGrp = nullptr;
138  QButtonGroup *mPlacePolygonBtnGrp = nullptr;
140  int mMinPixelLimit = 0;
141 
142  protected slots:
143 
145  void updateLinePlacementOptions();
146 
148  void updatePlacementWidgets();
149 
150  private:
151  Mode mWidgetMode = Text;
152  QgsMapCanvas *mMapCanvas = nullptr;
153  QgsCharacterSelectorDialog *mCharDlg = nullptr;
154  std::unique_ptr< QgsPaintEffect > mBufferEffect;
155  std::unique_ptr< QgsPaintEffect > mBackgroundEffect;
156 
157  QFontDatabase mFontDB;
158 
159  // background reference font
160  QFont mRefFont;
161  bool mDockMode;
162 
163  bool mLoadSvgParams = false;
164 
165  void initWidget();
166  void setWidgetMode( Mode mode );
167  void toggleDDButtons( bool visible );
168  void blockFontChangeSignals( bool blk );
169  void populateFontCapitalsComboBox();
170  void populateFontStyleComboBox();
171  void updateFont( const QFont &font );
172  void connectValueChanged( const QList<QWidget *> &widgets, const char *slot );
173 
174  private slots:
175  void optionsStackedWidget_CurrentChanged( int indx );
176  void showBackgroundRadius( bool show );
177  void showBackgroundPenStyle( bool show );
178  void mShapeSVGPathLineEdit_textChanged( const QString &text );
179  void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
180  void previewScaleChanged( double scale );
181  void mFontSizeSpinBox_valueChanged( double d );
182  void mFontCapitalsComboBox_currentIndexChanged( int index );
183  void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
184  void mFontStyleComboBox_currentIndexChanged( const QString &text );
185  void mFontUnderlineBtn_toggled( bool ckd );
186  void mFontStrikethroughBtn_toggled( bool ckd );
187  void mFontWordSpacingSpinBox_valueChanged( double spacing );
188  void mFontLetterSpacingSpinBox_valueChanged( double spacing );
189  void mFontSizeUnitWidget_changed();
190  void mFontMinPixelSpinBox_valueChanged( int px );
191  void mFontMaxPixelSpinBox_valueChanged( int px );
192  void mBufferUnitWidget_changed();
193  void mCoordXDDBtn_activated( bool active );
194  void mCoordYDDBtn_activated( bool active );
195  void mShapeTypeCmbBx_currentIndexChanged( int index );
196  void mShapeRotationCmbBx_currentIndexChanged( int index );
197  void mShapeSVGParamsBtn_clicked();
198  void mShapeSVGSelectorBtn_clicked();
199  void mPreviewTextEdit_textChanged( const QString &text );
200  void mPreviewTextBtn_clicked();
201  void mPreviewBackgroundBtn_colorChanged( const QColor &color );
202  void mDirectSymbLeftToolBtn_clicked();
203  void mDirectSymbRightToolBtn_clicked();
204  void mChkNoObstacle_toggled( bool active );
205  void chkLineOrientationDependent_toggled( bool active );
206  void mToolButtonConfigureSubstitutes_clicked();
207  void collapseSample( bool collapse );
208  void changeTextColor( const QColor &color );
209  void changeBufferColor( const QColor &color );
210  void updatePreview();
211  void scrollPreview();
212  void updateSvgWidgets( const QString &svgPath );
213 };
214 
215 
228 class GUI_EXPORT QgsTextFormatDialog : public QDialog
229 {
230  Q_OBJECT
231 
232  public:
233 
241  QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
242 
243  ~QgsTextFormatDialog() override;
244 
248  QgsTextFormat format() const;
249 
250  private:
251 
252  QgsTextFormatWidget *mFormatWidget = nullptr;
253 };
254 
268 {
269  Q_OBJECT
270 
271  public:
272 
279  QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
280 
284  QgsTextFormat format() const;
285 
286  void setDockMode( bool dockMode ) override;
287 
288  private:
289 
290  QgsTextFormatWidget *mFormatWidget = nullptr;
291 };
292 
293 #endif //QGSTEXTFORMATWIDGET_H
294 
295 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A dialog for selecting a single character from a single font.
A widget for customizing 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 customizing text formatting settings.
Container for all settings relating to text rendering.
A simple dialog for customizing text formatting settings.
Wrapper widget for existing widgets which can&#39;t have the inheritance tree changed, e.g dialogs.