1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
41 ****************************************************************************/
43 #ifndef QQUICKTEXT_P_H
44 #define QQUICKTEXT_P_H
46 #include "qquickimplicitsizeitem_p.h"
48 #include <private/qtquickglobal_p.h>
50 #include <QtGui/qtextoption.h>
56 class QQuickTextPrivate;
58 class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem
65 Q_ENUMS(TextElideMode)
67 Q_ENUMS(LineHeightMode)
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)
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)
91 QQuickText(QQuickItem *parent=0);
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,
105 enum TextFormat { PlainText = Qt::PlainText,
106 RichText = Qt::RichText,
107 AutoText = Qt::AutoText,
109 enum TextElideMode { ElideLeft = Qt::ElideLeft,
110 ElideRight = Qt::ElideRight,
111 ElideMiddle = Qt::ElideMiddle,
112 ElideNone = Qt::ElideNone };
114 enum WrapMode { NoWrap = QTextOption::NoWrap,
115 WordWrap = QTextOption::WordWrap,
116 WrapAnywhere = QTextOption::WrapAnywhere,
117 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
118 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
121 enum LineHeightMode { ProportionalHeight, FixedHeight };
123 QString text() const;
124 void setText(const QString &);
127 void setFont(const QFont &font);
129 QColor color() const;
130 void setColor(const QColor &c);
132 TextStyle style() const;
133 void setStyle(TextStyle style);
135 QColor styleColor() const;
136 void setStyleColor(const QColor &c);
138 HAlignment hAlign() const;
139 void setHAlign(HAlignment align);
141 HAlignment effectiveHAlign() const;
143 VAlignment vAlign() const;
144 void setVAlign(VAlignment align);
146 WrapMode wrapMode() const;
147 void setWrapMode(WrapMode w);
149 int lineCount() const;
150 bool truncated() const;
152 int maximumLineCount() const;
153 void setMaximumLineCount(int lines);
154 void resetMaximumLineCount();
156 TextFormat textFormat() const;
157 void setTextFormat(TextFormat format);
159 TextElideMode elideMode() const;
160 void setElideMode(TextElideMode);
162 qreal lineHeight() const;
163 void setLineHeight(qreal lineHeight);
165 LineHeightMode lineHeightMode() const;
166 void setLineHeightMode(LineHeightMode);
168 QUrl baseUrl() const;
169 void setBaseUrl(const QUrl &url);
172 virtual void componentComplete();
174 int resourcesLoading() const; // mainly for testing
176 qreal paintedWidth() const;
177 qreal paintedHeight() const;
179 QRectF boundingRect() const;
180 Q_INVOKABLE void doLayout();
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();
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 *);
213 void q_imagesLoaded();
214 void triggerPreprocess();
217 Q_DISABLE_COPY(QQuickText)
218 Q_DECLARE_PRIVATE(QQuickText)
222 class Q_AUTOTEST_EXPORT QQuickTextLine : public QObject
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)
234 void setLine(QTextLine* line);
238 void setWidth(qreal width);
240 qreal height() const;
241 void setHeight(qreal height);
256 QML_DECLARE_TYPE(QQuickText)
257 QML_DECLARE_TYPE(QQuickTextLine)
261 #endif // QQUICKTEXT_P_H