Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquicktext_p.h
1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKTEXT_P_H
44 #define QQUICKTEXT_P_H
45
46 #include "qquickimplicitsizeitem_p.h"
47
48 #include <private/qtquickglobal_p.h>
49
50 #include <QtGui/qtextoption.h>
51
52 QT_BEGIN_HEADER
53
54 QT_BEGIN_NAMESPACE
55
56 class QQuickTextPrivate;
57 class QQuickTextLine;
58 class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem
59 {
60     Q_OBJECT
61     Q_ENUMS(HAlignment)
62     Q_ENUMS(VAlignment)
63     Q_ENUMS(TextStyle)
64     Q_ENUMS(TextFormat)
65     Q_ENUMS(TextElideMode)
66     Q_ENUMS(WrapMode)
67     Q_ENUMS(LineHeightMode)
68
69     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
70     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
71     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
72     Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged)
73     Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
74     Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
75     Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
76     Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
77     Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
78     Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged)
79     Q_PROPERTY(bool truncated READ truncated NOTIFY truncatedChanged)
80     Q_PROPERTY(int maximumLineCount READ maximumLineCount WRITE setMaximumLineCount NOTIFY maximumLineCountChanged RESET resetMaximumLineCount)
81
82     Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
83     Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode?
84     Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
85     Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
86     Q_PROPERTY(qreal lineHeight READ lineHeight WRITE setLineHeight NOTIFY lineHeightChanged)
87     Q_PROPERTY(LineHeightMode lineHeightMode READ lineHeightMode WRITE setLineHeightMode NOTIFY lineHeightModeChanged)
88     Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged)
89
90 public:
91     QQuickText(QQuickItem *parent=0);
92     ~QQuickText();
93
94     enum HAlignment { AlignLeft = Qt::AlignLeft,
95                        AlignRight = Qt::AlignRight,
96                        AlignHCenter = Qt::AlignHCenter,
97                        AlignJustify = Qt::AlignJustify };
98     enum VAlignment { AlignTop = Qt::AlignTop,
99                        AlignBottom = Qt::AlignBottom,
100                        AlignVCenter = Qt::AlignVCenter };
101     enum TextStyle { Normal,
102                       Outline,
103                       Raised,
104                       Sunken };
105     enum TextFormat { PlainText = Qt::PlainText,
106                        RichText = Qt::RichText,
107                        AutoText = Qt::AutoText,
108                        StyledText = 4 };
109     enum TextElideMode { ElideLeft = Qt::ElideLeft,
110                           ElideRight = Qt::ElideRight,
111                           ElideMiddle = Qt::ElideMiddle,
112                           ElideNone = Qt::ElideNone };
113
114     enum WrapMode { NoWrap = QTextOption::NoWrap,
115                     WordWrap = QTextOption::WordWrap,
116                     WrapAnywhere = QTextOption::WrapAnywhere,
117                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
118                     Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
119                   };
120
121     enum LineHeightMode { ProportionalHeight, FixedHeight };
122
123     QString text() const;
124     void setText(const QString &);
125
126     QFont font() const;
127     void setFont(const QFont &font);
128
129     QColor color() const;
130     void setColor(const QColor &c);
131
132     TextStyle style() const;
133     void setStyle(TextStyle style);
134
135     QColor styleColor() const;
136     void setStyleColor(const QColor &c);
137
138     HAlignment hAlign() const;
139     void setHAlign(HAlignment align);
140     void resetHAlign();
141     HAlignment effectiveHAlign() const;
142
143     VAlignment vAlign() const;
144     void setVAlign(VAlignment align);
145
146     WrapMode wrapMode() const;
147     void setWrapMode(WrapMode w);
148
149     int lineCount() const;
150     bool truncated() const;
151
152     int maximumLineCount() const;
153     void setMaximumLineCount(int lines);
154     void resetMaximumLineCount();
155
156     TextFormat textFormat() const;
157     void setTextFormat(TextFormat format);
158
159     TextElideMode elideMode() const;
160     void setElideMode(TextElideMode);
161
162     qreal lineHeight() const;
163     void setLineHeight(qreal lineHeight);
164
165     LineHeightMode lineHeightMode() const;
166     void setLineHeightMode(LineHeightMode);
167
168     QUrl baseUrl() const;
169     void setBaseUrl(const QUrl &url);
170     void resetBaseUrl();
171
172     virtual void componentComplete();
173
174     int resourcesLoading() const; // mainly for testing
175
176     qreal paintedWidth() const;
177     qreal paintedHeight() const;
178
179     QRectF boundingRect() const;
180     Q_INVOKABLE void doLayout();
181
182 Q_SIGNALS:
183     void textChanged(const QString &text);
184     void linkActivated(const QString &link);
185     void fontChanged(const QFont &font);
186     void colorChanged(const QColor &color);
187     void styleChanged(TextStyle style);
188     void styleColorChanged(const QColor &color);
189     void horizontalAlignmentChanged(HAlignment alignment);
190     void verticalAlignmentChanged(VAlignment alignment);
191     void wrapModeChanged();
192     void lineCountChanged();
193     void truncatedChanged();
194     void maximumLineCountChanged();
195     void textFormatChanged(TextFormat textFormat);
196     void elideModeChanged(TextElideMode mode);
197     void paintedSizeChanged();
198     void lineHeightChanged(qreal lineHeight);
199     void lineHeightModeChanged(LineHeightMode mode);
200     void effectiveHorizontalAlignmentChanged();
201     void lineLaidOut(QQuickTextLine *line);
202     void baseUrlChanged();
203
204 protected:
205     void mousePressEvent(QMouseEvent *event);
206     void mouseReleaseEvent(QMouseEvent *event);
207     virtual void geometryChanged(const QRectF &newGeometry,
208                                  const QRectF &oldGeometry);
209     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
210     virtual bool event(QEvent *);
211
212 private Q_SLOTS:
213     void q_imagesLoaded();
214     void triggerPreprocess();
215
216 private:
217     Q_DISABLE_COPY(QQuickText)
218     Q_DECLARE_PRIVATE(QQuickText)
219 };
220
221 class QTextLine;
222 class Q_AUTOTEST_EXPORT QQuickTextLine : public QObject
223 {
224     Q_OBJECT
225     Q_PROPERTY(int number READ number)
226     Q_PROPERTY(qreal width READ width WRITE setWidth)
227     Q_PROPERTY(qreal height READ height WRITE setHeight)
228     Q_PROPERTY(qreal x READ x WRITE setX)
229     Q_PROPERTY(qreal y READ y WRITE setY)
230
231 public:
232     QQuickTextLine();
233
234     void setLine(QTextLine* line);
235     int number() const;
236
237     qreal width() const;
238     void setWidth(qreal width);
239
240     qreal height() const;
241     void setHeight(qreal height);
242
243     qreal x() const;
244     void setX(qreal x);
245
246     qreal y() const;
247     void setY(qreal y);
248
249 private:
250     QTextLine *m_line;
251     qreal m_height;
252 };
253
254 QT_END_NAMESPACE
255
256 QML_DECLARE_TYPE(QQuickText)
257 QML_DECLARE_TYPE(QQuickTextLine)
258
259 QT_END_HEADER
260
261 #endif // QQUICKTEXT_P_H