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)
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(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
81 Q_PROPERTY(QQmlComponent *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 inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
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 persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
102 #ifndef QT_NO_CLIPBOARD
103 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
105 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
106 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
107 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
108 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
109 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
110 Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
113 QQuickTextInput(QQuickItem * parent=0);
116 void componentComplete();
118 enum EchoMode {//To match QLineEdit::EchoMode
126 AlignLeft = Qt::AlignLeft,
127 AlignRight = Qt::AlignRight,
128 AlignHCenter = Qt::AlignHCenter
132 AlignTop = Qt::AlignTop,
133 AlignBottom = Qt::AlignBottom,
134 AlignVCenter = Qt::AlignVCenter
138 NoWrap = QTextOption::NoWrap,
139 WordWrap = QTextOption::WordWrap,
140 WrapAnywhere = QTextOption::WrapAnywhere,
141 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
142 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
150 enum CursorPosition {
151 CursorBetweenCharacters,
155 enum RenderType { QtRendering,
159 //Auxilliary functions needed to control the TextInput from QML
160 Q_INVOKABLE void positionAt(QQmlV8Function *args) const;
161 Q_INVOKABLE QRectF positionToRectangle(int pos) const;
162 Q_INVOKABLE void moveCursorSelection(int pos);
163 Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
165 RenderType renderType() const;
166 void setRenderType(RenderType renderType);
168 QString text() const;
169 void setText(const QString &);
174 void setFont(const QFont &font);
176 QColor color() const;
177 void setColor(const QColor &c);
179 QColor selectionColor() const;
180 void setSelectionColor(const QColor &c);
182 QColor selectedTextColor() const;
183 void setSelectedTextColor(const QColor &c);
185 HAlignment hAlign() const;
186 void setHAlign(HAlignment align);
188 HAlignment effectiveHAlign() const;
190 VAlignment vAlign() const;
191 void setVAlign(VAlignment align);
193 WrapMode wrapMode() const;
194 void setWrapMode(WrapMode w);
196 bool isReadOnly() const;
197 void setReadOnly(bool);
199 bool isCursorVisible() const;
200 void setCursorVisible(bool on);
202 int cursorPosition() const;
203 void setCursorPosition(int cp);
205 QRectF cursorRectangle() const;
207 int selectionStart() const;
208 int selectionEnd() const;
210 QString selectedText() const;
212 int maxLength() const;
213 void setMaxLength(int ml);
215 #ifndef QT_NO_VALIDATOR
216 QValidator * validator() const;
217 void setValidator(QValidator* v);
219 QString inputMask() const;
220 void setInputMask(const QString &im);
222 EchoMode echoMode() const;
223 void setEchoMode(EchoMode echo);
225 QString passwordCharacter() const;
226 void setPasswordCharacter(const QString &str);
228 QString displayText() const;
230 QQmlComponent* cursorDelegate() const;
231 void setCursorDelegate(QQmlComponent*);
233 bool focusOnPress() const;
234 void setFocusOnPress(bool);
236 bool autoScroll() const;
237 void setAutoScroll(bool);
239 bool selectByMouse() const;
240 void setSelectByMouse(bool);
242 SelectionMode mouseSelectionMode() const;
243 void setMouseSelectionMode(SelectionMode mode);
245 bool persistentSelection() const;
246 void setPersistentSelection(bool persist);
248 bool hasAcceptableInput() const;
250 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
252 QRectF boundingRect() const;
253 QRectF clipRect() const;
255 #ifndef QT_NO_CLIPBOARD
256 bool canPaste() const;
259 bool canUndo() const;
260 bool canRedo() const;
262 bool isInputMethodComposing() const;
264 Qt::InputMethodHints inputMethodHints() const;
265 void setInputMethodHints(Qt::InputMethodHints hints);
267 Q_INVOKABLE QString getText(int start, int end) const;
269 qreal contentWidth() const;
270 qreal contentHeight() const;
274 void cursorPositionChanged();
275 void cursorRectangleChanged();
276 void selectionStartChanged();
277 void selectionEndChanged();
278 void selectedTextChanged();
280 void acceptableInputChanged();
282 void selectionColorChanged();
283 void selectedTextColorChanged();
284 void fontChanged(const QFont &font);
285 void horizontalAlignmentChanged(HAlignment alignment);
286 void verticalAlignmentChanged(VAlignment alignment);
287 void wrapModeChanged();
288 void readOnlyChanged(bool isReadOnly);
289 void cursorVisibleChanged(bool isCursorVisible);
290 void cursorDelegateChanged();
291 void maximumLengthChanged(int maximumLength);
292 void validatorChanged();
293 void inputMaskChanged(const QString &inputMask);
294 void echoModeChanged(EchoMode echoMode);
295 void passwordCharacterChanged();
296 void displayTextChanged();
297 void activeFocusOnPressChanged(bool activeFocusOnPress);
298 void autoScrollChanged(bool autoScroll);
299 void selectByMouseChanged(bool selectByMouse);
300 void mouseSelectionModeChanged(SelectionMode mode);
301 void persistentSelectionChanged();
302 void canPasteChanged();
303 void canUndoChanged();
304 void canRedoChanged();
305 void inputMethodComposingChanged();
306 void effectiveHorizontalAlignmentChanged();
307 void contentSizeChanged();
308 void inputMethodHintsChanged();
309 void renderTypeChanged();
312 virtual void geometryChanged(const QRectF &newGeometry,
313 const QRectF &oldGeometry);
315 void mousePressEvent(QMouseEvent *event);
316 void mouseMoveEvent(QMouseEvent *event);
317 void mouseReleaseEvent(QMouseEvent *event);
318 void mouseDoubleClickEvent(QMouseEvent *event);
319 void keyPressEvent(QKeyEvent* ev);
320 void inputMethodEvent(QInputMethodEvent *);
321 void mouseUngrabEvent();
322 bool event(QEvent *e);
323 void focusInEvent(QFocusEvent *event);
324 void timerEvent(QTimerEvent *event);
325 virtual void itemChange(ItemChange, const ItemChangeData &);
326 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data);
331 void select(int start, int end);
333 bool isRightToLeft(int start, int end);
334 #ifndef QT_NO_CLIPBOARD
341 void insert(int position, const QString &text);
342 void remove(int start, int end);
345 void selectionChanged();
347 void updateCursorRectangle();
348 void q_canPasteChanged();
349 void q_updateAlignment();
350 void triggerPreprocess();
352 #ifndef QT_NO_VALIDATOR
353 void q_validatorChanged();
357 friend class QQuickTextUtil;
359 Q_DECLARE_PRIVATE(QQuickTextInput)
362 #ifndef QT_NO_VALIDATOR
363 class Q_AUTOTEST_EXPORT QQuickIntValidator : public QIntValidator
366 Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
368 QQuickIntValidator(QObject *parent = 0);
370 QString localeName() const;
371 void setLocaleName(const QString &name);
372 void resetLocaleName();
375 void localeNameChanged();
378 class Q_AUTOTEST_EXPORT QQuickDoubleValidator : public QDoubleValidator
381 Q_PROPERTY(QString locale READ localeName WRITE setLocaleName RESET resetLocaleName NOTIFY localeNameChanged)
383 QQuickDoubleValidator(QObject *parent = 0);
385 QString localeName() const;
386 void setLocaleName(const QString &name);
387 void resetLocaleName();
390 void localeNameChanged();
396 QML_DECLARE_TYPE(QQuickTextInput)
397 #ifndef QT_NO_VALIDATOR
398 QML_DECLARE_TYPE(QValidator)
399 QML_DECLARE_TYPE(QQuickIntValidator)
400 QML_DECLARE_TYPE(QQuickDoubleValidator)
401 QML_DECLARE_TYPE(QRegExpValidator)
406 #endif // QQUICKTEXTINPUT_P_H