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 ** 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.
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)
60 class QDeclarative1TextInputPrivate;
61 class Q_AUTOTEST_EXPORT QDeclarative1TextInput : public QDeclarative1ImplicitSizePaintedItem
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 cursorRectangleChanged)
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 QDeclarative1TextInput(QDeclarativeItem* parent=0);
104 ~QDeclarative1TextInput();
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 cursorRectangleChanged();
225 void selectionStartChanged();
226 void selectionEndChanged();
227 void selectedTextChanged();
229 void acceptableInputChanged();
230 void colorChanged(const QColor &color);
231 void selectionColorChanged(const QColor &color);
232 void selectedTextColorChanged(const QColor &color);
233 void fontChanged(const QFont &font);
234 void horizontalAlignmentChanged(HAlignment alignment);
235 void readOnlyChanged(bool isReadOnly);
236 void cursorVisibleChanged(bool isCursorVisible);
237 void cursorDelegateChanged();
238 void maximumLengthChanged(int maximumLength);
239 void validatorChanged();
240 void inputMaskChanged(const QString &inputMask);
241 void echoModeChanged(EchoMode echoMode);
242 void passwordCharacterChanged();
243 void displayTextChanged();
244 void activeFocusOnPressChanged(bool activeFocusOnPress);
245 void autoScrollChanged(bool autoScroll);
246 void selectByMouseChanged(bool selectByMouse);
247 Q_REVISION(1) void mouseSelectionModeChanged(SelectionMode mode);
248 Q_REVISION(1) void canPasteChanged();
249 Q_REVISION(1) void inputMethodComposingChanged();
250 Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
253 virtual void geometryChanged(const QRectF &newGeometry,
254 const QRectF &oldGeometry);
256 void mousePressEvent(QGraphicsSceneMouseEvent *event);
257 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
258 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
259 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
260 bool sceneEvent(QEvent *event);
261 void keyPressEvent(QKeyEvent* ev);
262 void inputMethodEvent(QInputMethodEvent *);
263 bool event(QEvent *e);
264 void focusInEvent(QFocusEvent *event);
269 void select(int start, int end);
270 Q_REVISION(1) void deselect();
271 Q_REVISION(1) bool isRightToLeft(int start, int end);
272 #ifndef QT_NO_CLIPBOARD
279 void updateSize(bool needsRedraw = true);
280 void q_textChanged();
281 void selectionChanged();
283 void cursorPosChanged();
284 void updateCursorRectangle();
285 void updateRect(const QRect &r = QRect());
286 void q_canPasteChanged();
289 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextInput)
294 QML_DECLARE_TYPE(QDeclarative1TextInput)
295 #ifndef QT_NO_VALIDATOR
296 QML_DECLARE_TYPE(QValidator)
297 QML_DECLARE_TYPE(QIntValidator)
298 QML_DECLARE_TYPE(QDoubleValidator)
299 QML_DECLARE_TYPE(QRegExpValidator)
304 #endif // QT_NO_LINEEDIT
306 #endif // QDECLARATIVETEXTINPUT_H