Update to 5.0.0-beta1
[profile/ivi/qtdeclarative.git] / src / quick / items / qquicktextinput_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKTEXTINPUT_P_H
43 #define QQUICKTEXTINPUT_P_H
44
45 #include "qquickimplicitsizeitem_p.h"
46 #include <QtGui/qtextoption.h>
47 #include <QtGui/qvalidator.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QQuickTextInputPrivate;
54 class QValidator;
55 class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
56 {
57     Q_OBJECT
58     Q_ENUMS(HAlignment)
59     Q_ENUMS(VAlignment)
60     Q_ENUMS(WrapMode)
61     Q_ENUMS(EchoMode)
62     Q_ENUMS(SelectionMode)
63     Q_ENUMS(CursorPosition)
64     Q_ENUMS(RenderType)
65
66     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
67     Q_PROPERTY(int length READ length NOTIFY textChanged)
68     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
69     Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
70     Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
71     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
72     Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
73     Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
74     Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
75     Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
76
77     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
78     Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
79     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
80     Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
81     Q_PROPERTY(QQmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
82     Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
83     Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
84     Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
85
86     Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
87 #ifndef QT_NO_VALIDATOR
88     Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
89 #endif
90     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
91     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
92
93     Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
94     Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
95     Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
96     Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
97     Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
98     Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
99     Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
100     Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
101     Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
102 #ifndef QT_NO_CLIPBOARD
103     Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
104 #endif
105     Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
106     Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
107     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
108     Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
109     Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
110     Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
111
112 public:
113     QQuickTextInput(QQuickItem * parent=0);
114     ~QQuickTextInput();
115
116     void componentComplete();
117
118     enum EchoMode {//To match QLineEdit::EchoMode
119         Normal,
120         NoEcho,
121         Password,
122         PasswordEchoOnEdit
123     };
124
125     enum HAlignment {
126         AlignLeft = Qt::AlignLeft,
127         AlignRight = Qt::AlignRight,
128         AlignHCenter = Qt::AlignHCenter
129     };
130
131     enum VAlignment {
132         AlignTop = Qt::AlignTop,
133         AlignBottom = Qt::AlignBottom,
134         AlignVCenter = Qt::AlignVCenter
135     };
136
137     enum WrapMode {
138         NoWrap = QTextOption::NoWrap,
139         WordWrap = QTextOption::WordWrap,
140         WrapAnywhere = QTextOption::WrapAnywhere,
141         WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
142         Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
143     };
144
145     enum SelectionMode {
146         SelectCharacters,
147         SelectWords
148     };
149
150     enum CursorPosition {
151         CursorBetweenCharacters,
152         CursorOnCharacter
153     };
154
155     enum RenderType { QtRendering,
156                       NativeRendering
157                     };
158
159     //Auxilliary functions needed to control the TextInput from QML
160     Q_INVOKABLE void positionAt(QQmlV8Function *args) const;
161     Q_INVOKABLE QRectF positionToRectangle(int pos) const;
162     Q_INVOKABLE void moveCursorSelection(int pos);
163     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
164
165     RenderType renderType() const;
166     void setRenderType(RenderType renderType);
167
168     QString text() const;
169     void setText(const QString &);
170
171     int length() const;
172
173     QFont font() const;
174     void setFont(const QFont &font);
175
176     QColor color() const;
177     void setColor(const QColor &c);
178
179     QColor selectionColor() const;
180     void setSelectionColor(const QColor &c);
181
182     QColor selectedTextColor() const;
183     void setSelectedTextColor(const QColor &c);
184
185     HAlignment hAlign() const;
186     void setHAlign(HAlignment align);
187     void resetHAlign();
188     HAlignment effectiveHAlign() const;
189
190     VAlignment vAlign() const;
191     void setVAlign(VAlignment align);
192
193     WrapMode wrapMode() const;
194     void setWrapMode(WrapMode w);
195
196     bool isReadOnly() const;
197     void setReadOnly(bool);
198
199     bool isCursorVisible() const;
200     void setCursorVisible(bool on);
201
202     int cursorPosition() const;
203     void setCursorPosition(int cp);
204
205     QRectF cursorRectangle() const;
206
207     int selectionStart() const;
208     int selectionEnd() const;
209
210     QString selectedText() const;
211
212     int maxLength() const;
213     void setMaxLength(int ml);
214
215 #ifndef QT_NO_VALIDATOR
216     QValidator * validator() const;
217     void setValidator(QValidator* v);
218 #endif
219     QString inputMask() const;
220     void setInputMask(const QString &im);
221
222     EchoMode echoMode() const;
223     void setEchoMode(EchoMode echo);
224
225     QString passwordCharacter() const;
226     void setPasswordCharacter(const QString &str);
227
228     QString displayText() const;
229
230     QQmlComponent* cursorDelegate() const;
231     void setCursorDelegate(QQmlComponent*);
232
233     bool focusOnPress() const;
234     void setFocusOnPress(bool);
235
236     bool autoScroll() const;
237     void setAutoScroll(bool);
238
239     bool selectByMouse() const;
240     void setSelectByMouse(bool);
241
242     SelectionMode mouseSelectionMode() const;
243     void setMouseSelectionMode(SelectionMode mode);
244
245     bool persistentSelection() const;
246     void setPersistentSelection(bool persist);
247
248     bool hasAcceptableInput() const;
249
250     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
251
252     QRectF boundingRect() const;
253     QRectF clipRect() const;
254
255 #ifndef QT_NO_CLIPBOARD
256     bool canPaste() const;
257 #endif
258
259     bool canUndo() const;
260     bool canRedo() const;
261
262     bool isInputMethodComposing() const;
263
264     Qt::InputMethodHints inputMethodHints() const;
265     void setInputMethodHints(Qt::InputMethodHints hints);
266
267     Q_INVOKABLE QString getText(int start, int end) const;
268
269     qreal contentWidth() const;
270     qreal contentHeight() const;
271
272 Q_SIGNALS:
273     void textChanged();
274     void cursorPositionChanged();
275     void cursorRectangleChanged();
276     void selectionStartChanged();
277     void selectionEndChanged();
278     void selectedTextChanged();
279     void accepted();
280     void acceptableInputChanged();
281     void colorChanged();
282     void selectionColorChanged();
283     void selectedTextColorChanged();
284     void fontChanged(const QFont &font);
285     void horizontalAlignmentChanged(HAlignment alignment);
286     void verticalAlignmentChanged(VAlignment alignment);
287     void wrapModeChanged();
288     void readOnlyChanged(bool isReadOnly);
289     void cursorVisibleChanged(bool isCursorVisible);
290     void cursorDelegateChanged();
291     void maximumLengthChanged(int maximumLength);
292     void validatorChanged();
293     void inputMaskChanged(const QString &inputMask);
294     void echoModeChanged(EchoMode echoMode);
295     void passwordCharacterChanged();
296     void displayTextChanged();
297     void activeFocusOnPressChanged(bool activeFocusOnPress);
298     void autoScrollChanged(bool autoScroll);
299     void selectByMouseChanged(bool selectByMouse);
300     void mouseSelectionModeChanged(SelectionMode mode);
301     void persistentSelectionChanged();
302     void canPasteChanged();
303     void canUndoChanged();
304     void canRedoChanged();
305     void inputMethodComposingChanged();
306     void effectiveHorizontalAlignmentChanged();
307     void contentSizeChanged();
308     void inputMethodHintsChanged();
309     void renderTypeChanged();
310
311 protected:
312     virtual void geometryChanged(const QRectF &newGeometry,
313                                  const QRectF &oldGeometry);
314
315     void mousePressEvent(QMouseEvent *event);
316     void mouseMoveEvent(QMouseEvent *event);
317     void mouseReleaseEvent(QMouseEvent *event);
318     void mouseDoubleClickEvent(QMouseEvent *event);
319     void keyPressEvent(QKeyEvent* ev);
320     void inputMethodEvent(QInputMethodEvent *);
321     void mouseUngrabEvent();
322     bool event(QEvent *e);
323     void focusInEvent(QFocusEvent *event);
324     void timerEvent(QTimerEvent *event);
325     virtual void itemChange(ItemChange, const ItemChangeData &);
326     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data);
327
328 public Q_SLOTS:
329     void selectAll();
330     void selectWord();
331     void select(int start, int end);
332     void deselect();
333     bool isRightToLeft(int start, int end);
334 #ifndef QT_NO_CLIPBOARD
335     void cut();
336     void copy();
337     void paste();
338 #endif
339     void undo();
340     void redo();
341     void insert(int position, const QString &text);
342     void remove(int start, int end);
343
344 private Q_SLOTS:
345     void selectionChanged();
346     void createCursor();
347     void updateCursorRectangle();
348     void q_canPasteChanged();
349     void q_updateAlignment();
350     void triggerPreprocess();
351
352 #ifndef QT_NO_VALIDATOR
353     void q_validatorChanged();
354 #endif
355
356 private:
357     friend class QQuickTextUtil;
358
359     Q_DECLARE_PRIVATE(QQuickTextInput)
360 };
361
362 #ifndef QT_NO_VALIDATOR
363 class Q_AUTOTEST_EXPORT QQuickIntValidator : public QIntValidator
364 {
365     Q_OBJECT
366     Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
367 public:
368     QQuickIntValidator(QObject *parent = 0);
369
370     QString localeName() const;
371     void setLocaleName(const QString &name);
372     void resetLocaleName();
373
374 Q_SIGNALS:
375     void localeNameChanged();
376 };
377
378 class Q_AUTOTEST_EXPORT QQuickDoubleValidator : public QDoubleValidator
379 {
380     Q_OBJECT
381     Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
382 public:
383     QQuickDoubleValidator(QObject *parent = 0);
384
385     QString localeName() const;
386     void setLocaleName(const QString &name);
387     void resetLocaleName();
388
389 Q_SIGNALS:
390     void localeNameChanged();
391 };
392 #endif
393
394 QT_END_NAMESPACE
395
396 QML_DECLARE_TYPE(QQuickTextInput)
397 #ifndef QT_NO_VALIDATOR
398 QML_DECLARE_TYPE(QValidator)
399 QML_DECLARE_TYPE(QQuickIntValidator)
400 QML_DECLARE_TYPE(QQuickDoubleValidator)
401 QML_DECLARE_TYPE(QRegExpValidator)
402 #endif
403
404 QT_END_HEADER
405
406 #endif // QQUICKTEXTINPUT_P_H