QGIS API Documentation 4.3.0-Master (91d4a333d5d)
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 <QPointer>
23#include <QToolButton>
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 )
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 allow dragging colors
281 void mousePressEvent( QMouseEvent *e ) override;
282 void contextMenuEvent( QContextMenuEvent *e ) override;
283 // Reimplemented to allow dragging fonts from button
284 void mouseMoveEvent( QMouseEvent *e ) override;
285
286 // Reimplemented to accept dragged colors
287 void dragEnterEvent( QDragEnterEvent *e ) override;
288
289 // Reimplemented to reset button appearance after drag leave
290 void dragLeaveEvent( QDragLeaveEvent *e ) override;
291
292 // Reimplemented to accept dropped colors
293 void dropEvent( QDropEvent *e ) override;
294
295 void wheelEvent( QWheelEvent *event ) override;
296
297 private slots:
298
299 void showSettingsDialog();
300
304 void prepareMenu();
305
306 void addRecentColor( const QColor &color );
307
308 private:
309 QgsScreenHelper *mScreenHelper = nullptr;
310
311 QSize mSizeHint;
312
313 Mode mMode = ModeTextRenderer;
314
315 QString mDialogTitle;
316 QgsTextFormat mFormat;
317 QFont mFont;
318
319 QgsMapCanvas *mMapCanvas = nullptr;
320 QgsMessageBar *mMessageBar = nullptr;
321
322 QPoint mDragStartPosition;
323
324 QMenu *mMenu = nullptr;
325
326 QPointer<QgsVectorLayer> mLayer;
327
328 QSize mIconSize;
329
330 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
331
332 bool mShowNoFormat = false;
333 QString mNullFormatString;
334 QPointer<QAction> mNullFormatAction;
335 QPointer<QgsTextFormatPanelWidget> mActivePanel;
336
344 bool formatFromMimeData( const QMimeData *mimeData, QgsTextFormat &resultFormat ) const;
345
346
354 bool fontFromMimeData( const QMimeData *mimeData, QFont &resultFont ) const;
355
365 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
366
370 QPixmap createColorIcon( const QColor &color ) const;
371
375 QPixmap createDragIcon( QSize size = QSize( 50, 50 ), const QgsTextFormat *tempFormat = nullptr, const QFont *tempFont = nullptr ) const;
376
381 void updatePreview( const QColor &color = QColor(), QgsTextFormat *tempFormat = nullptr, QFont *tempFont = nullptr );
382};
383
384#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.
QgsTextFormat textFormat
void contextMenuEvent(QContextMenuEvent *e) override
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.
QString dialogTitle
void setCurrentFont(const QFont &font)
Sets the current text font to show in the widget.
void mousePressEvent(QMouseEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
bool showNullFormat() const
Returns whether the "null format" option will be shown in the button's drop-down menu.
QgsFontButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new font button.
void changeEvent(QEvent *e) override
void changed()
Emitted when the widget's text format settings are changed.
void resizeEvent(QResizeEvent *event) override
void dragEnterEvent(QDragEnterEvent *e) override
void dragLeaveEvent(QDragLeaveEvent *e) override
void showEvent(QShowEvent *e) override
void setDialogTitle(const QString &title)
Sets the title for the text settings dialog window.
void wheelEvent(QWheelEvent *event) override
bool event(QEvent *e) override
void dropEvent(QDropEvent *e) override
QgsTextFormat textFormat() const
Returns the current text formatting set by the widget.
void setTextFormat(const QgsTextFormat &format)
Sets the current text format to show in the widget.
void setMode(Mode mode)
Sets the current button mode.
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 dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52