1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
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 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
43 #ifndef QSGTEXTINPUT_P_H
44 #define QSGTEXTINPUT_P_H
46 #include "qsgimplicitsizeitem_p.h"
47 #include <QtGui/qvalidator.h>
53 QT_MODULE(Declarative)
55 class QSGTextInputPrivate;
57 class Q_AUTOTEST_EXPORT QSGTextInput : public QSGImplicitSizePaintedItem
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 cursorPositionChanged)
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 inputMethodHints WRITE setInputMethodHints)
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 QSGTextInput(QSGItem * 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 void paint(QPainter *p);
208 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
210 QRectF boundingRect() const;
211 bool canPaste() const;
213 bool isInputMethodComposing() const;
217 void cursorPositionChanged();
218 void selectionStartChanged();
219 void selectionEndChanged();
220 void selectedTextChanged();
222 void acceptableInputChanged();
223 void colorChanged(const QColor &color);
224 void selectionColorChanged(const QColor &color);
225 void selectedTextColorChanged(const QColor &color);
226 void fontChanged(const QFont &font);
227 void horizontalAlignmentChanged(HAlignment alignment);
228 void readOnlyChanged(bool isReadOnly);
229 void cursorVisibleChanged(bool isCursorVisible);
230 void cursorDelegateChanged();
231 void maximumLengthChanged(int maximumLength);
232 void validatorChanged();
233 void inputMaskChanged(const QString &inputMask);
234 void echoModeChanged(EchoMode echoMode);
235 void passwordCharacterChanged();
236 void displayTextChanged();
237 void activeFocusOnPressChanged(bool activeFocusOnPress);
238 void autoScrollChanged(bool autoScroll);
239 void selectByMouseChanged(bool selectByMouse);
240 void mouseSelectionModeChanged(SelectionMode mode);
241 void canPasteChanged();
242 void inputMethodComposingChanged();
243 void effectiveHorizontalAlignmentChanged();
246 virtual void geometryChanged(const QRectF &newGeometry,
247 const QRectF &oldGeometry);
249 void mousePressEvent(QGraphicsSceneMouseEvent *event);
250 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
251 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
252 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
253 bool sceneEvent(QEvent *event);
254 void keyPressEvent(QKeyEvent* ev);
255 void inputMethodEvent(QInputMethodEvent *);
256 void mouseUngrabEvent();
257 bool event(QEvent *e);
258 void focusInEvent(QFocusEvent *event);
259 virtual void itemChange(ItemChange, const ItemChangeData &);
264 void select(int start, int end);
266 bool isRightToLeft(int start, int end);
267 #ifndef QT_NO_CLIPBOARD
274 void updateSize(bool needsRedraw = true);
275 void q_textChanged();
276 void selectionChanged();
279 void cursorPosChanged();
280 void updateRect(const QRect &r = QRect());
281 void q_canPasteChanged();
284 Q_DECLARE_PRIVATE(QSGTextInput)
289 QML_DECLARE_TYPE(QSGTextInput)
290 #ifndef QT_NO_VALIDATOR
291 QML_DECLARE_TYPE(QValidator)
292 QML_DECLARE_TYPE(QIntValidator)
293 QML_DECLARE_TYPE(QDoubleValidator)
294 QML_DECLARE_TYPE(QRegExpValidator)
299 #endif // QSGTEXTINPUT_P_H