Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativetext_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 ** $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 <QtDeclarative/private/qdeclarativeglobal_p.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Declarative)
55 class QDeclarative1TextPrivate;
56 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1Text : public QDeclarative1ImplicitSizeItem
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(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)
79
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)
86
87 public:
88     QDeclarative1Text(QDeclarativeItem *parent=0);
89     ~QDeclarative1Text();
90
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,
99                       Outline,
100                       Raised,
101                       Sunken };
102     enum TextFormat { PlainText = Qt::PlainText,
103                        RichText = Qt::RichText,
104                        AutoText = Qt::AutoText,
105                        StyledText = 4 };
106     enum TextElideMode { ElideLeft = Qt::ElideLeft,
107                           ElideRight = Qt::ElideRight,
108                           ElideMiddle = Qt::ElideMiddle,
109                           ElideNone = Qt::ElideNone };
110
111     enum WrapMode { NoWrap = QTextOption::NoWrap,
112                     WordWrap = QTextOption::WordWrap,
113                     WrapAnywhere = QTextOption::WrapAnywhere,
114                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
115                     Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
116                   };
117
118     enum LineHeightMode { ProportionalHeight, FixedHeight };
119
120     QString text() const;
121     void setText(const QString &);
122
123     QFont font() const;
124     void setFont(const QFont &font);
125
126     QColor color() const;
127     void setColor(const QColor &c);
128
129     TextStyle style() const;
130     void setStyle(TextStyle style);
131
132     QColor styleColor() const;
133     void setStyleColor(const QColor &c);
134
135     HAlignment hAlign() const;
136     void setHAlign(HAlignment align);
137     void resetHAlign();
138     HAlignment effectiveHAlign() const;
139
140     VAlignment vAlign() const;
141     void setVAlign(VAlignment align);
142
143     WrapMode wrapMode() const;
144     void setWrapMode(WrapMode w);
145
146     int lineCount() const;
147     bool truncated() const;
148
149     int maximumLineCount() const;
150     void setMaximumLineCount(int lines);
151     void resetMaximumLineCount();
152
153     TextFormat textFormat() const;
154     void setTextFormat(TextFormat format);
155
156     TextElideMode elideMode() const;
157     void setElideMode(TextElideMode);
158
159     qreal lineHeight() const;
160     void setLineHeight(qreal lineHeight);
161
162     LineHeightMode lineHeightMode() const;
163     void setLineHeightMode(LineHeightMode);
164
165     void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
166
167     virtual void componentComplete();
168
169     int resourcesLoading() const; // mainly for testing
170
171     qreal paintedWidth() const;
172     qreal paintedHeight() const;
173
174     QRectF boundingRect() const;
175
176 Q_SIGNALS:
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();
195
196 protected:
197     void mousePressEvent(QGraphicsSceneMouseEvent *event);
198     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
199     virtual void geometryChanged(const QRectF &newGeometry,
200                                  const QRectF &oldGeometry);
201
202 private:
203     Q_DISABLE_COPY(QDeclarative1Text)
204     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Text)
205 };
206
207 QT_END_NAMESPACE
208
209 QML_DECLARE_TYPE(QDeclarative1Text)
210
211 QT_END_HEADER
212
213 #endif