Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquicktextinput_p.h
1 // Commit: 2f173e4945dd8414636c1061acfaf9c2d8b718d8
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 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 QQUICKTEXTINPUT_P_H
44 #define QQUICKTEXTINPUT_P_H
45
46 #include "qquickimplicitsizeitem_p.h"
47 #include <QtGui/qvalidator.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 QT_MODULE(Declarative)
54
55 class QQuickTextInputPrivate;
56 class QValidator;
57 class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
58 {
59     Q_OBJECT
60     Q_ENUMS(HAlignment)
61     Q_ENUMS(EchoMode)
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
72     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
73     Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
74     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
75     Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
76     Q_PROPERTY(QDeclarativeComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
77     Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
78     Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
79     Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
80
81     Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
82 #ifndef QT_NO_VALIDATOR
83     Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
84 #endif
85     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
86     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
87
88     Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
89     Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
90     Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
91     Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
92     Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
93     Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
94     Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
95     Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
96     Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
97     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
98
99 public:
100     QQuickTextInput(QQuickItem * parent=0);
101     ~QQuickTextInput();
102
103     enum EchoMode {//To match QLineEdit::EchoMode
104         Normal,
105         NoEcho,
106         Password,
107         PasswordEchoOnEdit
108     };
109
110     enum HAlignment {
111         AlignLeft = Qt::AlignLeft,
112         AlignRight = Qt::AlignRight,
113         AlignHCenter = Qt::AlignHCenter
114     };
115
116     enum SelectionMode {
117         SelectCharacters,
118         SelectWords
119     };
120
121     enum CursorPosition {
122         CursorBetweenCharacters,
123         CursorOnCharacter
124     };
125
126     //Auxilliary functions needed to control the TextInput from QML
127     Q_INVOKABLE int positionAt(int x) const;
128     Q_INVOKABLE int positionAt(int x, CursorPosition position) const;
129     Q_INVOKABLE QRectF positionToRectangle(int pos) const;
130     Q_INVOKABLE void moveCursorSelection(int pos);
131     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
132
133     Q_INVOKABLE void openSoftwareInputPanel();
134     Q_INVOKABLE void closeSoftwareInputPanel();
135
136     QString text() const;
137     void setText(const QString &);
138
139     QFont font() const;
140     void setFont(const QFont &font);
141
142     QColor color() const;
143     void setColor(const QColor &c);
144
145     QColor selectionColor() const;
146     void setSelectionColor(const QColor &c);
147
148     QColor selectedTextColor() const;
149     void setSelectedTextColor(const QColor &c);
150
151     HAlignment hAlign() const;
152     void setHAlign(HAlignment align);
153     void resetHAlign();
154     HAlignment effectiveHAlign() const;
155
156     bool isReadOnly() const;
157     void setReadOnly(bool);
158
159     bool isCursorVisible() const;
160     void setCursorVisible(bool on);
161
162     int cursorPosition() const;
163     void setCursorPosition(int cp);
164
165     QRect cursorRectangle() const;
166
167     int selectionStart() const;
168     int selectionEnd() const;
169
170     QString selectedText() const;
171
172     int maxLength() const;
173     void setMaxLength(int ml);
174
175 #ifndef QT_NO_VALIDATOR
176     QValidator * validator() const;
177     void setValidator(QValidator* v);
178 #endif
179     QString inputMask() const;
180     void setInputMask(const QString &im);
181
182     EchoMode echoMode() const;
183     void setEchoMode(EchoMode echo);
184
185     QString passwordCharacter() const;
186     void setPasswordCharacter(const QString &str);
187
188     QString displayText() const;
189
190     QDeclarativeComponent* cursorDelegate() const;
191     void setCursorDelegate(QDeclarativeComponent*);
192
193     bool focusOnPress() const;
194     void setFocusOnPress(bool);
195
196     bool autoScroll() const;
197     void setAutoScroll(bool);
198
199     bool selectByMouse() const;
200     void setSelectByMouse(bool);
201
202     SelectionMode mouseSelectionMode() const;
203     void setMouseSelectionMode(SelectionMode mode);
204
205     bool hasAcceptableInput() const;
206
207     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
208
209     QRectF boundingRect() const;
210     bool canPaste() const;
211
212     bool isInputMethodComposing() const;
213
214     Qt::InputMethodHints imHints() const;
215     void setIMHints(Qt::InputMethodHints hints);
216
217 Q_SIGNALS:
218     void textChanged();
219     void cursorPositionChanged();
220     void cursorRectangleChanged();
221     void selectionStartChanged();
222     void selectionEndChanged();
223     void selectedTextChanged();
224     void accepted();
225     void acceptableInputChanged();
226     void colorChanged(const QColor &color);
227     void selectionColorChanged(const QColor &color);
228     void selectedTextColorChanged(const QColor &color);
229     void fontChanged(const QFont &font);
230     void horizontalAlignmentChanged(HAlignment alignment);
231     void readOnlyChanged(bool isReadOnly);
232     void cursorVisibleChanged(bool isCursorVisible);
233     void cursorDelegateChanged();
234     void maximumLengthChanged(int maximumLength);
235     void validatorChanged();
236     void inputMaskChanged(const QString &inputMask);
237     void echoModeChanged(EchoMode echoMode);
238     void passwordCharacterChanged();
239     void displayTextChanged();
240     void activeFocusOnPressChanged(bool activeFocusOnPress);
241     void autoScrollChanged(bool autoScroll);
242     void selectByMouseChanged(bool selectByMouse);
243     void mouseSelectionModeChanged(SelectionMode mode);
244     void canPasteChanged();
245     void inputMethodComposingChanged();
246     void effectiveHorizontalAlignmentChanged();
247
248 protected:
249     virtual void geometryChanged(const QRectF &newGeometry,
250                                  const QRectF &oldGeometry);
251
252     void mousePressEvent(QMouseEvent *event);
253     void mouseMoveEvent(QMouseEvent *event);
254     void mouseReleaseEvent(QMouseEvent *event);
255     void mouseDoubleClickEvent(QMouseEvent *event);
256     bool sceneEvent(QEvent *event);
257     void keyPressEvent(QKeyEvent* ev);
258     void inputMethodEvent(QInputMethodEvent *);
259     void mouseUngrabEvent();
260     bool event(QEvent *e);
261     void focusInEvent(QFocusEvent *event);
262     virtual void itemChange(ItemChange, const ItemChangeData &);
263     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data);
264
265 public Q_SLOTS:
266     void selectAll();
267     void selectWord();
268     void select(int start, int end);
269     void deselect();
270     bool isRightToLeft(int start, int end);
271 #ifndef QT_NO_CLIPBOARD
272     void cut();
273     void copy();
274     void paste();
275 #endif
276
277 private Q_SLOTS:
278     void updateSize(bool needsRedraw = true);
279     void q_textChanged();
280     void selectionChanged();
281     void createCursor();
282     void cursorPosChanged();
283     void updateCursorRectangle();
284     void updateRect(const QRect &r = QRect());
285     void q_canPasteChanged();
286
287 private:
288     Q_DECLARE_PRIVATE(QQuickTextInput)
289 };
290
291 QT_END_NAMESPACE
292
293 QML_DECLARE_TYPE(QQuickTextInput)
294 #ifndef QT_NO_VALIDATOR
295 QML_DECLARE_TYPE(QValidator)
296 QML_DECLARE_TYPE(QIntValidator)
297 QML_DECLARE_TYPE(QDoubleValidator)
298 QML_DECLARE_TYPE(QRegExpValidator)
299 #endif
300
301 QT_END_HEADER
302
303 #endif // QQUICKTEXTINPUT_P_H