QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
48class GUI_EXPORT QgsFontButton : public QToolButton
49{
50 Q_OBJECT
51
52 Q_PROPERTY( Mode mode READ mode WRITE setMode )
53 Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
54 Q_PROPERTY( QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY changed )
55 Q_PROPERTY( QgsTextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY changed )
56
57 public:
58
60 enum Mode
61 {
64 };
65
66 Q_ENUM( Mode )
67
68
73 QgsFontButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
74
75 QSize minimumSizeHint() const override;
76 QSize sizeHint() const override;
77
82 QgsFontButton::Mode mode() const;
83
91 void setMode( Mode mode );
92
97 void setDialogTitle( const QString &title );
98
103 QString dialogTitle() const;
104
109 QgsMapCanvas *mapCanvas() const;
110
116 void setMapCanvas( QgsMapCanvas *canvas );
117
124 void setMessageBar( QgsMessageBar *bar );
125
131 QgsMessageBar *messageBar() const;
132
138 QgsTextFormat textFormat() const { return mFormat; }
139
145 QFont currentFont() const;
146
152 QgsVectorLayer *layer() const;
153
161 void setLayer( QgsVectorLayer *layer );
162
168 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
169
183 void setShowNullFormat( const bool show ) { mShowNoFormat = show; }
184
193 void setNoFormatString( const QString &string ) { mNullFormatString = string; }
194
207 bool showNullFormat() const { return mShowNoFormat; }
208
209 public slots:
210
216 void setTextFormat( const QgsTextFormat &format );
217
225 void setToNullFormat();
226
232 void setCurrentFont( const QFont &font );
233
239 void setColor( const QColor &color );
240
245 void copyFormat();
246
252 void pasteFormat();
253
259 void copyColor();
260
267 void pasteColor();
268
269 signals:
270
274 void changed();
275
276 protected:
277
278 bool event( QEvent *e ) override;
279 void changeEvent( QEvent *e ) override;
280 void showEvent( QShowEvent *e ) override;
281 void resizeEvent( QResizeEvent *event ) override;
282
283 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
284 void mousePressEvent( QMouseEvent *e ) override;
285 // Reimplemented to allow dragging fonts from button
286 void mouseMoveEvent( QMouseEvent *e ) override;
287
288 // Reimplemented to accept dragged colors
289 void dragEnterEvent( QDragEnterEvent *e ) override;
290
291 // Reimplemented to reset button appearance after drag leave
292 void dragLeaveEvent( QDragLeaveEvent *e ) override;
293
294 // Reimplemented to accept dropped colors
295 void dropEvent( QDropEvent *e ) override;
296
297 void wheelEvent( QWheelEvent *event ) override;
298
299 private slots:
300
301 void showSettingsDialog();
302
306 void prepareMenu();
307
308 void addRecentColor( const QColor &color );
309
310 private:
311
312 QgsScreenHelper *mScreenHelper = nullptr;
313
314 QSize mSizeHint;
315
316 Mode mMode = ModeTextRenderer;
317
318 QString mDialogTitle;
319 QgsTextFormat mFormat;
320 QFont mFont;
321
322 QgsMapCanvas *mMapCanvas = nullptr;
323 QgsMessageBar *mMessageBar = nullptr;
324
325 QPoint mDragStartPosition;
326
327 QMenu *mMenu = nullptr;
328
329 QPointer< QgsVectorLayer > mLayer;
330
331 QSize mIconSize;
332
333 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
334
335 bool mShowNoFormat = false;
336 QString mNullFormatString;
337 QPointer< QAction > mNullFormatAction;
338 QPointer< QgsTextFormatPanelWidget > mActivePanel;
339
347 bool formatFromMimeData( const QMimeData *mimeData, QgsTextFormat &resultFormat ) const;
348
349
357 bool fontFromMimeData( const QMimeData *mimeData, QFont &resultFont ) const;
358
368 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
369
373 QPixmap createColorIcon( const QColor &color ) const;
374
378 QPixmap createDragIcon( QSize size = QSize( 50, 50 ), const QgsTextFormat *tempFormat = nullptr, const QFont *tempFont = nullptr ) const;
379
384 void updatePreview( const QColor &color = QColor(), QgsTextFormat *tempFormat = nullptr, QFont *tempFont = nullptr );
385};
386
387#endif // QGSFONTBUTTON_H
Abstract interface for generating an expression context.
A button for customizing QgsTextFormat settings.
Definition: qgsfontbutton.h:49
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.
Definition: qgsfontbutton.h:61
@ ModeQFont
Configure font settings for use with QFont objects.
Definition: qgsfontbutton.h:63
@ ModeTextRenderer
Configure font settings for use with QgsTextRenderer.
Definition: qgsfontbutton.h:62
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.
Definition: qgsmapcanvas.h:90
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
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.
Definition: qgstextformat.h:41
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53