Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativetextedit_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 QDECLARATIVETEXTEDIT_H
43 #define QDECLARATIVETEXTEDIT_H
44
45 #include "private/qdeclarativetext_p.h"
46 #include "private/qdeclarativeimplicitsizeitem_p.h"
47
48 #include <QtGui/qtextdocument.h>
49 #include <QtGui/qtextoption.h>
50 #include <QtGui/qtextcursor.h>
51 #include <QtGui/qtextformat.h>
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57 QT_MODULE(Declarative)
58
59
60 class QDeclarative1TextEditPrivate;
61 class Q_AUTOTEST_EXPORT QDeclarative1TextEdit : public QDeclarative1ImplicitSizePaintedItem
62 {
63     Q_OBJECT
64     Q_ENUMS(VAlignment)
65     Q_ENUMS(HAlignment)
66     Q_ENUMS(TextFormat)
67     Q_ENUMS(WrapMode)
68     Q_ENUMS(SelectionMode)
69
70     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
71     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
72     Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
73     Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
74     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
75     Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
76     Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
77     Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
78     Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
79     Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
80     Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
81     Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
82     Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
83     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
84     Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
85     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
86     Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
87     Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
88     Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
89     Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
90     Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
91     Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
92     Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
93     Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
94     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
95     Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
96     Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged REVISION 1)
97     Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged REVISION 1)
98     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged REVISION 1)
99
100 public:
101     QDeclarative1TextEdit(QDeclarativeItem *parent=0);
102
103     enum HAlignment {
104         AlignLeft = Qt::AlignLeft,
105         AlignRight = Qt::AlignRight,
106         AlignHCenter = Qt::AlignHCenter,
107         AlignJustify = Qt::AlignJustify // ### VERSIONING: Only in QtQuick 1.1
108     };
109
110     enum VAlignment {
111         AlignTop = Qt::AlignTop,
112         AlignBottom = Qt::AlignBottom,
113         AlignVCenter = Qt::AlignVCenter
114     };
115
116     enum TextFormat {
117         PlainText = Qt::PlainText,
118         RichText = Qt::RichText,
119         AutoText = Qt::AutoText
120     };
121
122     enum WrapMode { NoWrap = QTextOption::NoWrap,
123                     WordWrap = QTextOption::WordWrap,
124                     WrapAnywhere = QTextOption::WrapAnywhere,
125                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
126                     Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
127                   };
128
129     enum SelectionMode {
130         SelectCharacters,
131         SelectWords
132     };
133
134     Q_INVOKABLE void openSoftwareInputPanel();
135     Q_INVOKABLE void closeSoftwareInputPanel();
136
137     QString text() const;
138     void setText(const QString &);
139
140     TextFormat textFormat() const;
141     void setTextFormat(TextFormat format);
142
143     QFont font() const;
144     void setFont(const QFont &font);
145
146     QColor color() const;
147     void setColor(const QColor &c);
148
149     QColor selectionColor() const;
150     void setSelectionColor(const QColor &c);
151
152     QColor selectedTextColor() const;
153     void setSelectedTextColor(const QColor &c);
154
155     HAlignment hAlign() const;
156     void setHAlign(HAlignment align);
157     void resetHAlign();
158     HAlignment effectiveHAlign() const;
159
160     VAlignment vAlign() const;
161     void setVAlign(VAlignment align);
162
163     WrapMode wrapMode() const;
164     void setWrapMode(WrapMode w);
165
166     int lineCount() const;
167
168     bool isCursorVisible() const;
169     void setCursorVisible(bool on);
170
171     int cursorPosition() const;
172     void setCursorPosition(int pos);
173
174     QDeclarativeComponent* cursorDelegate() const;
175     void setCursorDelegate(QDeclarativeComponent*);
176
177     int selectionStart() const;
178     int selectionEnd() const;
179
180     QString selectedText() const;
181
182     bool focusOnPress() const;
183     void setFocusOnPress(bool on);
184
185     bool persistentSelection() const;
186     void setPersistentSelection(bool on);
187
188     qreal textMargin() const;
189     void setTextMargin(qreal margin);
190
191     bool selectByMouse() const;
192     void setSelectByMouse(bool);
193
194     SelectionMode mouseSelectionMode() const;
195     void setMouseSelectionMode(SelectionMode mode);
196
197     bool canPaste() const;
198
199     virtual void componentComplete();
200
201     /* FROM EDIT */
202     void setReadOnly(bool);
203     bool isReadOnly() const;
204
205     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
206     Qt::TextInteractionFlags textInteractionFlags() const;
207
208     QRect cursorRectangle() const;
209
210     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
211
212     qreal paintedWidth() const;
213     qreal paintedHeight() const;
214
215     Q_INVOKABLE QRectF positionToRectangle(int) const;
216     Q_INVOKABLE int positionAt(int x, int y) const;
217     Q_INVOKABLE void moveCursorSelection(int pos);
218     Q_INVOKABLE Q_REVISION(1) void moveCursorSelection(int pos, SelectionMode mode);
219
220     QRectF boundingRect() const;
221
222     bool isInputMethodComposing() const;
223
224 Q_SIGNALS:
225     void textChanged(const QString &);
226     void paintedSizeChanged();
227     void cursorPositionChanged();
228     void cursorRectangleChanged();
229     void selectionStartChanged();
230     void selectionEndChanged();
231     void selectionChanged();
232     void colorChanged(const QColor &color);
233     void selectionColorChanged(const QColor &color);
234     void selectedTextColorChanged(const QColor &color);
235     void fontChanged(const QFont &font);
236     void horizontalAlignmentChanged(HAlignment alignment);
237     void verticalAlignmentChanged(VAlignment alignment);
238     void wrapModeChanged();
239     void lineCountChanged();
240     void textFormatChanged(TextFormat textFormat);
241     void readOnlyChanged(bool isReadOnly);
242     void cursorVisibleChanged(bool isCursorVisible);
243     void cursorDelegateChanged();
244     void activeFocusOnPressChanged(bool activeFocusOnPressed);
245     void persistentSelectionChanged(bool isPersistentSelection);
246     void textMarginChanged(qreal textMargin);
247     void selectByMouseChanged(bool selectByMouse);
248     Q_REVISION(1) void mouseSelectionModeChanged(SelectionMode mode);
249     Q_REVISION(1) void linkActivated(const QString &link);
250     Q_REVISION(1) void canPasteChanged();
251     Q_REVISION(1) void inputMethodComposingChanged();
252     Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
253
254 public Q_SLOTS:
255     void selectAll();
256     void selectWord();
257     void select(int start, int end);
258     Q_REVISION(1) void deselect();
259     Q_REVISION(1) bool isRightToLeft(int start, int end);
260 #ifndef QT_NO_CLIPBOARD
261     void cut();
262     void copy();
263     void paste();
264 #endif
265
266 private Q_SLOTS:
267     void updateImgCache(const QRectF &rect);
268     void q_textChanged();
269     void updateSelectionMarkers();
270     void moveCursorDelegate();
271     void loadCursorDelegate();
272     void q_canPasteChanged();
273
274 private:
275     void updateSize();
276     void updateTotalLines();
277
278 protected:
279     virtual void geometryChanged(const QRectF &newGeometry, 
280                                  const QRectF &oldGeometry);
281
282     bool event(QEvent *);
283     void keyPressEvent(QKeyEvent *);
284     void keyReleaseEvent(QKeyEvent *);
285     void focusInEvent(QFocusEvent *event);
286
287     // mouse filter?
288     void mousePressEvent(QGraphicsSceneMouseEvent *event);
289     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
290     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
291     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
292
293     void inputMethodEvent(QInputMethodEvent *e);
294
295     void drawContents(QPainter *, const QRect &);
296 private:
297     Q_DISABLE_COPY(QDeclarative1TextEdit)
298     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextEdit)
299 };
300
301 QT_END_NAMESPACE
302
303 QML_DECLARE_TYPE(QDeclarative1TextEdit)
304
305 QT_END_HEADER
306
307 #endif