QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgstextpreview.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextpreview.h
3  ----------------
4  begin : October 2016
5  copyright : (C) 2016 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 QGSTEXTPREVIEW_H
16 #define QGSTEXTPREVIEW_H
17 
18 #include "qgstextformat.h"
19 #include "qgsrendercontext.h"
20 
21 #include <QLabel>
22 #include "qgis_gui.h"
23 
39 class GUI_EXPORT QgsTextPreview : public QLabel
40 {
41  Q_OBJECT
42 
43  Q_PROPERTY( QgsTextFormat format READ format WRITE setFormat )
44  Q_PROPERTY( double scale READ scale WRITE setScale )
45  Q_PROPERTY( QgsUnitTypes::DistanceUnit mapUnits READ mapUnits WRITE setMapUnits )
46 
47  public:
48 
53  QgsTextPreview( QWidget *parent = nullptr );
54 
55  void paintEvent( QPaintEvent *e ) override;
56 
62  void setFormat( const QgsTextFormat &format );
63 
68  QgsTextFormat format() const { return mFormat; }
69 
76  void setScale( double scale );
77 
84  double scale() const { return mScale; }
85 
92  void setMapUnits( QgsUnitTypes::DistanceUnit unit );
93 
99  QgsUnitTypes::DistanceUnit mapUnits() const { return mMapUnits; }
100 
101  private:
102  QgsTextFormat mFormat;
103  QgsRenderContext mContext;
104  double mScale = -1;
106  void updateContext();
107 };
108 
109 #endif // QGSTEXTPREVIEW_H
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsTextPreview::mapUnits
QgsUnitTypes::DistanceUnit mapUnits() const
Returns the map unit type used for previewing format sizes in map units.
Definition: qgstextpreview.h:99
QgsTextFormat
Definition: qgstextformat.h:38
qgsrendercontext.h
QgsUnitTypes
Helper functions for various unit types.
Definition: qgsunittypes.h:38
QgsUnitTypes::DistanceMeters
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
QgsTextPreview
Definition: qgstextpreview.h:39
qgstextformat.h
QgsTextPreview::scale
double scale() const
Returns the scale used for previewing format sizes in map units.
Definition: qgstextpreview.h:84