|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtDeclarative module of the Qt Toolkit. |
|
8 ** |
|
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 |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 QT_BEGIN_HEADER |
|
52 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 QT_MODULE(Declarative) |
|
56 |
|
57 class QDeclarativeTextInputPrivate; |
|
58 class QValidator; |
|
59 class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedItem |
|
60 { |
|
61 Q_OBJECT |
|
62 Q_ENUMS(HAlignment) |
|
63 Q_ENUMS(EchoMode) |
|
64 |
|
65 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) |
|
66 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
67 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged) |
|
68 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged) |
|
69 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
70 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged) |
|
71 |
|
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 cursorRect READ cursorRect NOTIFY cursorPositionChanged) |
|
76 Q_PROPERTY(QDeclarativeComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged) |
|
77 Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) |
|
78 Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) |
|
79 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) |
|
80 |
|
81 Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged) |
|
82 Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged) |
|
83 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged) |
|
84 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) |
|
85 |
|
86 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) |
|
87 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged) |
|
88 Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged) |
|
89 Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged) |
|
90 Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged) |
|
91 Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged) |
|
92 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged) |
|
93 |
|
94 public: |
|
95 QDeclarativeTextInput(QDeclarativeItem* parent=0); |
|
96 ~QDeclarativeTextInput(); |
|
97 |
|
98 enum EchoMode {//To match QLineEdit::EchoMode |
|
99 Normal, |
|
100 NoEcho, |
|
101 Password, |
|
102 PasswordEchoOnEdit |
|
103 }; |
|
104 |
|
105 enum HAlignment { |
|
106 AlignLeft = Qt::AlignLeft, |
|
107 AlignRight = Qt::AlignRight, |
|
108 AlignHCenter = Qt::AlignHCenter |
|
109 }; |
|
110 |
|
111 //Auxilliary functions needed to control the TextInput from QML |
|
112 Q_INVOKABLE int xToPosition(int x); |
|
113 Q_INVOKABLE void moveCursorSelection(int pos); |
|
114 |
|
115 QString text() const; |
|
116 void setText(const QString &); |
|
117 |
|
118 QFont font() const; |
|
119 void setFont(const QFont &font); |
|
120 |
|
121 QColor color() const; |
|
122 void setColor(const QColor &c); |
|
123 |
|
124 QColor selectionColor() const; |
|
125 void setSelectionColor(const QColor &c); |
|
126 |
|
127 QColor selectedTextColor() const; |
|
128 void setSelectedTextColor(const QColor &c); |
|
129 |
|
130 HAlignment hAlign() const; |
|
131 void setHAlign(HAlignment align); |
|
132 |
|
133 bool isReadOnly() const; |
|
134 void setReadOnly(bool); |
|
135 |
|
136 bool isCursorVisible() const; |
|
137 void setCursorVisible(bool on); |
|
138 |
|
139 int cursorPosition() const; |
|
140 void setCursorPosition(int cp); |
|
141 |
|
142 QRect cursorRect() const; |
|
143 |
|
144 int selectionStart() const; |
|
145 void setSelectionStart(int); |
|
146 |
|
147 int selectionEnd() const; |
|
148 void setSelectionEnd(int); |
|
149 |
|
150 QString selectedText() const; |
|
151 |
|
152 int maxLength() const; |
|
153 void setMaxLength(int ml); |
|
154 |
|
155 QValidator * validator() const; |
|
156 void setValidator(QValidator* v); |
|
157 |
|
158 QString inputMask() const; |
|
159 void setInputMask(const QString &im); |
|
160 |
|
161 EchoMode echoMode() const; |
|
162 void setEchoMode(EchoMode echo); |
|
163 |
|
164 QString passwordCharacter() const; |
|
165 void setPasswordCharacter(const QString &str); |
|
166 |
|
167 QString displayText() const; |
|
168 |
|
169 QDeclarativeComponent* cursorDelegate() const; |
|
170 void setCursorDelegate(QDeclarativeComponent*); |
|
171 |
|
172 bool focusOnPress() const; |
|
173 void setFocusOnPress(bool); |
|
174 |
|
175 bool autoScroll() const; |
|
176 void setAutoScroll(bool); |
|
177 |
|
178 bool selectByMouse() const; |
|
179 void setSelectByMouse(bool); |
|
180 |
|
181 bool hasAcceptableInput() const; |
|
182 |
|
183 void drawContents(QPainter *p,const QRect &r); |
|
184 QVariant inputMethodQuery(Qt::InputMethodQuery property) const; |
|
185 |
|
186 Q_SIGNALS: |
|
187 void textChanged(); |
|
188 void cursorPositionChanged(); |
|
189 void selectionStartChanged(); |
|
190 void selectionEndChanged(); |
|
191 void selectedTextChanged(); |
|
192 void accepted(); |
|
193 void acceptableInputChanged(); |
|
194 void colorChanged(const QColor &color); |
|
195 void selectionColorChanged(const QColor &color); |
|
196 void selectedTextColorChanged(const QColor &color); |
|
197 void fontChanged(const QFont &font); |
|
198 void horizontalAlignmentChanged(HAlignment alignment); |
|
199 void readOnlyChanged(bool isReadOnly); |
|
200 void cursorVisibleChanged(bool isCursorVisible); |
|
201 void cursorDelegateChanged(); |
|
202 void maximumLengthChanged(int maximumLength); |
|
203 void validatorChanged(); |
|
204 void inputMaskChanged(const QString &inputMask); |
|
205 void echoModeChanged(EchoMode echoMode); |
|
206 void passwordCharacterChanged(); |
|
207 void displayTextChanged(const QString &text); |
|
208 void focusOnPressChanged(bool focusOnPress); |
|
209 void autoScrollChanged(bool autoScroll); |
|
210 void selectByMouseChanged(bool selectByMouse); |
|
211 |
|
212 protected: |
|
213 virtual void geometryChanged(const QRectF &newGeometry, |
|
214 const QRectF &oldGeometry); |
|
215 |
|
216 void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
217 void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
218 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
219 void keyPressEvent(QKeyEvent* ev); |
|
220 bool event(QEvent *e); |
|
221 |
|
222 public Q_SLOTS: |
|
223 void selectAll(); |
|
224 |
|
225 private Q_SLOTS: |
|
226 void updateSize(bool needsRedraw = true); |
|
227 void q_textChanged(); |
|
228 void selectionChanged(); |
|
229 void createCursor(); |
|
230 void moveCursor(); |
|
231 void cursorPosChanged(); |
|
232 void updateRect(const QRect &r = QRect()); |
|
233 |
|
234 private: |
|
235 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeTextInput) |
|
236 }; |
|
237 |
|
238 QT_END_NAMESPACE |
|
239 |
|
240 QML_DECLARE_TYPE(QDeclarativeTextInput) |
|
241 QML_DECLARE_TYPE(QValidator) |
|
242 QML_DECLARE_TYPE(QIntValidator) |
|
243 QML_DECLARE_TYPE(QDoubleValidator) |
|
244 QML_DECLARE_TYPE(QRegExpValidator) |
|
245 |
|
246 QT_END_HEADER |
|
247 |
|
248 #endif // QDECLARATIVETEXTINPUT_H |