QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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_sip.h"
20#include "qgstextformat.h"
21
22#include <QToolButton>
23#include <QPointer>
24
26class QgsMapCanvas;
27class QgsMessageBar;
29class QgsScreenHelper;
30
31
47class GUI_EXPORT QgsFontButton : public QToolButton
48{
49 Q_OBJECT
50
51 Q_PROPERTY( Mode mode READ mode WRITE setMode )
52 Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
53 Q_PROPERTY( QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY changed )
54 Q_PROPERTY( QgsTextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY changed )
55
56 public:
57
64
65 Q_ENUM( Mode )
66
67
72 QgsFontButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
73
74 QSize minimumSizeHint() const override;
75 QSize sizeHint() const override;
76
81 QgsFontButton::Mode mode() const;
82
90 void setMode( Mode mode );
91
96 void setDialogTitle( const QString &title );
97
102 QString dialogTitle() const;
103
108 QgsMapCanvas *mapCanvas() const;
109
115 void setMapCanvas( QgsMapCanvas *canvas );
116
123 void setMessageBar( QgsMessageBar *bar );
124
130 QgsMessageBar *messageBar() const;
131
137 QgsTextFormat textFormat() const { return mFormat; }
138
144 QFont currentFont() const;
145
151 QgsVectorLayer *layer() const;
152
160 void setLayer( QgsVectorLayer *layer );
161
167 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
168
182 void setShowNullFormat( const bool show ) { mShowNoFormat = show; }
183
192 void setNoFormatString( const QString &string ) { mNullFormatString = string; }
193
206 bool showNullFormat() const { return mShowNoFormat; }
207
208 public slots:
209
215 void setTextFormat( const QgsTextFormat &format );
216
224 void setToNullFormat();
225
231 void setCurrentFont( const QFont &font );
232
238 void setColor( const QColor &color );
239
244 void copyFormat();
245
251 void pasteFormat();
252
258 void copyColor();
259
266 void pasteColor();
267
268 signals:
269
273 void changed();
274
275 protected:
276
277 bool event( QEvent *e ) override;
278 void changeEvent( QEvent *e ) override;
279 void showEvent( QShowEvent *e ) override;
280 void resizeEvent( QResizeEvent *event ) override;
281
282 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
283 void mousePressEvent( QMouseEvent *e ) override;
284 // Reimplemented to allow dragging fonts from button
285 void mouseMoveEvent( QMouseEvent *e ) override;
286
287 // Reimplemented to accept dragged colors
288 void dragEnterEvent( QDragEnterEvent *e ) override;
289
290 // Reimplemented to reset button appearance after drag leave
291 void dragLeaveEvent( QDragLeaveEvent *e ) override;
292
293 // Reimplemented to accept dropped colors
294 void dropEvent( QDropEvent *e ) override;
295
296 void wheelEvent( QWheelEvent *event ) override;
297
298 private slots:
299
300 void showSettingsDialog();
301
305 void prepareMenu();
306
307 void addRecentColor( const QColor &color );
308
309 private:
310
311 QgsScreenHelper *mScreenHelper = nullptr;
312
313 QSize mSizeHint;
314
315 Mode mMode = ModeTextRenderer;
316
317 QString mDialogTitle;
318 QgsTextFormat mFormat;
319 QFont mFont;
320
321 QgsMapCanvas *mMapCanvas = nullptr;
322 QgsMessageBar *mMessageBar = nullptr;
323
324 QPoint mDragStartPosition;
325
326 QMenu *mMenu = nullptr;
327
328 QPointer< QgsVectorLayer > mLayer;
329
330 QSize mIconSize;
331
332 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
333
334 bool mShowNoFormat = false;
335 QString mNullFormatString;
336 QPointer< QAction > mNullFormatAction;
337 QPointer< QgsTextFormatPanelWidget > mActivePanel;
338
346 bool formatFromMimeData( const QMimeData *mimeData, QgsTextFormat &resultFormat ) const;
347
348
356 bool fontFromMimeData( const QMimeData *mimeData, QFont &resultFont ) const;
357
367 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
368
372 QPixmap createColorIcon( const QColor &color ) const;
373
377 QPixmap createDragIcon( QSize size = QSize( 50, 50 ), const QgsTextFormat *tempFormat = nullptr, const QFont *tempFont = nullptr ) const;
378
383 void updatePreview( const QColor &color = QColor(), QgsTextFormat *tempFormat = nullptr, QFont *tempFont = nullptr );
384};
385
386#endif // QGSFONTBUTTON_H
Abstract interface for generating an expression context.
A button for customizing QgsTextFormat settings.
void setNoFormatString(const QString &string)
Sets the string to use for the "null format" option in the button's drop-down menu.
Mode
Available button modes.
@ ModeQFont
Configure font settings for use with QFont objects.
@ ModeTextRenderer
Configure font settings for use with QgsTextRenderer.
void setShowNullFormat(const bool show)
Sets whether the "null format" option should be shown in the button's drop-down menu.
bool showNullFormat() const
Returns whether the "null format" option will be shown in the button's drop-down menu.
void changed()
Emitted when the widget's text format settings are changed.
QgsTextFormat textFormat() const
Returns the current text formatting set by the widget.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
A utility class for dynamic handling of changes to screen properties.
A panel widget for customizing text formatting settings.
Container for all settings relating to text rendering.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53