QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
63
64 Q_ENUM( Mode )
65
66
71 QgsFontButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
72
73 QSize minimumSizeHint() const override;
74 QSize sizeHint() const override;
75
80 QgsFontButton::Mode mode() const;
81
89 void setMode( Mode mode );
90
95 void setDialogTitle( const QString &title );
96
101 QString dialogTitle() const;
102
107 QgsMapCanvas *mapCanvas() const;
108
114 void setMapCanvas( QgsMapCanvas *canvas );
115
122 void setMessageBar( QgsMessageBar *bar );
123
129 QgsMessageBar *messageBar() const;
130
136 QgsTextFormat textFormat() const { return mFormat; }
137
143 QFont currentFont() const;
144
150 QgsVectorLayer *layer() const;
151
159 void setLayer( QgsVectorLayer *layer );
160
166 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
167
181 void setShowNullFormat( const bool show ) { mShowNoFormat = show; }
182
191 void setNoFormatString( const QString &string ) { mNullFormatString = string; }
192
205 bool showNullFormat() const { return mShowNoFormat; }
206
207 public slots:
208
214 void setTextFormat( const QgsTextFormat &format );
215
223 void setToNullFormat();
224
230 void setCurrentFont( const QFont &font );
231
237 void setColor( const QColor &color );
238
243 void copyFormat();
244
250 void pasteFormat();
251
257 void copyColor();
258
265 void pasteColor();
266
267 signals:
268
272 void changed();
273
274 protected:
275 bool event( QEvent *e ) override;
276 void changeEvent( QEvent *e ) override;
277 void showEvent( QShowEvent *e ) override;
278 void resizeEvent( QResizeEvent *event ) override;
279
280 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
281 void mousePressEvent( QMouseEvent *e ) override;
282 // Reimplemented to allow dragging fonts from button
283 void mouseMoveEvent( QMouseEvent *e ) override;
284
285 // Reimplemented to accept dragged colors
286 void dragEnterEvent( QDragEnterEvent *e ) override;
287
288 // Reimplemented to reset button appearance after drag leave
289 void dragLeaveEvent( QDragLeaveEvent *e ) override;
290
291 // Reimplemented to accept dropped colors
292 void dropEvent( QDropEvent *e ) override;
293
294 void wheelEvent( QWheelEvent *event ) override;
295
296 private slots:
297
298 void showSettingsDialog();
299
303 void prepareMenu();
304
305 void addRecentColor( const QColor &color );
306
307 private:
308 QgsScreenHelper *mScreenHelper = nullptr;
309
310 QSize mSizeHint;
311
312 Mode mMode = ModeTextRenderer;
313
314 QString mDialogTitle;
315 QgsTextFormat mFormat;
316 QFont mFont;
317
318 QgsMapCanvas *mMapCanvas = nullptr;
319 QgsMessageBar *mMessageBar = nullptr;
320
321 QPoint mDragStartPosition;
322
323 QMenu *mMenu = nullptr;
324
325 QPointer<QgsVectorLayer> mLayer;
326
327 QSize mIconSize;
328
329 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
330
331 bool mShowNoFormat = false;
332 QString mNullFormatString;
333 QPointer<QAction> mNullFormatAction;
334 QPointer<QgsTextFormatPanelWidget> mActivePanel;
335
343 bool formatFromMimeData( const QMimeData *mimeData, QgsTextFormat &resultFormat ) const;
344
345
353 bool fontFromMimeData( const QMimeData *mimeData, QFont &resultFont ) const;
354
364 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
365
369 QPixmap createColorIcon( const QColor &color ) const;
370
374 QPixmap createDragIcon( QSize size = QSize( 50, 50 ), const QgsTextFormat *tempFormat = nullptr, const QFont *tempFont = nullptr ) const;
375
380 void updatePreview( const QColor &color = QColor(), QgsTextFormat *tempFormat = nullptr, QFont *tempFont = nullptr );
381};
382
383#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