~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.0.2/src/qwt_text.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// vim: expandtab
 
11
 
 
12
#ifndef QWT_TEXT_H
 
13
#define QWT_TEXT_H
 
14
 
 
15
#include <qstring.h>
 
16
#include <qsize.h>
 
17
#include <qfont.h>
 
18
#include "qwt_global.h"
 
19
 
 
20
class QColor;
 
21
class QPen;
 
22
class QBrush;
 
23
class QRect;
 
24
class QPainter;
 
25
class QwtTextEngine;
 
26
 
 
27
/*!
 
28
  \brief A class representing a text
 
29
 
 
30
  A QwtText is a text including a set of attributes how to render it.
 
31
 
 
32
  - Format\n
 
33
    A text might include control sequences (f.e tags) describing
 
34
    how to render it. Each format (f.e MathML, TeX, Qt Rich Text)
 
35
    has its own set of control sequences, that can be handles by
 
36
    a QwtTextEngine for this format.
 
37
  - Background\n
 
38
    A text might have a background, defined by a QPen and QBrush
 
39
    to improve its visibility.
 
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
      - AutoText\n
 
62
        The text format is determined using QwtTextEngine::mightRender for
 
63
        all available text engines in increasing order > PlainText.
 
64
        If none of the text engines can render the text is rendered
 
65
        like PlainText.
 
66
      - PlainText\n
 
67
        Draw the text as it is, using a QwtPlainTextEngine.
 
68
      - RichText\n
 
69
        Use the Scribe framework (Qt Rich Text) to render the text.
 
70
      - MathMLText\n
 
71
        Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine
 
72
        to display the text. The Qwt MathML extension offers such an engine
 
73
        based on the MathML renderer of the Qt solutions package. Unfortunately
 
74
        it is only available for owners of a commercial Qt license.
 
75
      - TeXText\n
 
76
        Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine
 
77
        to display the text. 
 
78
      - OtherFormat\n
 
79
        The number of text formats can be extended using setTextEngine.
 
80
        Formats >= OtherFormat are not used by Qwt.
 
81
 
 
82
      \sa QwtTextEngine, setTextEngine
 
83
    */
 
84
 
 
85
    enum TextFormat
 
86
    {
 
87
        AutoText = 0,
 
88
        
 
89
        PlainText,
 
90
        RichText,
 
91
 
 
92
        MathMLText,
 
93
        TeXText,
 
94
 
 
95
        OtherFormat = 100
 
96
    };
 
97
 
 
98
    /*!
 
99
      \brief Paint Attributes
 
100
 
 
101
      Font and color and background are optional attributes of a QwtText. 
 
102
      The paint attributes hold the information, if they are set.
 
103
 
 
104
      - PaintUsingTextFont\n
 
105
        The text has an individual font.
 
106
      - PaintUsingTextColor\n
 
107
        The text has an individual color.
 
108
      - PaintBackground\n
 
109
        The text has an individual background.
 
110
    */
 
111
    enum PaintAttribute
 
112
    {
 
113
        PaintUsingTextFont = 1,
 
114
        PaintUsingTextColor = 2,
 
115
        PaintBackground = 4
 
116
    };
 
117
 
 
118
    /*!
 
119
      \brief Layout Attributes
 
120
 
 
121
      The layout attributes affects some aspects of the layout of the text.
 
122
 
 
123
      - MinimumLayout\n
 
124
        Layout the text without its margins. This mode is useful if a
 
125
        text needs to be aligned accurately, like the tick labels of a scale.
 
126
        If QwtTextEngine::textMargins is not implemented for the format
 
127
        of the text, MinimumLayout has no effect.
 
128
    */
 
129
    enum LayoutAttribute
 
130
    {
 
131
        MinimumLayout = 1
 
132
    };
 
133
 
 
134
    QwtText(const QString & = QString::null, 
 
135
        TextFormat textFormat = AutoText);
 
136
    QwtText(const QwtText &);
 
137
    ~QwtText();
 
138
 
 
139
    QwtText &operator=(const QwtText &);
 
140
 
 
141
    int operator==(const QwtText &) const;
 
142
    int operator!=(const QwtText &) const;
 
143
 
 
144
    void setText(const QString &, 
 
145
        QwtText::TextFormat textFormat = AutoText);
 
146
    QString text() const;
 
147
 
 
148
    //! \return text().isNull()
 
149
    inline bool isNull() const { return text().isNull(); }
 
150
 
 
151
    //! \return text().isEmpty()
 
152
    inline bool isEmpty() const { return text().isEmpty(); }
 
153
 
 
154
    void setFont(const QFont &);
 
155
    QFont font() const;
 
156
 
 
157
    QFont usedFont(const QFont &) const;
 
158
 
 
159
    void setRenderFlags(int flags);
 
160
    int renderFlags() const;
 
161
 
 
162
    void setColor(const QColor &);
 
163
    QColor color() const;
 
164
 
 
165
    QColor usedColor(const QColor &) const;
 
166
 
 
167
    void setBackgroundPen(const QPen &);
 
168
    QPen backgroundPen() const;
 
169
 
 
170
    void setBackgroundBrush(const QBrush &);
 
171
    QBrush backgroundBrush() const;
 
172
 
 
173
    void setPaintAttribute(PaintAttribute, bool on = true);
 
174
    bool testPaintAttribute(PaintAttribute) const;
 
175
 
 
176
    void setLayoutAttribute(LayoutAttribute, bool on = true);
 
177
    bool testLayoutAttribute(LayoutAttribute) const;
 
178
 
 
179
    int heightForWidth(int width, const QFont & = QFont()) const;
 
180
    QSize textSize(const QFont & = QFont()) const;
 
181
 
 
182
    void draw(QPainter *painter, const QRect &rect) const;
 
183
 
 
184
    static const QwtTextEngine *textEngine(const QString &text,
 
185
        QwtText::TextFormat = AutoText);
 
186
 
 
187
    static const QwtTextEngine *textEngine(QwtText::TextFormat);
 
188
    static void setTextEngine(QwtText::TextFormat, QwtTextEngine *);
 
189
 
 
190
private:
 
191
    class PrivateData;
 
192
    PrivateData *d_data;
 
193
 
 
194
    class LayoutCache;
 
195
    LayoutCache *d_layoutCache;
 
196
};
 
197
 
 
198
#endif