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 |
|
---|
19 | class QColor;
|
---|
20 | class QPen;
|
---|
21 | class QBrush;
|
---|
22 | class QRectF;
|
---|
23 | class QPainter;
|
---|
24 | class 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 |
|
---|
51 | class QWT_EXPORT QwtText
|
---|
52 | {
|
---|
53 | public:
|
---|
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 former Qt solutions package.
|
---|
84 | To enable MathML support the following code needs to be added to the
|
---|
85 | application:
|
---|
86 |
|
---|
87 | \code
|
---|
88 | QwtText::setTextEngine( QwtText::MathMLText, new QwtMathMLTextEngine() );
|
---|
89 | \endcode
|
---|
90 | */
|
---|
91 | MathMLText,
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine
|
---|
95 | to display the text ( not implemented yet ).
|
---|
96 | */
|
---|
97 | TeXText,
|
---|
98 |
|
---|
99 | /*!
|
---|
100 | The number of text formats can be extended using setTextEngine.
|
---|
101 | Formats >= QwtText::OtherFormat are not used by Qwt.
|
---|
102 | */
|
---|
103 | OtherFormat = 100
|
---|
104 | };
|
---|
105 |
|
---|
106 | /*!
|
---|
107 | \brief Paint Attributes
|
---|
108 |
|
---|
109 | Font and color and background are optional attributes of a QwtText.
|
---|
110 | The paint attributes hold the information, if they are set.
|
---|
111 | */
|
---|
112 | enum PaintAttribute
|
---|
113 | {
|
---|
114 | //! The text has an individual font.
|
---|
115 | PaintUsingTextFont = 0x01,
|
---|
116 |
|
---|
117 | //! The text has an individual color.
|
---|
118 | PaintUsingTextColor = 0x02,
|
---|
119 |
|
---|
120 | //! The text has an individual background.
|
---|
121 | PaintBackground = 0x04
|
---|
122 | };
|
---|
123 |
|
---|
124 | //! Paint attributes
|
---|
125 | typedef QFlags<PaintAttribute> PaintAttributes;
|
---|
126 |
|
---|
127 | /*!
|
---|
128 | \brief Layout Attributes
|
---|
129 | The layout attributes affects some aspects of the layout of the text.
|
---|
130 | */
|
---|
131 | enum LayoutAttribute
|
---|
132 | {
|
---|
133 | /*!
|
---|
134 | Layout the text without its margins. This mode is useful if a
|
---|
135 | text needs to be aligned accurately, like the tick labels of a scale.
|
---|
136 | If QwtTextEngine::textMargins is not implemented for the format
|
---|
137 | of the text, MinimumLayout has no effect.
|
---|
138 | */
|
---|
139 | MinimumLayout = 0x01
|
---|
140 | };
|
---|
141 |
|
---|
142 | //! Layout attributes
|
---|
143 | typedef QFlags<LayoutAttribute> LayoutAttributes;
|
---|
144 |
|
---|
145 | QwtText( const QString & = QString(),
|
---|
146 | TextFormat textFormat = AutoText );
|
---|
147 | QwtText( const QwtText & );
|
---|
148 | ~QwtText();
|
---|
149 |
|
---|
150 | QwtText &operator=( const QwtText & );
|
---|
151 |
|
---|
152 | bool operator==( const QwtText & ) const;
|
---|
153 | bool operator!=( const QwtText & ) const;
|
---|
154 |
|
---|
155 | void setText( const QString &,
|
---|
156 | QwtText::TextFormat textFormat = AutoText );
|
---|
157 | QString text() const;
|
---|
158 |
|
---|
159 | bool isNull() const;
|
---|
160 | bool isEmpty() const;
|
---|
161 |
|
---|
162 | void setFont( const QFont & );
|
---|
163 | QFont font() const;
|
---|
164 |
|
---|
165 | QFont usedFont( const QFont & ) const;
|
---|
166 |
|
---|
167 | void setRenderFlags( int );
|
---|
168 | int renderFlags() const;
|
---|
169 |
|
---|
170 | void setColor( const QColor & );
|
---|
171 | QColor color() const;
|
---|
172 |
|
---|
173 | QColor usedColor( const QColor & ) const;
|
---|
174 |
|
---|
175 | void setBorderRadius( double );
|
---|
176 | double borderRadius() const;
|
---|
177 |
|
---|
178 | void setBorderPen( const QPen & );
|
---|
179 | QPen borderPen() const;
|
---|
180 |
|
---|
181 | void setBackgroundBrush( const QBrush & );
|
---|
182 | QBrush backgroundBrush() const;
|
---|
183 |
|
---|
184 | void setPaintAttribute( PaintAttribute, bool on = true );
|
---|
185 | bool testPaintAttribute( PaintAttribute ) const;
|
---|
186 |
|
---|
187 | void setLayoutAttribute( LayoutAttribute, bool on = true );
|
---|
188 | bool testLayoutAttribute( LayoutAttribute ) const;
|
---|
189 |
|
---|
190 | double heightForWidth( double width, const QFont & = QFont() ) const;
|
---|
191 | QSizeF textSize( const QFont & = QFont() ) const;
|
---|
192 |
|
---|
193 | void draw( QPainter *painter, const QRectF &rect ) const;
|
---|
194 |
|
---|
195 | static const QwtTextEngine *textEngine(
|
---|
196 | const QString &text, QwtText::TextFormat = AutoText );
|
---|
197 |
|
---|
198 | static const QwtTextEngine *textEngine( QwtText::TextFormat );
|
---|
199 | static void setTextEngine( QwtText::TextFormat, QwtTextEngine * );
|
---|
200 |
|
---|
201 | private:
|
---|
202 | class PrivateData;
|
---|
203 | PrivateData *d_data;
|
---|
204 |
|
---|
205 | class LayoutCache;
|
---|
206 | LayoutCache *d_layoutCache;
|
---|
207 | };
|
---|
208 |
|
---|
209 | //! \return text().isNull()
|
---|
210 | inline bool QwtText::isNull() const
|
---|
211 | {
|
---|
212 | return text().isNull();
|
---|
213 | }
|
---|
214 |
|
---|
215 | //! \return text().isEmpty()
|
---|
216 | inline bool QwtText::isEmpty() const
|
---|
217 | {
|
---|
218 | return text().isEmpty();
|
---|
219 | }
|
---|
220 |
|
---|
221 | Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::PaintAttributes )
|
---|
222 | Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::LayoutAttributes )
|
---|
223 |
|
---|
224 | Q_DECLARE_METATYPE( QwtText )
|
---|
225 |
|
---|
226 | #endif
|
---|