Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / graphicsitems / qdeclarativetextinput_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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/qdeclarativeimplicitsizeitem_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 QDeclarativeImplicitSizePaintedItem
62 {
63     Q_OBJECT
64     Q_ENUMS(HAlignment)
65     Q_ENUMS(EchoMode)
66     Q_ENUMS(SelectionMode)
67
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)
83
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)
87 #endif
88     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
89     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
90
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)
101
102 public:
103     QDeclarativeTextInput(QDeclarativeItem* parent=0);
104     ~QDeclarativeTextInput();
105
106     enum EchoMode {//To match QLineEdit::EchoMode
107         Normal,
108         NoEcho,
109         Password,
110         PasswordEchoOnEdit
111     };
112
113     enum HAlignment {
114         AlignLeft = Qt::AlignLeft,
115         AlignRight = Qt::AlignRight,
116         AlignHCenter = Qt::AlignHCenter
117     };
118
119     enum SelectionMode {
120         SelectCharacters,
121         SelectWords
122     };
123
124     enum CursorPosition {
125         CursorBetweenCharacters,
126         CursorOnCharacter
127     };
128
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);
135
136     Q_INVOKABLE void openSoftwareInputPanel();
137     Q_INVOKABLE void closeSoftwareInputPanel();
138
139     QString text() const;
140     void setText(const QString &);
141
142     QFont font() const;
143     void setFont(const QFont &font);
144
145     QColor color() const;
146     void setColor(const QColor &c);
147
148     QColor selectionColor() const;
149     void setSelectionColor(const QColor &c);
150
151     QColor selectedTextColor() const;
152     void setSelectedTextColor(const QColor &c);
153
154     HAlignment hAlign() const;
155     void setHAlign(HAlignment align);
156     void resetHAlign();
157     HAlignment effectiveHAlign() const;
158
159     bool isReadOnly() const;
160     void setReadOnly(bool);
161
162     bool isCursorVisible() const;
163     void setCursorVisible(bool on);
164
165     int cursorPosition() const;
166     void setCursorPosition(int cp);
167
168     QRect cursorRectangle() const;
169
170     int selectionStart() const;
171     int selectionEnd() const;
172
173     QString selectedText() const;
174
175     int maxLength() const;
176     void setMaxLength(int ml);
177
178 #ifndef QT_NO_VALIDATOR
179     QValidator * validator() const;
180     void setValidator(QValidator* v);
181 #endif
182     QString inputMask() const;
183     void setInputMask(const QString &im);
184
185     EchoMode echoMode() const;
186     void setEchoMode(EchoMode echo);
187
188     QString passwordCharacter() const;
189     void setPasswordCharacter(const QString &str);
190
191     QString displayText() const;
192
193     QDeclarativeComponent* cursorDelegate() const;
194     void setCursorDelegate(QDeclarativeComponent*);
195
196     bool focusOnPress() const;
197     void setFocusOnPress(bool);
198
199     bool autoScroll() const;
200     void setAutoScroll(bool);
201
202     bool selectByMouse() const;
203     void setSelectByMouse(bool);
204
205     SelectionMode mouseSelectionMode() const;
206     void setMouseSelectionMode(SelectionMode mode);
207
208     bool hasAcceptableInput() const;
209
210     void drawContents(QPainter *p,const QRect &r);
211     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
212
213     QRectF boundingRect() const;
214     bool canPaste() const;
215
216     bool isInputMethodComposing() const;
217
218     Qt::InputMethodHints imHints() const;
219     void setIMHints(Qt::InputMethodHints hints);
220
221 Q_SIGNALS:
222     void textChanged();
223     void cursorPositionChanged();
224     void selectionStartChanged();
225     void selectionEndChanged();
226     void selectedTextChanged();
227     void accepted();
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();
250
251 protected:
252     virtual void geometryChanged(const QRectF &newGeometry,
253                                  const QRectF &oldGeometry);
254
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);
264
265 public Q_SLOTS:
266     void selectAll();
267     void selectWord();
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
272     void cut();
273     void copy();
274     void paste();
275 #endif
276
277 private Q_SLOTS:
278     void updateSize(bool needsRedraw = true);
279     void q_textChanged();
280     void selectionChanged();
281     void createCursor();
282     void moveCursor();
283     void cursorPosChanged();
284     void updateRect(const QRect &r = QRect());
285     void q_canPasteChanged();
286
287 private:
288     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeTextInput)
289 };
290
291 QT_END_NAMESPACE
292
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)
299 #endif
300
301 QT_END_HEADER
302
303 #endif // QT_NO_LINEEDIT
304
305 #endif // QDECLARATIVETEXTINPUT_H