e0ed20becd8e527aa889baf2047db0e0bb8492ba
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativetext_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 class QDeclarative1TextPrivate;
55 class Q_QTQUICK1_EXPORT QDeclarative1Text : public QDeclarative1ImplicitSizeItem
56 {
57     Q_OBJECT
58     Q_ENUMS(HAlignment)
59     Q_ENUMS(VAlignment)
60     Q_ENUMS(TextStyle)
61     Q_ENUMS(TextFormat)
62     Q_ENUMS(TextElideMode)
63     Q_ENUMS(WrapMode)
64     Q_ENUMS(LineHeightMode)
65
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)
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     QDeclarative1Text(QDeclarativeItem *parent=0);
88     ~QDeclarative1Text();
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     Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
194
195 protected:
196     void mousePressEvent(QGraphicsSceneMouseEvent *event);
197     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
198     virtual void geometryChanged(const QRectF &newGeometry,
199                                  const QRectF &oldGeometry);
200
201 private:
202     Q_DISABLE_COPY(QDeclarative1Text)
203     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Text)
204 };
205
206 QT_END_NAMESPACE
207
208 QML_DECLARE_TYPE(QDeclarative1Text)
209
210 QT_END_HEADER
211
212 #endif