Remove "All rights reserved" line from license headers.
[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 ** 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 **
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     Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged)
97
98 public:
99     QQuickTextEdit(QQuickItem *parent=0);
100
101     enum HAlignment {
102         AlignLeft = Qt::AlignLeft,
103         AlignRight = Qt::AlignRight,
104         AlignHCenter = Qt::AlignHCenter,
105         AlignJustify = Qt::AlignJustify
106     };
107
108     enum VAlignment {
109         AlignTop = Qt::AlignTop,
110         AlignBottom = Qt::AlignBottom,
111         AlignVCenter = Qt::AlignVCenter
112     };
113
114     enum TextFormat {
115         PlainText = Qt::PlainText,
116         RichText = Qt::RichText,
117         AutoText = Qt::AutoText
118     };
119
120     enum WrapMode { NoWrap = QTextOption::NoWrap,
121                     WordWrap = QTextOption::WordWrap,
122                     WrapAnywhere = QTextOption::WrapAnywhere,
123                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
124                     Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
125                   };
126
127     enum SelectionMode {
128         SelectCharacters,
129         SelectWords
130     };
131
132     Q_INVOKABLE void openSoftwareInputPanel();
133     Q_INVOKABLE void closeSoftwareInputPanel();
134
135     QString text() const;
136     void setText(const QString &);
137
138     TextFormat textFormat() const;
139     void setTextFormat(TextFormat format);
140
141     QFont font() const;
142     void setFont(const QFont &font);
143
144     QColor color() const;
145     void setColor(const QColor &c);
146
147     QColor selectionColor() const;
148     void setSelectionColor(const QColor &c);
149
150     QColor selectedTextColor() const;
151     void setSelectedTextColor(const QColor &c);
152
153     HAlignment hAlign() const;
154     void setHAlign(HAlignment align);
155     void resetHAlign();
156     HAlignment effectiveHAlign() const;
157
158     VAlignment vAlign() const;
159     void setVAlign(VAlignment align);
160
161     WrapMode wrapMode() const;
162     void setWrapMode(WrapMode w);
163
164     int lineCount() const;
165
166     int length() 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     bool canUndo() const;
200     bool canRedo() const;
201
202     virtual void componentComplete();
203
204     /* FROM EDIT */
205     void setReadOnly(bool);
206     bool isReadOnly() const;
207
208     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
209     Qt::TextInteractionFlags textInteractionFlags() const;
210
211     QRect cursorRectangle() const;
212
213     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
214
215     qreal paintedWidth() const;
216     qreal paintedHeight() const;
217
218     QUrl baseUrl() const;
219     void setBaseUrl(const QUrl &url);
220     void resetBaseUrl();
221
222     Q_INVOKABLE QRectF positionToRectangle(int) const;
223     Q_INVOKABLE int positionAt(int x, int y) const;
224     Q_INVOKABLE void moveCursorSelection(int pos);
225     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
226
227     QRectF boundingRect() const;
228
229     bool isInputMethodComposing() const;
230
231     Q_INVOKABLE QString getText(int start, int end) const;
232     Q_INVOKABLE QString getFormattedText(int start, int end) const;
233
234 Q_SIGNALS:
235     void textChanged();
236     void paintedSizeChanged();
237     void cursorPositionChanged();
238     void cursorRectangleChanged();
239     void selectionStartChanged();
240     void selectionEndChanged();
241     void selectionChanged();
242     void colorChanged(const QColor &color);
243     void selectionColorChanged(const QColor &color);
244     void selectedTextColorChanged(const QColor &color);
245     void fontChanged(const QFont &font);
246     void horizontalAlignmentChanged(HAlignment alignment);
247     void verticalAlignmentChanged(VAlignment alignment);
248     void wrapModeChanged();
249     void lineCountChanged();
250     void textFormatChanged(TextFormat textFormat);
251     void readOnlyChanged(bool isReadOnly);
252     void cursorVisibleChanged(bool isCursorVisible);
253     void cursorDelegateChanged();
254     void activeFocusOnPressChanged(bool activeFocusOnPressed);
255     void persistentSelectionChanged(bool isPersistentSelection);
256     void textMarginChanged(qreal textMargin);
257     void selectByMouseChanged(bool selectByMouse);
258     void mouseSelectionModeChanged(SelectionMode mode);
259     void linkActivated(const QString &link);
260     void canPasteChanged();
261     void canUndoChanged();
262     void canRedoChanged();
263     void inputMethodComposingChanged();
264     void effectiveHorizontalAlignmentChanged();
265     void baseUrlChanged();
266
267 public Q_SLOTS:
268     void selectAll();
269     void selectWord();
270     void select(int start, int end);
271     void deselect();
272     bool isRightToLeft(int start, int end);
273 #ifndef QT_NO_CLIPBOARD
274     void cut();
275     void copy();
276     void paste();
277 #endif
278     void undo();
279     void redo();
280     void insert(int position, const QString &text);
281     void remove(int start, int end);
282
283 private Q_SLOTS:
284     void q_textChanged();
285     void updateSelectionMarkers();
286     void moveCursorDelegate();
287     void loadCursorDelegate();
288     void q_canPasteChanged();
289     void updateDocument();
290     void updateCursor();
291     void q_updateAlignment();
292     void updateSize();
293     void triggerPreprocess();
294
295 private:
296     void updateTotalLines();
297     void updateImageCache(const QRectF &rect = QRectF());
298
299 protected:
300     virtual void geometryChanged(const QRectF &newGeometry,
301                                  const QRectF &oldGeometry);
302
303     bool event(QEvent *);
304     void keyPressEvent(QKeyEvent *);
305     void keyReleaseEvent(QKeyEvent *);
306     void focusInEvent(QFocusEvent *event);
307
308     // mouse filter?
309     void mousePressEvent(QMouseEvent *event);
310     void mouseReleaseEvent(QMouseEvent *event);
311     void mouseDoubleClickEvent(QMouseEvent *event);
312     void mouseMoveEvent(QMouseEvent *event);
313     void inputMethodEvent(QInputMethodEvent *e);
314     virtual void itemChange(ItemChange, const ItemChangeData &);
315
316     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
317
318 private:
319     Q_DISABLE_COPY(QQuickTextEdit)
320     Q_DECLARE_PRIVATE(QQuickTextEdit)
321 };
322
323 QT_END_NAMESPACE
324
325 QML_DECLARE_TYPE(QQuickTextEdit)
326
327 QT_END_HEADER
328
329 #endif // QQUICKTEXTEDIT_P_H