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