source: ntrip/branches/BNC_2.12/qwt/qwt_text.h@ 8286

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