1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETEXT_H
43 #define QDECLARATIVETEXT_H
45 #include <QtGui/qtextoption.h>
46 #include "qdeclarativeimplicitsizeitem_p.h"
48 #include <QtDeclarative/private/qdeclarativeglobal_p.h>
54 class QDeclarative1TextPrivate;
55 class Q_QTQUICK1_EXPORT QDeclarative1Text : public QDeclarative1ImplicitSizeItem
62 Q_ENUMS(TextElideMode)
64 Q_ENUMS(LineHeightMode)
66 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
67 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
68 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
69 Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged)
70 Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
71 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
72 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
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)
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)
87 QDeclarative1Text(QDeclarativeItem *parent=0);
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,
101 enum TextFormat { PlainText = Qt::PlainText,
102 RichText = Qt::RichText,
103 AutoText = Qt::AutoText,
105 enum TextElideMode { ElideLeft = Qt::ElideLeft,
106 ElideRight = Qt::ElideRight,
107 ElideMiddle = Qt::ElideMiddle,
108 ElideNone = Qt::ElideNone };
110 enum WrapMode { NoWrap = QTextOption::NoWrap,
111 WordWrap = QTextOption::WordWrap,
112 WrapAnywhere = QTextOption::WrapAnywhere,
113 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
114 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
117 enum LineHeightMode { ProportionalHeight, FixedHeight };
119 QString text() const;
120 void setText(const QString &);
123 void setFont(const QFont &font);
125 QColor color() const;
126 void setColor(const QColor &c);
128 TextStyle style() const;
129 void setStyle(TextStyle style);
131 QColor styleColor() const;
132 void setStyleColor(const QColor &c);
134 HAlignment hAlign() const;
135 void setHAlign(HAlignment align);
137 HAlignment effectiveHAlign() const;
139 VAlignment vAlign() const;
140 void setVAlign(VAlignment align);
142 WrapMode wrapMode() const;
143 void setWrapMode(WrapMode w);
145 int lineCount() const;
146 bool truncated() const;
148 int maximumLineCount() const;
149 void setMaximumLineCount(int lines);
150 void resetMaximumLineCount();
152 TextFormat textFormat() const;
153 void setTextFormat(TextFormat format);
155 TextElideMode elideMode() const;
156 void setElideMode(TextElideMode);
158 qreal lineHeight() const;
159 void setLineHeight(qreal lineHeight);
161 LineHeightMode lineHeightMode() const;
162 void setLineHeightMode(LineHeightMode);
164 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
166 virtual void componentComplete();
168 int resourcesLoading() const; // mainly for testing
170 qreal paintedWidth() const;
171 qreal paintedHeight() const;
173 QRectF boundingRect() const;
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 Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
196 void mousePressEvent(QGraphicsSceneMouseEvent *event);
197 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
198 virtual void geometryChanged(const QRectF &newGeometry,
199 const QRectF &oldGeometry);
202 Q_DISABLE_COPY(QDeclarative1Text)
203 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Text)
208 QML_DECLARE_TYPE(QDeclarative1Text)