1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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.
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 QT_MODULE(Declarative)
55 class QDeclarative1TextPrivate;
56 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1Text : public QDeclarative1ImplicitSizeItem
63 Q_ENUMS(TextElideMode)
65 Q_ENUMS(LineHeightMode)
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(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
74 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
75 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
76 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
77 Q_PROPERTY(bool truncated READ truncated NOTIFY truncatedChanged REVISION 1)
78 Q_PROPERTY(int maximumLineCount READ maximumLineCount WRITE setMaximumLineCount NOTIFY maximumLineCountChanged RESET resetMaximumLineCount REVISION 1)
80 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
81 Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode?
82 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
83 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
84 Q_PROPERTY(qreal lineHeight READ lineHeight WRITE setLineHeight NOTIFY lineHeightChanged REVISION 1)
85 Q_PROPERTY(LineHeightMode lineHeightMode READ lineHeightMode WRITE setLineHeightMode NOTIFY lineHeightModeChanged REVISION 1)
88 QDeclarative1Text(QDeclarativeItem *parent=0);
91 enum HAlignment { AlignLeft = Qt::AlignLeft,
92 AlignRight = Qt::AlignRight,
93 AlignHCenter = Qt::AlignHCenter,
94 AlignJustify = Qt::AlignJustify }; // ### VERSIONING: Only in QtQuick 1.1
95 enum VAlignment { AlignTop = Qt::AlignTop,
96 AlignBottom = Qt::AlignBottom,
97 AlignVCenter = Qt::AlignVCenter };
98 enum TextStyle { Normal,
102 enum TextFormat { PlainText = Qt::PlainText,
103 RichText = Qt::RichText,
104 AutoText = Qt::AutoText,
106 enum TextElideMode { ElideLeft = Qt::ElideLeft,
107 ElideRight = Qt::ElideRight,
108 ElideMiddle = Qt::ElideMiddle,
109 ElideNone = Qt::ElideNone };
111 enum WrapMode { NoWrap = QTextOption::NoWrap,
112 WordWrap = QTextOption::WordWrap,
113 WrapAnywhere = QTextOption::WrapAnywhere,
114 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
115 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
118 enum LineHeightMode { ProportionalHeight, FixedHeight };
120 QString text() const;
121 void setText(const QString &);
124 void setFont(const QFont &font);
126 QColor color() const;
127 void setColor(const QColor &c);
129 TextStyle style() const;
130 void setStyle(TextStyle style);
132 QColor styleColor() const;
133 void setStyleColor(const QColor &c);
135 HAlignment hAlign() const;
136 void setHAlign(HAlignment align);
138 HAlignment effectiveHAlign() const;
140 VAlignment vAlign() const;
141 void setVAlign(VAlignment align);
143 WrapMode wrapMode() const;
144 void setWrapMode(WrapMode w);
146 int lineCount() const;
147 bool truncated() const;
149 int maximumLineCount() const;
150 void setMaximumLineCount(int lines);
151 void resetMaximumLineCount();
153 TextFormat textFormat() const;
154 void setTextFormat(TextFormat format);
156 TextElideMode elideMode() const;
157 void setElideMode(TextElideMode);
159 qreal lineHeight() const;
160 void setLineHeight(qreal lineHeight);
162 LineHeightMode lineHeightMode() const;
163 void setLineHeightMode(LineHeightMode);
165 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
167 virtual void componentComplete();
169 int resourcesLoading() const; // mainly for testing
171 qreal paintedWidth() const;
172 qreal paintedHeight() const;
174 QRectF boundingRect() const;
177 void textChanged(const QString &text);
178 void linkActivated(const QString &link);
179 void fontChanged(const QFont &font);
180 void colorChanged(const QColor &color);
181 void styleChanged(TextStyle style);
182 void styleColorChanged(const QColor &color);
183 void horizontalAlignmentChanged(HAlignment alignment);
184 void verticalAlignmentChanged(VAlignment alignment);
185 void wrapModeChanged();
186 Q_REVISION(1) void lineCountChanged();
187 Q_REVISION(1) void truncatedChanged();
188 Q_REVISION(1) void maximumLineCountChanged();
189 void textFormatChanged(TextFormat textFormat);
190 void elideModeChanged(TextElideMode mode);
191 void paintedSizeChanged();
192 Q_REVISION(1) void lineHeightChanged(qreal lineHeight);
193 Q_REVISION(1) void lineHeightModeChanged(LineHeightMode mode);
194 Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
197 void mousePressEvent(QGraphicsSceneMouseEvent *event);
198 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
199 virtual void geometryChanged(const QRectF &newGeometry,
200 const QRectF &oldGeometry);
203 Q_DISABLE_COPY(QDeclarative1Text)
204 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Text)
209 QML_DECLARE_TYPE(QDeclarative1Text)