1 // Commit: 2f173e4945dd8414636c1061acfaf9c2d8b718d8
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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/qtextoption.h>
48 #include <QtGui/qvalidator.h>
54 class QQuickTextInputPrivate;
56 class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
63 Q_ENUMS(SelectionMode)
64 Q_ENUMS(CursorPosition)
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)
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)
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)
90 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
91 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
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)
107 QQuickTextInput(QQuickItem * parent=0);
110 void componentComplete();
112 enum EchoMode {//To match QLineEdit::EchoMode
120 AlignLeft = Qt::AlignLeft,
121 AlignRight = Qt::AlignRight,
122 AlignHCenter = Qt::AlignHCenter
126 AlignTop = Qt::AlignTop,
127 AlignBottom = Qt::AlignBottom,
128 AlignVCenter = Qt::AlignVCenter
132 NoWrap = QTextOption::NoWrap,
133 WordWrap = QTextOption::WordWrap,
134 WrapAnywhere = QTextOption::WrapAnywhere,
135 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
136 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
144 enum CursorPosition {
145 CursorBetweenCharacters,
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);
156 Q_INVOKABLE void openSoftwareInputPanel();
157 Q_INVOKABLE void closeSoftwareInputPanel();
159 QString text() const;
160 void setText(const QString &);
165 void setFont(const QFont &font);
167 QColor color() const;
168 void setColor(const QColor &c);
170 QColor selectionColor() const;
171 void setSelectionColor(const QColor &c);
173 QColor selectedTextColor() const;
174 void setSelectedTextColor(const QColor &c);
176 HAlignment hAlign() const;
177 void setHAlign(HAlignment align);
179 HAlignment effectiveHAlign() const;
181 VAlignment vAlign() const;
182 void setVAlign(VAlignment align);
184 WrapMode wrapMode() const;
185 void setWrapMode(WrapMode w);
187 bool isReadOnly() const;
188 void setReadOnly(bool);
190 bool isCursorVisible() const;
191 void setCursorVisible(bool on);
193 int cursorPosition() const;
194 void setCursorPosition(int cp);
196 QRect cursorRectangle() const;
198 int selectionStart() const;
199 int selectionEnd() const;
201 QString selectedText() const;
203 int maxLength() const;
204 void setMaxLength(int ml);
206 #ifndef QT_NO_VALIDATOR
207 QValidator * validator() const;
208 void setValidator(QValidator* v);
210 QString inputMask() const;
211 void setInputMask(const QString &im);
213 EchoMode echoMode() const;
214 void setEchoMode(EchoMode echo);
216 QString passwordCharacter() const;
217 void setPasswordCharacter(const QString &str);
219 QString displayText() const;
221 QDeclarativeComponent* cursorDelegate() const;
222 void setCursorDelegate(QDeclarativeComponent*);
224 bool focusOnPress() const;
225 void setFocusOnPress(bool);
227 bool autoScroll() const;
228 void setAutoScroll(bool);
230 bool selectByMouse() const;
231 void setSelectByMouse(bool);
233 SelectionMode mouseSelectionMode() const;
234 void setMouseSelectionMode(SelectionMode mode);
236 bool hasAcceptableInput() const;
238 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
240 QRectF boundingRect() const;
241 bool canPaste() const;
243 bool canUndo() const;
244 bool canRedo() const;
246 bool isInputMethodComposing() const;
248 Qt::InputMethodHints imHints() const;
249 void setIMHints(Qt::InputMethodHints hints);
251 Q_INVOKABLE QString getText(int start, int end) const;
255 void cursorPositionChanged();
256 void cursorRectangleChanged();
257 void selectionStartChanged();
258 void selectionEndChanged();
259 void selectedTextChanged();
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();
289 virtual void geometryChanged(const QRectF &newGeometry,
290 const QRectF &oldGeometry);
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);
308 void select(int start, int end);
310 bool isRightToLeft(int start, int end);
311 #ifndef QT_NO_CLIPBOARD
318 void insert(int position, const QString &text);
319 void remove(int start, int end);
322 void selectionChanged();
324 void updateCursorRectangle();
325 void q_canPasteChanged();
326 void q_updateAlignment();
327 void triggerPreprocess();
330 Q_DECLARE_PRIVATE(QQuickTextInput)
333 #ifndef QT_NO_VALIDATOR
334 class Q_AUTOTEST_EXPORT QQuickIntValidator : public QIntValidator
337 Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
339 QQuickIntValidator(QObject *parent = 0);
341 QString localeName() const;
342 void setLocaleName(const QString &name);
343 void resetLocaleName();
346 void localeNameChanged();
349 class Q_AUTOTEST_EXPORT QQuickDoubleValidator : public QDoubleValidator
352 Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
354 QQuickDoubleValidator(QObject *parent = 0);
356 QString localeName() const;
357 void setLocaleName(const QString &name);
358 void resetLocaleName();
361 void localeNameChanged();
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)
377 #endif // QQUICKTEXTINPUT_P_H