QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsfontbutton.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfontbutton.h
3  ---------------
4  Date : May 2017
5  Copyright : (C) 2017 by Nyall Dawson
6  Email : nyall dot dawson 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 #ifndef QGSFONTBUTTON_H
16 #define QGSFONTBUTTON_H
17 
18 #include "qgis_gui.h"
19 #include "qgis.h"
20 #include "qgstextrenderer.h"
21 
22 #include <QToolButton>
23 
24 class QgsMapCanvas;
25 
42 class GUI_EXPORT QgsFontButton : public QToolButton
43 {
44  Q_OBJECT
45 
46  Q_PROPERTY( Mode mode READ mode WRITE setMode )
47  Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
48  Q_PROPERTY( QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY changed )
49  Q_PROPERTY( QgsTextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY changed )
50 
51  public:
52 
54  enum Mode
55  {
58  };
59 
60  Q_ENUM( Mode )
61 
62 
67  QgsFontButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
68 
69  QSize minimumSizeHint() const override;
70  QSize sizeHint() const override;
71 
76  QgsFontButton::Mode mode() const;
77 
85  void setMode( Mode mode );
86 
91  void setDialogTitle( const QString &title );
92 
97  QString dialogTitle() const;
98 
103  QgsMapCanvas *mapCanvas() const;
104 
110  void setMapCanvas( QgsMapCanvas *canvas );
111 
117  QgsTextFormat textFormat() const { return mFormat; }
118 
124  QFont currentFont() const;
125 
126 
127  public slots:
128 
134  void setTextFormat( const QgsTextFormat &format );
135 
141  void setCurrentFont( const QFont &font );
142 
148  void setColor( const QColor &color );
149 
154  void copyFormat();
155 
161  void pasteFormat();
162 
168  void copyColor();
169 
176  void pasteColor();
177 
178  signals:
179 
183  void changed();
184 
185  protected:
186 
187  bool event( QEvent *e ) override;
188  void changeEvent( QEvent *e ) override;
189  void showEvent( QShowEvent *e ) override;
190  void resizeEvent( QResizeEvent *event ) override;
191 
192  // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
193  void mousePressEvent( QMouseEvent *e ) override;
194  // Reimplemented to allow dragging fonts from button
195  void mouseMoveEvent( QMouseEvent *e ) override;
196 
197  // Reimplemented to accept dragged colors
198  void dragEnterEvent( QDragEnterEvent *e ) override;
199 
200  // Reimplemented to reset button appearance after drag leave
201  void dragLeaveEvent( QDragLeaveEvent *e ) override;
202 
203  // Reimplemented to accept dropped colors
204  void dropEvent( QDropEvent *e ) override;
205 
206  void wheelEvent( QWheelEvent *event ) override;
207 
208  private slots:
209 
210  void showSettingsDialog();
211 
215  void prepareMenu();
216 
217  void addRecentColor( const QColor &color );
218 
219  private:
220 
221  QSize mSizeHint;
222 
223  Mode mMode = ModeTextRenderer;
224 
225  QString mDialogTitle;
226  QgsTextFormat mFormat;
227  QFont mFont;
228 
229  QgsMapCanvas *mMapCanvas = nullptr;
230 
231  QPoint mDragStartPosition;
232 
233  QMenu *mMenu = nullptr;
234 
235  QSize mIconSize;
236 
244  bool formatFromMimeData( const QMimeData *mimeData, QgsTextFormat &resultFormat ) const;
245 
246 
254  bool fontFromMimeData( const QMimeData *mimeData, QFont &resultFont ) const;
255 
265  bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
266 
270  QPixmap createColorIcon( const QColor &color ) const;
271 
275  QPixmap createDragIcon( QSize size = QSize( 50, 50 ), const QgsTextFormat *tempFormat = nullptr, const QFont *tempFont = nullptr ) const;
276 
281  void updatePreview( const QColor &color = QColor(), QgsTextFormat *tempFormat = nullptr, QFont *tempFont = nullptr );
282 };
283 
284 #endif // QGSFONTBUTTON_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Mode
Available button modes.
Definition: qgsfontbutton.h:54
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
Configure font settings for use with QgsTextRenderer.
Definition: qgsfontbutton.h:56
A button for customizing QgsTextFormat settings.
Definition: qgsfontbutton.h:42
Configure font settings for use with QFont objects.
Definition: qgsfontbutton.h:57
Container for all settings relating to text rendering.