9a3be0f116ffaabc5151e1972f2e79cee93f8608
[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
65     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
66     Q_PROPERTY(int length READ length 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
76     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
77     Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
78     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
79     Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
80     Q_PROPERTY(QQmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
81     Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
82     Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
83     Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
84
85     Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
86 #ifndef QT_NO_VALIDATOR
87     Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
88 #endif
89     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
90     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
91
92     Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
93     Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
94     Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
95     Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
96     Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
97     Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
98     Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
99     Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
100     Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
101 #ifndef QT_NO_CLIPBOARD
102     Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
103 #endif
104     Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
105     Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
106     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
107     Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
108     Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
109
110 public:
111     QQuickTextInput(QQuickItem * parent=0);
112     ~QQuickTextInput();
113
114     void componentComplete();
115
116     enum EchoMode {//To match QLineEdit::EchoMode
117         Normal,
118         NoEcho,
119         Password,
120         PasswordEchoOnEdit
121     };
122
123     enum HAlignment {
124         AlignLeft = Qt::AlignLeft,
125         AlignRight = Qt::AlignRight,
126         AlignHCenter = Qt::AlignHCenter
127     };
128
129     enum VAlignment {
130         AlignTop = Qt::AlignTop,
131         AlignBottom = Qt::AlignBottom,
132         AlignVCenter = Qt::AlignVCenter
133     };
134
135     enum WrapMode {
136         NoWrap = QTextOption::NoWrap,
137         WordWrap = QTextOption::WordWrap,
138         WrapAnywhere = QTextOption::WrapAnywhere,
139         WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
140         Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
141     };
142
143     enum SelectionMode {
144         SelectCharacters,
145         SelectWords
146     };
147
148     enum CursorPosition {
149         CursorBetweenCharacters,
150         CursorOnCharacter
151     };
152
153
154     //Auxilliary functions needed to control the TextInput from QML
155     Q_INVOKABLE void positionAt(QQmlV8Function *args) const;
156     Q_INVOKABLE QRectF positionToRectangle(int pos) const;
157     Q_INVOKABLE void moveCursorSelection(int pos);
158     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
159
160     Q_INVOKABLE void openSoftwareInputPanel();
161     Q_INVOKABLE void closeSoftwareInputPanel();
162
163     QString text() const;
164     void setText(const QString &);
165
166     int length() const;
167
168     QFont font() const;
169     void setFont(const QFont &font);
170
171     QColor color() const;
172     void setColor(const QColor &c);
173
174     QColor selectionColor() const;
175     void setSelectionColor(const QColor &c);
176
177     QColor selectedTextColor() const;
178     void setSelectedTextColor(const QColor &c);
179
180     HAlignment hAlign() const;
181     void setHAlign(HAlignment align);
182     void resetHAlign();
183     HAlignment effectiveHAlign() const;
184
185     VAlignment vAlign() const;
186     void setVAlign(VAlignment align);
187
188     WrapMode wrapMode() const;
189     void setWrapMode(WrapMode w);
190
191     bool isReadOnly() const;
192     void setReadOnly(bool);
193
194     bool isCursorVisible() const;
195     void setCursorVisible(bool on);
196
197     int cursorPosition() const;
198     void setCursorPosition(int cp);
199
200     QRectF cursorRectangle() const;
201
202     int selectionStart() const;
203     int selectionEnd() const;
204
205     QString selectedText() const;
206
207     int maxLength() const;
208     void setMaxLength(int ml);
209
210 #ifndef QT_NO_VALIDATOR
211     QValidator * validator() const;
212     void setValidator(QValidator* v);
213 #endif
214     QString inputMask() const;
215     void setInputMask(const QString &im);
216
217     EchoMode echoMode() const;
218     void setEchoMode(EchoMode echo);
219
220     QString passwordCharacter() const;
221     void setPasswordCharacter(const QString &str);
222
223     QString displayText() const;
224
225     QQmlComponent* cursorDelegate() const;
226     void setCursorDelegate(QQmlComponent*);
227
228     bool focusOnPress() const;
229     void setFocusOnPress(bool);
230
231     bool autoScroll() const;
232     void setAutoScroll(bool);
233
234     bool selectByMouse() const;
235     void setSelectByMouse(bool);
236
237     SelectionMode mouseSelectionMode() const;
238     void setMouseSelectionMode(SelectionMode mode);
239
240     bool persistentSelection() const;
241     void setPersistentSelection(bool persist);
242
243     bool hasAcceptableInput() const;
244
245     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
246
247     QRectF boundingRect() const;
248     QRectF clipRect() const;
249
250 #ifndef QT_NO_CLIPBOARD
251     bool canPaste() const;
252 #endif
253
254     bool canUndo() const;
255     bool canRedo() const;
256
257     bool isInputMethodComposing() const;
258
259     Qt::InputMethodHints inputMethodHints() const;
260     void setInputMethodHints(Qt::InputMethodHints hints);
261
262     Q_INVOKABLE QString getText(int start, int end) const;
263
264     qreal contentWidth() const;
265     qreal contentHeight() const;
266
267 Q_SIGNALS:
268     void textChanged();
269     void cursorPositionChanged();
270     void cursorRectangleChanged();
271     void selectionStartChanged();
272     void selectionEndChanged();
273     void selectedTextChanged();
274     void accepted();
275     void acceptableInputChanged();
276     void colorChanged();
277     void selectionColorChanged();
278     void selectedTextColorChanged();
279     void fontChanged(const QFont &font);
280     void horizontalAlignmentChanged(HAlignment alignment);
281     void verticalAlignmentChanged(VAlignment alignment);
282     void wrapModeChanged();
283     void readOnlyChanged(bool isReadOnly);
284     void cursorVisibleChanged(bool isCursorVisible);
285     void cursorDelegateChanged();
286     void maximumLengthChanged(int maximumLength);
287     void validatorChanged();
288     void inputMaskChanged(const QString &inputMask);
289     void echoModeChanged(EchoMode echoMode);
290     void passwordCharacterChanged();
291     void displayTextChanged();
292     void activeFocusOnPressChanged(bool activeFocusOnPress);
293     void autoScrollChanged(bool autoScroll);
294     void selectByMouseChanged(bool selectByMouse);
295     void mouseSelectionModeChanged(SelectionMode mode);
296     void persistentSelectionChanged();
297     void canPasteChanged();
298     void canUndoChanged();
299     void canRedoChanged();
300     void inputMethodComposingChanged();
301     void effectiveHorizontalAlignmentChanged();
302     void contentSizeChanged();
303     void inputMethodHintsChanged();
304
305 protected:
306     virtual void geometryChanged(const QRectF &newGeometry,
307                                  const QRectF &oldGeometry);
308
309     void mousePressEvent(QMouseEvent *event);
310     void mouseMoveEvent(QMouseEvent *event);
311     void mouseReleaseEvent(QMouseEvent *event);
312     void mouseDoubleClickEvent(QMouseEvent *event);
313     void keyPressEvent(QKeyEvent* ev);
314     void inputMethodEvent(QInputMethodEvent *);
315     void mouseUngrabEvent();
316     bool event(QEvent *e);
317     void focusInEvent(QFocusEvent *event);
318     void timerEvent(QTimerEvent *event);
319     virtual void itemChange(ItemChange, const ItemChangeData &);
320     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data);
321
322 public Q_SLOTS:
323     void selectAll();
324     void selectWord();
325     void select(int start, int end);
326     void deselect();
327     bool isRightToLeft(int start, int end);
328 #ifndef QT_NO_CLIPBOARD
329     void cut();
330     void copy();
331     void paste();
332 #endif
333     void undo();
334     void redo();
335     void insert(int position, const QString &text);
336     void remove(int start, int end);
337
338 private Q_SLOTS:
339     void selectionChanged();
340     void createCursor();
341     void updateCursorRectangle();
342     void q_canPasteChanged();
343     void q_updateAlignment();
344     void triggerPreprocess();
345
346 private:
347     Q_DECLARE_PRIVATE(QQuickTextInput)
348 };
349
350 #ifndef QT_NO_VALIDATOR
351 class Q_AUTOTEST_EXPORT QQuickIntValidator : public QIntValidator
352 {
353     Q_OBJECT
354     Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
355 public:
356     QQuickIntValidator(QObject *parent = 0);
357
358     QString localeName() const;
359     void setLocaleName(const QString &name);
360     void resetLocaleName();
361
362 Q_SIGNALS:
363     void localeNameChanged();
364 };
365
366 class Q_AUTOTEST_EXPORT QQuickDoubleValidator : public QDoubleValidator
367 {
368     Q_OBJECT
369     Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
370 public:
371     QQuickDoubleValidator(QObject *parent = 0);
372
373     QString localeName() const;
374     void setLocaleName(const QString &name);
375     void resetLocaleName();
376
377 Q_SIGNALS:
378     void localeNameChanged();
379 };
380 #endif
381
382 QT_END_NAMESPACE
383
384 QML_DECLARE_TYPE(QQuickTextInput)
385 #ifndef QT_NO_VALIDATOR
386 QML_DECLARE_TYPE(QValidator)
387 QML_DECLARE_TYPE(QQuickIntValidator)
388 QML_DECLARE_TYPE(QQuickDoubleValidator)
389 QML_DECLARE_TYPE(QRegExpValidator)
390 #endif
391
392 QT_END_HEADER
393
394 #endif // QQUICKTEXTINPUT_P_H