1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETEXTINPUT_H
43 #define QDECLARATIVETEXTINPUT_H
45 #include "private/qdeclarativetext_p.h"
46 #include "private/qdeclarativeimplicitsizeitem_p.h"
48 #include <QGraphicsSceneMouseEvent>
49 #include <QIntValidator>
51 #ifndef QT_NO_LINEEDIT
57 QT_MODULE(Declarative)
59 class QDeclarativeTextInputPrivate;
61 class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativeImplicitSizePaintedItem
66 Q_ENUMS(SelectionMode)
68 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
69 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
70 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
71 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
72 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
73 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
74 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
75 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
76 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
77 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
78 Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorPositionChanged)
79 Q_PROPERTY(QDeclarativeComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
80 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
81 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
82 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
84 Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
85 #ifndef QT_NO_VALIDATOR
86 Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
88 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
89 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
91 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
92 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
93 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
94 Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
95 Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
96 Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
97 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
98 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged REVISION 1)
99 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged REVISION 1)
100 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged REVISION 1)
103 QDeclarativeTextInput(QDeclarativeItem* parent=0);
104 ~QDeclarativeTextInput();
106 enum EchoMode {//To match QLineEdit::EchoMode
114 AlignLeft = Qt::AlignLeft,
115 AlignRight = Qt::AlignRight,
116 AlignHCenter = Qt::AlignHCenter
124 enum CursorPosition {
125 CursorBetweenCharacters,
129 //Auxilliary functions needed to control the TextInput from QML
130 Q_INVOKABLE int positionAt(int x) const;
131 Q_INVOKABLE Q_REVISION(1) int positionAt(int x, CursorPosition position) const;
132 Q_INVOKABLE QRectF positionToRectangle(int pos) const;
133 Q_INVOKABLE void moveCursorSelection(int pos);
134 Q_INVOKABLE Q_REVISION(1) void moveCursorSelection(int pos, SelectionMode mode);
136 Q_INVOKABLE void openSoftwareInputPanel();
137 Q_INVOKABLE void closeSoftwareInputPanel();
139 QString text() const;
140 void setText(const QString &);
143 void setFont(const QFont &font);
145 QColor color() const;
146 void setColor(const QColor &c);
148 QColor selectionColor() const;
149 void setSelectionColor(const QColor &c);
151 QColor selectedTextColor() const;
152 void setSelectedTextColor(const QColor &c);
154 HAlignment hAlign() const;
155 void setHAlign(HAlignment align);
157 HAlignment effectiveHAlign() const;
159 bool isReadOnly() const;
160 void setReadOnly(bool);
162 bool isCursorVisible() const;
163 void setCursorVisible(bool on);
165 int cursorPosition() const;
166 void setCursorPosition(int cp);
168 QRect cursorRectangle() const;
170 int selectionStart() const;
171 int selectionEnd() const;
173 QString selectedText() const;
175 int maxLength() const;
176 void setMaxLength(int ml);
178 #ifndef QT_NO_VALIDATOR
179 QValidator * validator() const;
180 void setValidator(QValidator* v);
182 QString inputMask() const;
183 void setInputMask(const QString &im);
185 EchoMode echoMode() const;
186 void setEchoMode(EchoMode echo);
188 QString passwordCharacter() const;
189 void setPasswordCharacter(const QString &str);
191 QString displayText() const;
193 QDeclarativeComponent* cursorDelegate() const;
194 void setCursorDelegate(QDeclarativeComponent*);
196 bool focusOnPress() const;
197 void setFocusOnPress(bool);
199 bool autoScroll() const;
200 void setAutoScroll(bool);
202 bool selectByMouse() const;
203 void setSelectByMouse(bool);
205 SelectionMode mouseSelectionMode() const;
206 void setMouseSelectionMode(SelectionMode mode);
208 bool hasAcceptableInput() const;
210 void drawContents(QPainter *p,const QRect &r);
211 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
213 QRectF boundingRect() const;
214 bool canPaste() const;
216 bool isInputMethodComposing() const;
218 Qt::InputMethodHints imHints() const;
219 void setIMHints(Qt::InputMethodHints hints);
223 void cursorPositionChanged();
224 void selectionStartChanged();
225 void selectionEndChanged();
226 void selectedTextChanged();
228 void acceptableInputChanged();
229 void colorChanged(const QColor &color);
230 void selectionColorChanged(const QColor &color);
231 void selectedTextColorChanged(const QColor &color);
232 void fontChanged(const QFont &font);
233 void horizontalAlignmentChanged(HAlignment alignment);
234 void readOnlyChanged(bool isReadOnly);
235 void cursorVisibleChanged(bool isCursorVisible);
236 void cursorDelegateChanged();
237 void maximumLengthChanged(int maximumLength);
238 void validatorChanged();
239 void inputMaskChanged(const QString &inputMask);
240 void echoModeChanged(EchoMode echoMode);
241 void passwordCharacterChanged();
242 void displayTextChanged();
243 void activeFocusOnPressChanged(bool activeFocusOnPress);
244 void autoScrollChanged(bool autoScroll);
245 void selectByMouseChanged(bool selectByMouse);
246 Q_REVISION(1) void mouseSelectionModeChanged(SelectionMode mode);
247 Q_REVISION(1) void canPasteChanged();
248 Q_REVISION(1) void inputMethodComposingChanged();
249 Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
252 virtual void geometryChanged(const QRectF &newGeometry,
253 const QRectF &oldGeometry);
255 void mousePressEvent(QGraphicsSceneMouseEvent *event);
256 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
257 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
258 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
259 bool sceneEvent(QEvent *event);
260 void keyPressEvent(QKeyEvent* ev);
261 void inputMethodEvent(QInputMethodEvent *);
262 bool event(QEvent *e);
263 void focusInEvent(QFocusEvent *event);
268 void select(int start, int end);
269 Q_REVISION(1) void deselect();
270 Q_REVISION(1) bool isRightToLeft(int start, int end);
271 #ifndef QT_NO_CLIPBOARD
278 void updateSize(bool needsRedraw = true);
279 void q_textChanged();
280 void selectionChanged();
283 void cursorPosChanged();
284 void updateRect(const QRect &r = QRect());
285 void q_canPasteChanged();
288 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeTextInput)
293 QML_DECLARE_TYPE(QDeclarativeTextInput)
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 // QT_NO_LINEEDIT
305 #endif // QDECLARATIVETEXTINPUT_H