1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
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.
|
---|
23 | **
|
---|
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.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDECLARATIVETEXTINPUT_H
|
---|
43 | #define QDECLARATIVETEXTINPUT_H
|
---|
44 |
|
---|
45 | #include "private/qdeclarativetext_p.h"
|
---|
46 | #include "private/qdeclarativepainteditem_p.h"
|
---|
47 |
|
---|
48 | #include <QGraphicsSceneMouseEvent>
|
---|
49 | #include <QIntValidator>
|
---|
50 |
|
---|
51 | #ifndef QT_NO_LINEEDIT
|
---|
52 |
|
---|
53 | QT_BEGIN_HEADER
|
---|
54 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | QT_MODULE(Declarative)
|
---|
58 |
|
---|
59 | class QDeclarativeTextInputPrivate;
|
---|
60 | class QValidator;
|
---|
61 | class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativePaintedItem
|
---|
62 | {
|
---|
63 | Q_OBJECT
|
---|
64 | Q_ENUMS(HAlignment)
|
---|
65 | Q_ENUMS(EchoMode)
|
---|
66 |
|
---|
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 NOTIFY horizontalAlignmentChanged)
|
---|
73 |
|
---|
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 cursorPositionChanged)
|
---|
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)
|
---|
82 |
|
---|
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)
|
---|
86 | #endif
|
---|
87 | Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
|
---|
88 | Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
|
---|
89 |
|
---|
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 |
|
---|
98 | public:
|
---|
99 | QDeclarativeTextInput(QDeclarativeItem* parent=0);
|
---|
100 | ~QDeclarativeTextInput();
|
---|
101 |
|
---|
102 | enum EchoMode {//To match QLineEdit::EchoMode
|
---|
103 | Normal,
|
---|
104 | NoEcho,
|
---|
105 | Password,
|
---|
106 | PasswordEchoOnEdit
|
---|
107 | };
|
---|
108 |
|
---|
109 | enum HAlignment {
|
---|
110 | AlignLeft = Qt::AlignLeft,
|
---|
111 | AlignRight = Qt::AlignRight,
|
---|
112 | AlignHCenter = Qt::AlignHCenter
|
---|
113 | };
|
---|
114 |
|
---|
115 | //Auxilliary functions needed to control the TextInput from QML
|
---|
116 | Q_INVOKABLE int positionAt(int x) const;
|
---|
117 | Q_INVOKABLE QRectF positionToRectangle(int pos) const;
|
---|
118 | Q_INVOKABLE void moveCursorSelection(int pos);
|
---|
119 |
|
---|
120 | Q_INVOKABLE void openSoftwareInputPanel();
|
---|
121 | Q_INVOKABLE void closeSoftwareInputPanel();
|
---|
122 |
|
---|
123 | QString text() const;
|
---|
124 | void setText(const QString &);
|
---|
125 |
|
---|
126 | QFont font() const;
|
---|
127 | void setFont(const QFont &font);
|
---|
128 |
|
---|
129 | QColor color() const;
|
---|
130 | void setColor(const QColor &c);
|
---|
131 |
|
---|
132 | QColor selectionColor() const;
|
---|
133 | void setSelectionColor(const QColor &c);
|
---|
134 |
|
---|
135 | QColor selectedTextColor() const;
|
---|
136 | void setSelectedTextColor(const QColor &c);
|
---|
137 |
|
---|
138 | HAlignment hAlign() const;
|
---|
139 | void setHAlign(HAlignment align);
|
---|
140 |
|
---|
141 | bool isReadOnly() const;
|
---|
142 | void setReadOnly(bool);
|
---|
143 |
|
---|
144 | bool isCursorVisible() const;
|
---|
145 | void setCursorVisible(bool on);
|
---|
146 |
|
---|
147 | int cursorPosition() const;
|
---|
148 | void setCursorPosition(int cp);
|
---|
149 |
|
---|
150 | QRect cursorRectangle() const;
|
---|
151 |
|
---|
152 | int selectionStart() const;
|
---|
153 | int selectionEnd() const;
|
---|
154 |
|
---|
155 | QString selectedText() const;
|
---|
156 |
|
---|
157 | int maxLength() const;
|
---|
158 | void setMaxLength(int ml);
|
---|
159 |
|
---|
160 | #ifndef QT_NO_VALIDATOR
|
---|
161 | QValidator * validator() const;
|
---|
162 | void setValidator(QValidator* v);
|
---|
163 | #endif
|
---|
164 | QString inputMask() const;
|
---|
165 | void setInputMask(const QString &im);
|
---|
166 |
|
---|
167 | EchoMode echoMode() const;
|
---|
168 | void setEchoMode(EchoMode echo);
|
---|
169 |
|
---|
170 | QString passwordCharacter() const;
|
---|
171 | void setPasswordCharacter(const QString &str);
|
---|
172 |
|
---|
173 | QString displayText() const;
|
---|
174 |
|
---|
175 | QDeclarativeComponent* cursorDelegate() const;
|
---|
176 | void setCursorDelegate(QDeclarativeComponent*);
|
---|
177 |
|
---|
178 | bool focusOnPress() const;
|
---|
179 | void setFocusOnPress(bool);
|
---|
180 |
|
---|
181 | bool autoScroll() const;
|
---|
182 | void setAutoScroll(bool);
|
---|
183 |
|
---|
184 | bool selectByMouse() const;
|
---|
185 | void setSelectByMouse(bool);
|
---|
186 |
|
---|
187 | bool hasAcceptableInput() const;
|
---|
188 |
|
---|
189 | void drawContents(QPainter *p,const QRect &r);
|
---|
190 | QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
|
---|
191 |
|
---|
192 | QRectF boundingRect() const;
|
---|
193 |
|
---|
194 | Q_SIGNALS:
|
---|
195 | void textChanged();
|
---|
196 | void cursorPositionChanged();
|
---|
197 | void selectionStartChanged();
|
---|
198 | void selectionEndChanged();
|
---|
199 | void selectedTextChanged();
|
---|
200 | void accepted();
|
---|
201 | void acceptableInputChanged();
|
---|
202 | void colorChanged(const QColor &color);
|
---|
203 | void selectionColorChanged(const QColor &color);
|
---|
204 | void selectedTextColorChanged(const QColor &color);
|
---|
205 | void fontChanged(const QFont &font);
|
---|
206 | void horizontalAlignmentChanged(HAlignment alignment);
|
---|
207 | void readOnlyChanged(bool isReadOnly);
|
---|
208 | void cursorVisibleChanged(bool isCursorVisible);
|
---|
209 | void cursorDelegateChanged();
|
---|
210 | void maximumLengthChanged(int maximumLength);
|
---|
211 | void validatorChanged();
|
---|
212 | void inputMaskChanged(const QString &inputMask);
|
---|
213 | void echoModeChanged(EchoMode echoMode);
|
---|
214 | void passwordCharacterChanged();
|
---|
215 | void displayTextChanged();
|
---|
216 | void activeFocusOnPressChanged(bool activeFocusOnPress);
|
---|
217 | void autoScrollChanged(bool autoScroll);
|
---|
218 | void selectByMouseChanged(bool selectByMouse);
|
---|
219 |
|
---|
220 | protected:
|
---|
221 | virtual void geometryChanged(const QRectF &newGeometry,
|
---|
222 | const QRectF &oldGeometry);
|
---|
223 |
|
---|
224 | void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
---|
225 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
---|
226 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
---|
227 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
---|
228 | void keyPressEvent(QKeyEvent* ev);
|
---|
229 | void inputMethodEvent(QInputMethodEvent *);
|
---|
230 | bool event(QEvent *e);
|
---|
231 | void focusInEvent(QFocusEvent *event);
|
---|
232 |
|
---|
233 | public Q_SLOTS:
|
---|
234 | void selectAll();
|
---|
235 | void selectWord();
|
---|
236 | void select(int start, int end);
|
---|
237 | #ifndef QT_NO_CLIPBOARD
|
---|
238 | void cut();
|
---|
239 | void copy();
|
---|
240 | void paste();
|
---|
241 | #endif
|
---|
242 |
|
---|
243 | private Q_SLOTS:
|
---|
244 | void updateSize(bool needsRedraw = true);
|
---|
245 | void q_textChanged();
|
---|
246 | void selectionChanged();
|
---|
247 | void createCursor();
|
---|
248 | void moveCursor();
|
---|
249 | void cursorPosChanged();
|
---|
250 | void updateRect(const QRect &r = QRect());
|
---|
251 |
|
---|
252 | private:
|
---|
253 | Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeTextInput)
|
---|
254 | };
|
---|
255 |
|
---|
256 | QT_END_NAMESPACE
|
---|
257 |
|
---|
258 | QML_DECLARE_TYPE(QDeclarativeTextInput)
|
---|
259 | #ifndef QT_NO_VALIDATOR
|
---|
260 | QML_DECLARE_TYPE(QValidator)
|
---|
261 | QML_DECLARE_TYPE(QIntValidator)
|
---|
262 | QML_DECLARE_TYPE(QDoubleValidator)
|
---|
263 | QML_DECLARE_TYPE(QRegExpValidator)
|
---|
264 | #endif
|
---|
265 |
|
---|
266 | QT_END_HEADER
|
---|
267 |
|
---|
268 | #endif // QT_NO_LINEEDIT
|
---|
269 |
|
---|
270 | #endif // QDECLARATIVETEXTINPUT_H
|
---|