a98c5eeaf1b3e315e5b6a4bb97f1dabc78e43d73
[profile/ivi/qtdeclarative.git] / src / quick / items / qquicktextinput_p.h
1 // Commit: 2f173e4945dd8414636c1061acfaf9c2d8b718d8
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
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 QQUICKTEXTINPUT_P_H
44 #define QQUICKTEXTINPUT_P_H
45
46 #include "qquickimplicitsizeitem_p.h"
47 #include <QtGui/qtextoption.h>
48 #include <QtGui/qvalidator.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 class QQuickTextInputPrivate;
55 class QValidator;
56 class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
57 {
58     Q_OBJECT
59     Q_ENUMS(HAlignment)
60     Q_ENUMS(VAlignment)
61     Q_ENUMS(WrapMode)
62     Q_ENUMS(EchoMode)
63     Q_ENUMS(SelectionMode)
64     Q_ENUMS(CursorPosition)
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(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
81     Q_PROPERTY(QDeclarativeComponent *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 imHints WRITE setIMHints)
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 canPaste READ canPaste NOTIFY canPasteChanged)
102     Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
103     Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
104     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
105
106 public:
107     QQuickTextInput(QQuickItem * parent=0);
108     ~QQuickTextInput();
109
110     void componentComplete();
111
112     enum EchoMode {//To match QLineEdit::EchoMode
113         Normal,
114         NoEcho,
115         Password,
116         PasswordEchoOnEdit
117     };
118
119     enum HAlignment {
120         AlignLeft = Qt::AlignLeft,
121         AlignRight = Qt::AlignRight,
122         AlignHCenter = Qt::AlignHCenter
123     };
124
125     enum VAlignment {
126         AlignTop = Qt::AlignTop,
127         AlignBottom = Qt::AlignBottom,
128         AlignVCenter = Qt::AlignVCenter
129     };
130
131     enum WrapMode {
132         NoWrap = QTextOption::NoWrap,
133         WordWrap = QTextOption::WordWrap,
134         WrapAnywhere = QTextOption::WrapAnywhere,
135         WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
136         Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
137     };
138
139     enum SelectionMode {
140         SelectCharacters,
141         SelectWords
142     };
143
144     enum CursorPosition {
145         CursorBetweenCharacters,
146         CursorOnCharacter
147     };
148
149
150     //Auxilliary functions needed to control the TextInput from QML
151     Q_INVOKABLE void positionAt(QDeclarativeV8Function *args) const;
152     Q_INVOKABLE QRectF positionToRectangle(int pos) const;
153     Q_INVOKABLE void moveCursorSelection(int pos);
154     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
155
156     Q_INVOKABLE void openSoftwareInputPanel();
157     Q_INVOKABLE void closeSoftwareInputPanel();
158
159     QString text() const;
160     void setText(const QString &);
161
162     int length() const;
163
164     QFont font() const;
165     void setFont(const QFont &font);
166
167     QColor color() const;
168     void setColor(const QColor &c);
169
170     QColor selectionColor() const;
171     void setSelectionColor(const QColor &c);
172
173     QColor selectedTextColor() const;
174     void setSelectedTextColor(const QColor &c);
175
176     HAlignment hAlign() const;
177     void setHAlign(HAlignment align);
178     void resetHAlign();
179     HAlignment effectiveHAlign() const;
180
181     VAlignment vAlign() const;
182     void setVAlign(VAlignment align);
183
184     WrapMode wrapMode() const;
185     void setWrapMode(WrapMode w);
186
187     bool isReadOnly() const;
188     void setReadOnly(bool);
189
190     bool isCursorVisible() const;
191     void setCursorVisible(bool on);
192
193     int cursorPosition() const;
194     void setCursorPosition(int cp);
195
196     QRect cursorRectangle() const;
197
198     int selectionStart() const;
199     int selectionEnd() const;
200
201     QString selectedText() const;
202
203     int maxLength() const;
204     void setMaxLength(int ml);
205
206 #ifndef QT_NO_VALIDATOR
207     QValidator * validator() const;
208     void setValidator(QValidator* v);
209 #endif
210     QString inputMask() const;
211     void setInputMask(const QString &im);
212
213     EchoMode echoMode() const;
214     void setEchoMode(EchoMode echo);
215
216     QString passwordCharacter() const;
217     void setPasswordCharacter(const QString &str);
218
219     QString displayText() const;
220
221     QDeclarativeComponent* cursorDelegate() const;
222     void setCursorDelegate(QDeclarativeComponent*);
223
224     bool focusOnPress() const;
225     void setFocusOnPress(bool);
226
227     bool autoScroll() const;
228     void setAutoScroll(bool);
229
230     bool selectByMouse() const;
231     void setSelectByMouse(bool);
232
233     SelectionMode mouseSelectionMode() const;
234     void setMouseSelectionMode(SelectionMode mode);
235
236     bool hasAcceptableInput() const;
237
238     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
239
240     QRectF boundingRect() const;
241     bool canPaste() const;
242
243     bool canUndo() const;
244     bool canRedo() const;
245
246     bool isInputMethodComposing() const;
247
248     Qt::InputMethodHints imHints() const;
249     void setIMHints(Qt::InputMethodHints hints);
250
251     Q_INVOKABLE QString getText(int start, int end) const;
252
253 Q_SIGNALS:
254     void textChanged();
255     void cursorPositionChanged();
256     void cursorRectangleChanged();
257     void selectionStartChanged();
258     void selectionEndChanged();
259     void selectedTextChanged();
260     void accepted();
261     void acceptableInputChanged();
262     void colorChanged(const QColor &color);
263     void selectionColorChanged(const QColor &color);
264     void selectedTextColorChanged(const QColor &color);
265     void fontChanged(const QFont &font);
266     void horizontalAlignmentChanged(HAlignment alignment);
267     void verticalAlignmentChanged(VAlignment alignment);
268     void wrapModeChanged();
269     void readOnlyChanged(bool isReadOnly);
270     void cursorVisibleChanged(bool isCursorVisible);
271     void cursorDelegateChanged();
272     void maximumLengthChanged(int maximumLength);
273     void validatorChanged();
274     void inputMaskChanged(const QString &inputMask);
275     void echoModeChanged(EchoMode echoMode);
276     void passwordCharacterChanged();
277     void displayTextChanged();
278     void activeFocusOnPressChanged(bool activeFocusOnPress);
279     void autoScrollChanged(bool autoScroll);
280     void selectByMouseChanged(bool selectByMouse);
281     void mouseSelectionModeChanged(SelectionMode mode);
282     void canPasteChanged();
283     void canUndoChanged();
284     void canRedoChanged();
285     void inputMethodComposingChanged();
286     void effectiveHorizontalAlignmentChanged();
287
288 protected:
289     virtual void geometryChanged(const QRectF &newGeometry,
290                                  const QRectF &oldGeometry);
291
292     void mousePressEvent(QMouseEvent *event);
293     void mouseMoveEvent(QMouseEvent *event);
294     void mouseReleaseEvent(QMouseEvent *event);
295     void mouseDoubleClickEvent(QMouseEvent *event);
296     void keyPressEvent(QKeyEvent* ev);
297     void inputMethodEvent(QInputMethodEvent *);
298     void mouseUngrabEvent();
299     bool event(QEvent *e);
300     void focusInEvent(QFocusEvent *event);
301     void timerEvent(QTimerEvent *event);
302     virtual void itemChange(ItemChange, const ItemChangeData &);
303     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data);
304
305 public Q_SLOTS:
306     void selectAll();
307     void selectWord();
308     void select(int start, int end);
309     void deselect();
310     bool isRightToLeft(int start, int end);
311 #ifndef QT_NO_CLIPBOARD
312     void cut();
313     void copy();
314     void paste();
315 #endif
316     void undo();
317     void redo();
318     void insert(int position, const QString &text);
319     void remove(int start, int end);
320
321 private Q_SLOTS:
322     void selectionChanged();
323     void createCursor();
324     void updateCursorRectangle();
325     void q_canPasteChanged();
326     void q_updateAlignment();
327     void triggerPreprocess();
328
329 private:
330     Q_DECLARE_PRIVATE(QQuickTextInput)
331 };
332
333 #ifndef QT_NO_VALIDATOR
334 class Q_AUTOTEST_EXPORT QQuickIntValidator : public QIntValidator
335 {
336     Q_OBJECT
337     Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
338 public:
339     QQuickIntValidator(QObject *parent = 0);
340
341     QString localeName() const;
342     void setLocaleName(const QString &name);
343     void resetLocaleName();
344
345 Q_SIGNALS:
346     void localeNameChanged();
347 };
348
349 class Q_AUTOTEST_EXPORT QQuickDoubleValidator : public QDoubleValidator
350 {
351     Q_OBJECT
352     Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
353 public:
354     QQuickDoubleValidator(QObject *parent = 0);
355
356     QString localeName() const;
357     void setLocaleName(const QString &name);
358     void resetLocaleName();
359
360 Q_SIGNALS:
361     void localeNameChanged();
362 };
363 #endif
364
365 QT_END_NAMESPACE
366
367 QML_DECLARE_TYPE(QQuickTextInput)
368 #ifndef QT_NO_VALIDATOR
369 QML_DECLARE_TYPE(QValidator)
370 QML_DECLARE_TYPE(QQuickIntValidator)
371 QML_DECLARE_TYPE(QQuickDoubleValidator)
372 QML_DECLARE_TYPE(QRegExpValidator)
373 #endif
374
375 QT_END_HEADER
376
377 #endif // QQUICKTEXTINPUT_P_H