1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVETEXT_H
43 #define QDECLARATIVETEXT_H
44
45 #include <QtGui/qtextoption.h>
46 #include "qdeclarativeimplicitsizeitem_p.h"
47
48 #include <private/qdeclarativeglobal_p.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
QT_MODULE(Declarative)54 QT_MODULE(Declarative)
55 class QDeclarativeTextPrivate;
56 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeText : public QDeclarativeImplicitSizeItem
57 {
58 Q_OBJECT
59 Q_ENUMS(HAlignment)
60 Q_ENUMS(VAlignment)
61 Q_ENUMS(TextStyle)
62 Q_ENUMS(TextFormat)
63 Q_ENUMS(TextElideMode)
64 Q_ENUMS(WrapMode)
65 Q_ENUMS(LineHeightMode)
66
67 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
68 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
69 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
70 Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged)
71 Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
72 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
73 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
74 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
75 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
76 Q_PROPERTY(bool truncated READ truncated NOTIFY truncatedChanged REVISION 1)
77 Q_PROPERTY(int maximumLineCount READ maximumLineCount WRITE setMaximumLineCount NOTIFY maximumLineCountChanged RESET resetMaximumLineCount REVISION 1)
78
79 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
80 Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode?
81 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
82 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
83 Q_PROPERTY(qreal lineHeight READ lineHeight WRITE setLineHeight NOTIFY lineHeightChanged REVISION 1)
84 Q_PROPERTY(LineHeightMode lineHeightMode READ lineHeightMode WRITE setLineHeightMode NOTIFY lineHeightModeChanged REVISION 1)
85
86 public:
87 QDeclarativeText(QDeclarativeItem *parent=0);
88 ~QDeclarativeText();
89
90 enum HAlignment { AlignLeft = Qt::AlignLeft,
91 AlignRight = Qt::AlignRight,
92 AlignHCenter = Qt::AlignHCenter,
93 AlignJustify = Qt::AlignJustify }; // ### VERSIONING: Only in QtQuick 1.1
94 enum VAlignment { AlignTop = Qt::AlignTop,
95 AlignBottom = Qt::AlignBottom,
96 AlignVCenter = Qt::AlignVCenter };
97 enum TextStyle { Normal,
98 Outline,
99 Raised,
100 Sunken };
101 enum TextFormat { PlainText = Qt::PlainText,
102 RichText = Qt::RichText,
103 AutoText = Qt::AutoText,
104 StyledText = 4 };
105 enum TextElideMode { ElideLeft = Qt::ElideLeft,
106 ElideRight = Qt::ElideRight,
107 ElideMiddle = Qt::ElideMiddle,
108 ElideNone = Qt::ElideNone };
109
110 enum WrapMode { NoWrap = QTextOption::NoWrap,
111 WordWrap = QTextOption::WordWrap,
112 WrapAnywhere = QTextOption::WrapAnywhere,
113 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
114 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
115 };
116
117 enum LineHeightMode { ProportionalHeight, FixedHeight };
118
119 QString text() const;
120 void setText(const QString &);
121
122 QFont font() const;
123 void setFont(const QFont &font);
124
125 QColor color() const;
126 void setColor(const QColor &c);
127
128 TextStyle style() const;
129 void setStyle(TextStyle style);
130
131 QColor styleColor() const;
132 void setStyleColor(const QColor &c);
133
134 HAlignment hAlign() const;
135 void setHAlign(HAlignment align);
136 void resetHAlign();
137 HAlignment effectiveHAlign() const;
138
139 VAlignment vAlign() const;
140 void setVAlign(VAlignment align);
141
142 WrapMode wrapMode() const;
143 void setWrapMode(WrapMode w);
144
145 int lineCount() const;
146 bool truncated() const;
147
148 int maximumLineCount() const;
149 void setMaximumLineCount(int lines);
150 void resetMaximumLineCount();
151
152 TextFormat textFormat() const;
153 void setTextFormat(TextFormat format);
154
155 TextElideMode elideMode() const;
156 void setElideMode(TextElideMode);
157
158 qreal lineHeight() const;
159 void setLineHeight(qreal lineHeight);
160
161 LineHeightMode lineHeightMode() const;
162 void setLineHeightMode(LineHeightMode);
163
164 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
165
166 virtual void componentComplete();
167
168 int resourcesLoading() const; // mainly for testing
169
170 qreal paintedWidth() const;
171 qreal paintedHeight() const;
172
173 QRectF boundingRect() const;
174
175 Q_SIGNALS:
176 void textChanged(const QString &text);
177 void linkActivated(const QString &link);
178 void fontChanged(const QFont &font);
179 void colorChanged(const QColor &color);
180 void styleChanged(TextStyle style);
181 void styleColorChanged(const QColor &color);
182 void horizontalAlignmentChanged(HAlignment alignment);
183 void verticalAlignmentChanged(VAlignment alignment);
184 void wrapModeChanged();
185 Q_REVISION(1) void lineCountChanged();
186 Q_REVISION(1) void truncatedChanged();
187 Q_REVISION(1) void maximumLineCountChanged();
188 void textFormatChanged(TextFormat textFormat);
189 void elideModeChanged(TextElideMode mode);
190 void paintedSizeChanged();
191 Q_REVISION(1) void lineHeightChanged(qreal lineHeight);
192 Q_REVISION(1) void lineHeightModeChanged(LineHeightMode mode);
193
194 protected:
195 void mousePressEvent(QGraphicsSceneMouseEvent *event);
196 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
197 virtual void geometryChanged(const QRectF &newGeometry,
198 const QRectF &oldGeometry);
199
200 private:
201 Q_DISABLE_COPY(QDeclarativeText)
202 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeText)
203 };
204
205 QT_END_NAMESPACE
206
207 QML_DECLARE_TYPE(QDeclarativeText)
208
209 QT_END_HEADER
210
211 #endif
212