1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKTEXTINPUT_P_H
43 #define QQUICKTEXTINPUT_P_H
45 #include "qquickimplicitsizeitem_p.h"
46 #include <QtGui/qtextoption.h>
47 #include <QtGui/qvalidator.h>
53 class QQuickTextInputPrivate;
55 class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
62 Q_ENUMS(SelectionMode)
63 Q_ENUMS(CursorPosition)
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)
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)
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)
89 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
90 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
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)
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)
111 QQuickTextInput(QQuickItem * parent=0);
114 void componentComplete();
116 enum EchoMode {//To match QLineEdit::EchoMode
124 AlignLeft = Qt::AlignLeft,
125 AlignRight = Qt::AlignRight,
126 AlignHCenter = Qt::AlignHCenter
130 AlignTop = Qt::AlignTop,
131 AlignBottom = Qt::AlignBottom,
132 AlignVCenter = Qt::AlignVCenter
136 NoWrap = QTextOption::NoWrap,
137 WordWrap = QTextOption::WordWrap,
138 WrapAnywhere = QTextOption::WrapAnywhere,
139 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
140 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
148 enum CursorPosition {
149 CursorBetweenCharacters,
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);
160 Q_INVOKABLE void openSoftwareInputPanel();
161 Q_INVOKABLE void closeSoftwareInputPanel();
163 QString text() const;
164 void setText(const QString &);
169 void setFont(const QFont &font);
171 QColor color() const;
172 void setColor(const QColor &c);
174 QColor selectionColor() const;
175 void setSelectionColor(const QColor &c);
177 QColor selectedTextColor() const;
178 void setSelectedTextColor(const QColor &c);
180 HAlignment hAlign() const;
181 void setHAlign(HAlignment align);
183 HAlignment effectiveHAlign() const;
185 VAlignment vAlign() const;
186 void setVAlign(VAlignment align);
188 WrapMode wrapMode() const;
189 void setWrapMode(WrapMode w);
191 bool isReadOnly() const;
192 void setReadOnly(bool);
194 bool isCursorVisible() const;
195 void setCursorVisible(bool on);
197 int cursorPosition() const;
198 void setCursorPosition(int cp);
200 QRectF cursorRectangle() const;
202 int selectionStart() const;
203 int selectionEnd() const;
205 QString selectedText() const;
207 int maxLength() const;
208 void setMaxLength(int ml);
210 #ifndef QT_NO_VALIDATOR
211 QValidator * validator() const;
212 void setValidator(QValidator* v);
214 QString inputMask() const;
215 void setInputMask(const QString &im);
217 EchoMode echoMode() const;
218 void setEchoMode(EchoMode echo);
220 QString passwordCharacter() const;
221 void setPasswordCharacter(const QString &str);
223 QString displayText() const;
225 QQmlComponent* cursorDelegate() const;
226 void setCursorDelegate(QQmlComponent*);
228 bool focusOnPress() const;
229 void setFocusOnPress(bool);
231 bool autoScroll() const;
232 void setAutoScroll(bool);
234 bool selectByMouse() const;
235 void setSelectByMouse(bool);
237 SelectionMode mouseSelectionMode() const;
238 void setMouseSelectionMode(SelectionMode mode);
240 bool persistentSelection() const;
241 void setPersistentSelection(bool persist);
243 bool hasAcceptableInput() const;
245 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
247 QRectF boundingRect() const;
248 QRectF clipRect() const;
250 #ifndef QT_NO_CLIPBOARD
251 bool canPaste() const;
254 bool canUndo() const;
255 bool canRedo() const;
257 bool isInputMethodComposing() const;
259 Qt::InputMethodHints inputMethodHints() const;
260 void setInputMethodHints(Qt::InputMethodHints hints);
262 Q_INVOKABLE QString getText(int start, int end) const;
264 qreal contentWidth() const;
265 qreal contentHeight() const;
269 void cursorPositionChanged();
270 void cursorRectangleChanged();
271 void selectionStartChanged();
272 void selectionEndChanged();
273 void selectedTextChanged();
275 void acceptableInputChanged();
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();
306 virtual void geometryChanged(const QRectF &newGeometry,
307 const QRectF &oldGeometry);
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);
325 void select(int start, int end);
327 bool isRightToLeft(int start, int end);
328 #ifndef QT_NO_CLIPBOARD
335 void insert(int position, const QString &text);
336 void remove(int start, int end);
339 void selectionChanged();
341 void updateCursorRectangle();
342 void q_canPasteChanged();
343 void q_updateAlignment();
344 void triggerPreprocess();
347 Q_DECLARE_PRIVATE(QQuickTextInput)
350 #ifndef QT_NO_VALIDATOR
351 class Q_AUTOTEST_EXPORT QQuickIntValidator : public QIntValidator
354 Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
356 QQuickIntValidator(QObject *parent = 0);
358 QString localeName() const;
359 void setLocaleName(const QString &name);
360 void resetLocaleName();
363 void localeNameChanged();
366 class Q_AUTOTEST_EXPORT QQuickDoubleValidator : public QDoubleValidator
369 Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
371 QQuickDoubleValidator(QObject *parent = 0);
373 QString localeName() const;
374 void setLocaleName(const QString &name);
375 void resetLocaleName();
378 void localeNameChanged();
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)
394 #endif // QQUICKTEXTINPUT_P_H