source: ntrip/trunk/BNC/qwt/qwt_text.h@ 9274

Last change on this file since 9274 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 6.0 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_TEXT_H
11#define QWT_TEXT_H
12
13#include "qwt_global.h"
14#include <qstring.h>
15#include <qsize.h>
16#include <qfont.h>
17#include <qmetatype.h>
18
19class QColor;
20class QPen;
21class QBrush;
22class QRectF;
23class QPainter;
24class QwtTextEngine;
25
26/*!
27 \brief A class representing a text
28
29 A QwtText is a text including a set of attributes how to render it.
30
31 - Format\n
32 A text might include control sequences (f.e tags) describing
33 how to render it. Each format (f.e MathML, TeX, Qt Rich Text)
34 has its own set of control sequences, that can be handles by
35 a special QwtTextEngine for this format.
36 - Background\n
37 A text might have a background, defined by a QPen and QBrush
38 to improve its visibility. The corners of the background might
39 be rounded.
40 - Font\n
41 A text might have an individual font.
42 - Color\n
43 A text might have an individual color.
44 - Render Flags\n
45 Flags from Qt::AlignmentFlag and Qt::TextFlag used like in
46 QPainter::drawText().
47
48 \sa QwtTextEngine, QwtTextLabel
49*/
50
51class QWT_EXPORT QwtText
52{
53public:
54
55 /*!
56 \brief Text format
57
58 The text format defines the QwtTextEngine, that is used to render
59 the text.
60
61 \sa QwtTextEngine, setTextEngine()
62 */
63
64 enum TextFormat
65 {
66 /*!
67 The text format is determined using QwtTextEngine::mightRender() for
68 all available text engines in increasing order > PlainText.
69 If none of the text engines can render the text is rendered
70 like QwtText::PlainText.
71 */
72 AutoText = 0,
73
74 //! Draw the text as it is, using a QwtPlainTextEngine.
75 PlainText,
76
77 //! Use the Scribe framework (Qt Rich Text) to render the text.
78 RichText,
79
80 /*!
81 Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine
82 to display the text. The Qwt MathML extension offers such an engine
83 based on the MathML renderer of the Qt solutions package.
84 To enable MathML support the following code needs to be added to the
85 application:
86\verbatim QwtText::setTextEngine(QwtText::MathMLText, new QwtMathMLTextEngine()); \endverbatim
87 */
88 MathMLText,
89
90 /*!
91 Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine
92 to display the text ( not implemented yet ).
93 */
94 TeXText,
95
96 /*!
97 The number of text formats can be extended using setTextEngine.
98 Formats >= QwtText::OtherFormat are not used by Qwt.
99 */
100 OtherFormat = 100
101 };
102
103 /*!
104 \brief Paint Attributes
105
106 Font and color and background are optional attributes of a QwtText.
107 The paint attributes hold the information, if they are set.
108 */
109 enum PaintAttribute
110 {
111 //! The text has an individual font.
112 PaintUsingTextFont = 0x01,
113
114 //! The text has an individual color.
115 PaintUsingTextColor = 0x02,
116
117 //! The text has an individual background.
118 PaintBackground = 0x04
119 };
120
121 //! Paint attributes
122 typedef QFlags<PaintAttribute> PaintAttributes;
123
124 /*!
125 \brief Layout Attributes
126 The layout attributes affects some aspects of the layout of the text.
127 */
128 enum LayoutAttribute
129 {
130 /*!
131 Layout the text without its margins. This mode is useful if a
132 text needs to be aligned accurately, like the tick labels of a scale.
133 If QwtTextEngine::textMargins is not implemented for the format
134 of the text, MinimumLayout has no effect.
135 */
136 MinimumLayout = 0x01
137 };
138
139 //! Layout attributes
140 typedef QFlags<LayoutAttribute> LayoutAttributes;
141
142 QwtText( const QString & = QString::null,
143 TextFormat textFormat = AutoText );
144 QwtText( const QwtText & );
145 ~QwtText();
146
147 QwtText &operator=( const QwtText & );
148
149 bool operator==( const QwtText & ) const;
150 bool operator!=( const QwtText & ) const;
151
152 void setText( const QString &,
153 QwtText::TextFormat textFormat = AutoText );
154 QString text() const;
155
156 bool isNull() const;
157 bool isEmpty() const;
158
159 void setFont( const QFont & );
160 QFont font() const;
161
162 QFont usedFont( const QFont & ) const;
163
164 void setRenderFlags( int flags );
165 int renderFlags() const;
166
167 void setColor( const QColor & );
168 QColor color() const;
169
170 QColor usedColor( const QColor & ) const;
171
172 void setBorderRadius( double );
173 double borderRadius() const;
174
175 void setBorderPen( const QPen & );
176 QPen borderPen() const;
177
178 void setBackgroundBrush( const QBrush & );
179 QBrush backgroundBrush() const;
180
181 void setPaintAttribute( PaintAttribute, bool on = true );
182 bool testPaintAttribute( PaintAttribute ) const;
183
184 void setLayoutAttribute( LayoutAttribute, bool on = true );
185 bool testLayoutAttribute( LayoutAttribute ) const;
186
187 double heightForWidth( double width, const QFont & = QFont() ) const;
188 QSizeF textSize( const QFont & = QFont() ) const;
189
190 void draw( QPainter *painter, const QRectF &rect ) const;
191
192 static const QwtTextEngine *textEngine(
193 const QString &text, QwtText::TextFormat = AutoText );
194
195 static const QwtTextEngine *textEngine( QwtText::TextFormat );
196 static void setTextEngine( QwtText::TextFormat, QwtTextEngine * );
197
198private:
199 class PrivateData;
200 PrivateData *d_data;
201
202 class LayoutCache;
203 LayoutCache *d_layoutCache;
204};
205
206//! \return text().isNull()
207inline bool QwtText::isNull() const
208{
209 return text().isNull();
210}
211
212//! \return text().isEmpty()
213inline bool QwtText::isEmpty() const
214{
215 return text().isEmpty();
216}
217
218Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::PaintAttributes )
219Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::LayoutAttributes )
220
221Q_DECLARE_METATYPE( QwtText )
222
223#endif
Note: See TracBrowser for help on using the repository browser.