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 QtDeclarative 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 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
59 class QDeclarative1TextInputPrivate;
60 class Q_AUTOTEST_EXPORT QDeclarative1TextInput : public QDeclarative1ImplicitSizePaintedItem
65 Q_ENUMS(SelectionMode)
67 Q_PROPERTY(QString text READ text WRITE setText 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 REVISION 1)
74 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
75 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
76 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
77 Q_PROPERTY(QRect cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
78 Q_PROPERTY(QDeclarativeComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
79 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
80 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
81 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
83 Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
84 #ifndef QT_NO_VALIDATOR
85 Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
87 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
88 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
90 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
91 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
92 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
93 Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
94 Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
95 Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
96 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
97 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged REVISION 1)
98 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged REVISION 1)
99 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged REVISION 1)
102 QDeclarative1TextInput(QDeclarativeItem* parent=0);
103 ~QDeclarative1TextInput();
105 enum EchoMode {//To match QLineEdit::EchoMode
113 AlignLeft = Qt::AlignLeft,
114 AlignRight = Qt::AlignRight,
115 AlignHCenter = Qt::AlignHCenter
123 enum CursorPosition {
124 CursorBetweenCharacters,
128 //Auxilliary functions needed to control the TextInput from QML
129 Q_INVOKABLE int positionAt(int x) const;
130 Q_INVOKABLE Q_REVISION(1) int positionAt(int x, CursorPosition position) const;
131 Q_INVOKABLE QRectF positionToRectangle(int pos) const;
132 Q_INVOKABLE void moveCursorSelection(int pos);
133 Q_INVOKABLE Q_REVISION(1) void moveCursorSelection(int pos, SelectionMode mode);
135 Q_INVOKABLE void openSoftwareInputPanel();
136 Q_INVOKABLE void closeSoftwareInputPanel();
138 QString text() const;
139 void setText(const QString &);
142 void setFont(const QFont &font);
144 QColor color() const;
145 void setColor(const QColor &c);
147 QColor selectionColor() const;
148 void setSelectionColor(const QColor &c);
150 QColor selectedTextColor() const;
151 void setSelectedTextColor(const QColor &c);
153 HAlignment hAlign() const;
154 void setHAlign(HAlignment align);
156 HAlignment effectiveHAlign() const;
158 bool isReadOnly() const;
159 void setReadOnly(bool);
161 bool isCursorVisible() const;
162 void setCursorVisible(bool on);
164 int cursorPosition() const;
165 void setCursorPosition(int cp);
167 QRect cursorRectangle() const;
169 int selectionStart() const;
170 int selectionEnd() const;
172 QString selectedText() const;
174 int maxLength() const;
175 void setMaxLength(int ml);
177 #ifndef QT_NO_VALIDATOR
178 QValidator * validator() const;
179 void setValidator(QValidator* v);
181 QString inputMask() const;
182 void setInputMask(const QString &im);
184 EchoMode echoMode() const;
185 void setEchoMode(EchoMode echo);
187 QString passwordCharacter() const;
188 void setPasswordCharacter(const QString &str);
190 QString displayText() const;
192 QDeclarativeComponent* cursorDelegate() const;
193 void setCursorDelegate(QDeclarativeComponent*);
195 bool focusOnPress() const;
196 void setFocusOnPress(bool);
198 bool autoScroll() const;
199 void setAutoScroll(bool);
201 bool selectByMouse() const;
202 void setSelectByMouse(bool);
204 SelectionMode mouseSelectionMode() const;
205 void setMouseSelectionMode(SelectionMode mode);
207 bool hasAcceptableInput() const;
209 void drawContents(QPainter *p,const QRect &r);
210 QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
212 QRectF boundingRect() const;
213 bool canPaste() const;
215 bool isInputMethodComposing() const;
217 Qt::InputMethodHints imHints() const;
218 void setIMHints(Qt::InputMethodHints hints);
222 void cursorPositionChanged();
223 void cursorRectangleChanged();
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();
282 void cursorPosChanged();
283 void updateCursorRectangle();
284 void updateRect(const QRect &r = QRect());
285 void q_canPasteChanged();
288 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextInput)
293 QML_DECLARE_TYPE(QDeclarative1TextInput)
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