1 // Commit: 2f173e4945dd8414636c1061acfaf9c2d8b718d8
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
41 ****************************************************************************/
43 #ifndef QQUICKTEXTINPUT_P_H
44 #define QQUICKTEXTINPUT_P_H
46 #include "qquickimplicitsizeitem_p.h"
47 #include <QtGui/qvalidator.h>
53 QT_MODULE(Declarative)
55 class QQuickTextInputPrivate;
57 class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
62 Q_ENUMS(SelectionMode)
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)
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)
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)
85 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
86 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
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)
100 QQuickTextInput(QQuickItem * parent=0);
103 enum EchoMode {//To match QLineEdit::EchoMode
111 AlignLeft = Qt::AlignLeft,
112 AlignRight = Qt::AlignRight,
113 AlignHCenter = Qt::AlignHCenter
121 enum CursorPosition {
122 CursorBetweenCharacters,
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);
133 Q_INVOKABLE void openSoftwareInputPanel();
134 Q_INVOKABLE void closeSoftwareInputPanel();
136 QString text() const;
137 void setText(const QString &);
140 void setFont(const QFont &font);
142 QColor color() const;
143 void setColor(const QColor &c);
145 QColor selectionColor() const;
146 void setSelectionColor(const QColor &c);
148 QColor selectedTextColor() const;
149 void setSelectedTextColor(const QColor &c);
151 HAlignment hAlign() const;
152 void setHAlign(HAlignment align);
154 HAlignment effectiveHAlign() const;
156 bool isReadOnly() const;
157 void setReadOnly(bool);
159 bool isCursorVisible() const;
160 void setCursorVisible(bool on);
162 int cursorPosition() const;
163 void setCursorPosition(int cp);
165 QRect cursorRectangle() const;
167 int selectionStart() const;
168 int selectionEnd() const;
170 QString selectedText() const;
172 int maxLength() const;
173 void setMaxLength(int ml);
175 #ifndef QT_NO_VALIDATOR
176 QValidator * validator() const;
177 void setValidator(QValidator* v);
179 QString inputMask() const;
180 void setInputMask(const QString &im);
182 EchoMode echoMode() const;
183 void setEchoMode(EchoMode echo);
185 QString passwordCharacter() const;
186 void setPasswordCharacter(const QString &str);
188 QString displayText() const;
190 QDeclarativeComponent* cursorDelegate() const;
191 void setCursorDelegate(QDeclarativeComponent*);
193 bool focusOnPress() const;
194 void setFocusOnPress(bool);
196 bool autoScroll() const;
197 void setAutoScroll(bool);
199 bool selectByMouse() const;
200 void setSelectByMouse(bool);
202 SelectionMode mouseSelectionMode() const;
203 void setMouseSelectionMode(SelectionMode mode);
205 bool hasAcceptableInput() const;
207 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
209 QRectF boundingRect() const;
210 bool canPaste() const;
212 bool isInputMethodComposing() const;
214 Qt::InputMethodHints imHints() const;
215 void setIMHints(Qt::InputMethodHints hints);
219 void cursorPositionChanged();
220 void cursorRectangleChanged();
221 void selectionStartChanged();
222 void selectionEndChanged();
223 void selectedTextChanged();
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();
249 virtual void geometryChanged(const QRectF &newGeometry,
250 const QRectF &oldGeometry);
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);
268 void select(int start, int end);
270 bool isRightToLeft(int start, int end);
271 #ifndef QT_NO_CLIPBOARD
278 void updateSize(bool needsRedraw = true);
279 void q_textChanged();
280 void selectionChanged();
282 void cursorPosChanged();
283 void updateCursorRectangle();
284 void updateRect(const QRect &r = QRect());
285 void q_canPasteChanged();
288 Q_DECLARE_PRIVATE(QQuickTextInput)
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)
303 #endif // QQUICKTEXTINPUT_P_H