Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgtextedit_p.h
1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGTEXTEDIT_P_H
44 #define QSGTEXTEDIT_P_H
45
46 #include "qsgimplicitsizeitem_p.h"
47
48 #include <QtGui/qtextoption.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Declarative)
55
56 class QSGTextEditPrivate;
57 class Q_AUTOTEST_EXPORT QSGTextEdit : public QSGImplicitSizeItem
58 {
59     Q_OBJECT
60     Q_ENUMS(VAlignment)
61     Q_ENUMS(HAlignment)
62     Q_ENUMS(TextFormat)
63     Q_ENUMS(WrapMode)
64     Q_ENUMS(SelectionMode)
65
66     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
67     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
68     Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
69     Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
70     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
71     Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
72     Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
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)
76     Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
77     Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
78     Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
79     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
80     Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
81     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
82     Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
83     Q_PROPERTY(QDeclarativeComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
84     Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
85     Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
86     Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged)
87     Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
88     Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
89     Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
90     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
91     Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
92     Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
93     Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
94     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
95
96 public:
97     QSGTextEdit(QSGItem *parent=0);
98
99     enum HAlignment {
100         AlignLeft = Qt::AlignLeft,
101         AlignRight = Qt::AlignRight,
102         AlignHCenter = Qt::AlignHCenter,
103         AlignJustify = Qt::AlignJustify
104     };
105
106     enum VAlignment {
107         AlignTop = Qt::AlignTop,
108         AlignBottom = Qt::AlignBottom,
109         AlignVCenter = Qt::AlignVCenter
110     };
111
112     enum TextFormat {
113         PlainText = Qt::PlainText,
114         RichText = Qt::RichText,
115         AutoText = Qt::AutoText
116     };
117
118     enum WrapMode { NoWrap = QTextOption::NoWrap,
119                     WordWrap = QTextOption::WordWrap,
120                     WrapAnywhere = QTextOption::WrapAnywhere,
121                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
122                     Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
123                   };
124
125     enum SelectionMode {
126         SelectCharacters,
127         SelectWords
128     };
129
130     Q_INVOKABLE void openSoftwareInputPanel();
131     Q_INVOKABLE void closeSoftwareInputPanel();
132
133     QString text() const;
134     void setText(const QString &);
135
136     TextFormat textFormat() const;
137     void setTextFormat(TextFormat format);
138
139     QFont font() const;
140     void setFont(const QFont &font);
141
142     QColor color() const;
143     void setColor(const QColor &c);
144
145     QColor selectionColor() const;
146     void setSelectionColor(const QColor &c);
147
148     QColor selectedTextColor() const;
149     void setSelectedTextColor(const QColor &c);
150
151     HAlignment hAlign() const;
152     void setHAlign(HAlignment align);
153     void resetHAlign();
154     HAlignment effectiveHAlign() const;
155
156     VAlignment vAlign() const;
157     void setVAlign(VAlignment align);
158
159     WrapMode wrapMode() const;
160     void setWrapMode(WrapMode w);
161
162     int lineCount() const;
163
164     bool isCursorVisible() const;
165     void setCursorVisible(bool on);
166
167     int cursorPosition() const;
168     void setCursorPosition(int pos);
169
170     QDeclarativeComponent* cursorDelegate() const;
171     void setCursorDelegate(QDeclarativeComponent*);
172
173     int selectionStart() const;
174     int selectionEnd() const;
175
176     QString selectedText() const;
177
178     bool focusOnPress() const;
179     void setFocusOnPress(bool on);
180
181     bool persistentSelection() const;
182     void setPersistentSelection(bool on);
183
184     qreal textMargin() const;
185     void setTextMargin(qreal margin);
186
187     bool selectByMouse() const;
188     void setSelectByMouse(bool);
189
190     SelectionMode mouseSelectionMode() const;
191     void setMouseSelectionMode(SelectionMode mode);
192
193     bool canPaste() const;
194
195     virtual void componentComplete();
196
197     /* FROM EDIT */
198     void setReadOnly(bool);
199     bool isReadOnly() const;
200
201     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
202     Qt::TextInteractionFlags textInteractionFlags() const;
203
204     QRect cursorRectangle() const;
205
206     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
207
208     qreal paintedWidth() const;
209     qreal paintedHeight() const;
210
211     Q_INVOKABLE QRectF positionToRectangle(int) const;
212     Q_INVOKABLE int positionAt(int x, int y) const;
213     Q_INVOKABLE void moveCursorSelection(int pos);
214     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
215
216     QRectF boundingRect() const;
217
218     bool isInputMethodComposing() const;
219
220 Q_SIGNALS:
221     void textChanged(const QString &);
222     void paintedSizeChanged();
223     void cursorPositionChanged();
224     void cursorRectangleChanged();
225     void selectionStartChanged();
226     void selectionEndChanged();
227     void selectionChanged();
228     void colorChanged(const QColor &color);
229     void selectionColorChanged(const QColor &color);
230     void selectedTextColorChanged(const QColor &color);
231     void fontChanged(const QFont &font);
232     void horizontalAlignmentChanged(HAlignment alignment);
233     void verticalAlignmentChanged(VAlignment alignment);
234     void wrapModeChanged();
235     void lineCountChanged();
236     void textFormatChanged(TextFormat textFormat);
237     void readOnlyChanged(bool isReadOnly);
238     void cursorVisibleChanged(bool isCursorVisible);
239     void cursorDelegateChanged();
240     void activeFocusOnPressChanged(bool activeFocusOnPressed);
241     void persistentSelectionChanged(bool isPersistentSelection);
242     void textMarginChanged(qreal textMargin);
243     void selectByMouseChanged(bool selectByMouse);
244     void mouseSelectionModeChanged(SelectionMode mode);
245     void linkActivated(const QString &link);
246     void canPasteChanged();
247     void inputMethodComposingChanged();
248     void effectiveHorizontalAlignmentChanged();
249
250 public Q_SLOTS:
251     void selectAll();
252     void selectWord();
253     void select(int start, int end);
254     void deselect();
255     bool isRightToLeft(int start, int end);
256 #ifndef QT_NO_CLIPBOARD
257     void cut();
258     void copy();
259     void paste();
260 #endif
261
262 private Q_SLOTS:
263     void q_textChanged();
264     void updateSelectionMarkers();
265     void moveCursorDelegate();
266     void loadCursorDelegate();
267     void q_canPasteChanged();
268     void updateDocument();
269     void updateCursor();
270
271 private:
272     void updateSize();
273     void updateTotalLines();
274     void updateImageCache(const QRectF &rect = QRectF());
275
276 protected:
277     virtual void geometryChanged(const QRectF &newGeometry,
278                                  const QRectF &oldGeometry);
279
280     bool event(QEvent *);
281     void keyPressEvent(QKeyEvent *);
282     void keyReleaseEvent(QKeyEvent *);
283     void focusInEvent(QFocusEvent *event);
284
285     // mouse filter?
286     void mousePressEvent(QMouseEvent *event);
287     void mouseReleaseEvent(QMouseEvent *event);
288     void mouseDoubleClickEvent(QMouseEvent *event);
289     void mouseMoveEvent(QMouseEvent *event);
290     void inputMethodEvent(QInputMethodEvent *e);
291     virtual void itemChange(ItemChange, const ItemChangeData &);
292
293     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
294
295 private:
296     Q_DISABLE_COPY(QSGTextEdit)
297     Q_DECLARE_PRIVATE(QSGTextEdit)
298 };
299
300 QT_END_NAMESPACE
301
302 QML_DECLARE_TYPE(QSGTextEdit)
303
304 QT_END_HEADER
305
306 #endif // QSGTEXTEDIT_P_H