Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgtextinput_p.h
1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGTEXTINPUT_P_H
44 #define QSGTEXTINPUT_P_H
45
46 #include "qsgimplicitsizeitem_p.h"
47 #include <QtGui/qvalidator.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 QT_MODULE(Declarative)
54
55 class QSGTextInputPrivate;
56 class QValidator;
57 class Q_AUTOTEST_EXPORT QSGTextInput : public QSGImplicitSizePaintedItem
58 {
59     Q_OBJECT
60     Q_ENUMS(HAlignment)
61     Q_ENUMS(EchoMode)
62     Q_ENUMS(SelectionMode)
63
64     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
65     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
66     Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
67     Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
68     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
69     Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
70     Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
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 cursorRectangle READ cursorRectangle NOTIFY cursorPositionChanged)
76     Q_PROPERTY(QDeclarativeComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
77     Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
78     Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
79     Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
80
81     Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
82 #ifndef QT_NO_VALIDATOR
83     Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
84 #endif
85     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
86     Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
87
88     Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
89     Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
90     Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
91     Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
92     Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
93     Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
94     Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
95     Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
96     Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
97     Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
98
99 public:
100     QSGTextInput(QSGItem * parent=0);
101     ~QSGTextInput();
102
103     enum EchoMode {//To match QLineEdit::EchoMode
104         Normal,
105         NoEcho,
106         Password,
107         PasswordEchoOnEdit
108     };
109
110     enum HAlignment {
111         AlignLeft = Qt::AlignLeft,
112         AlignRight = Qt::AlignRight,
113         AlignHCenter = Qt::AlignHCenter
114     };
115
116     enum SelectionMode {
117         SelectCharacters,
118         SelectWords
119     };
120
121     enum CursorPosition {
122         CursorBetweenCharacters,
123         CursorOnCharacter
124     };
125
126     //Auxilliary functions needed to control the TextInput from QML
127     Q_INVOKABLE int positionAt(int x) const;
128     Q_INVOKABLE int positionAt(int x, CursorPosition position) const;
129     Q_INVOKABLE QRectF positionToRectangle(int pos) const;
130     Q_INVOKABLE void moveCursorSelection(int pos);
131     Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
132
133     Q_INVOKABLE void openSoftwareInputPanel();
134     Q_INVOKABLE void closeSoftwareInputPanel();
135
136     QString text() const;
137     void setText(const QString &);
138
139     QFont font() const;
140     void setFont(const QFont &font);
141
142     QColor color() const;
143     void setColor(const QColor &c);
144
145     QColor selectionColor() const;
146     void setSelectionColor(const QColor &c);
147
148     QColor selectedTextColor() const;
149     void setSelectedTextColor(const QColor &c);
150
151     HAlignment hAlign() const;
152     void setHAlign(HAlignment align);
153     void resetHAlign();
154     HAlignment effectiveHAlign() const;
155
156     bool isReadOnly() const;
157     void setReadOnly(bool);
158
159     bool isCursorVisible() const;
160     void setCursorVisible(bool on);
161
162     int cursorPosition() const;
163     void setCursorPosition(int cp);
164
165     QRect cursorRectangle() const;
166
167     int selectionStart() const;
168     int selectionEnd() const;
169
170     QString selectedText() const;
171
172     int maxLength() const;
173     void setMaxLength(int ml);
174
175 #ifndef QT_NO_VALIDATOR
176     QValidator * validator() const;
177     void setValidator(QValidator* v);
178 #endif
179     QString inputMask() const;
180     void setInputMask(const QString &im);
181
182     EchoMode echoMode() const;
183     void setEchoMode(EchoMode echo);
184
185     QString passwordCharacter() const;
186     void setPasswordCharacter(const QString &str);
187
188     QString displayText() const;
189
190     QDeclarativeComponent* cursorDelegate() const;
191     void setCursorDelegate(QDeclarativeComponent*);
192
193     bool focusOnPress() const;
194     void setFocusOnPress(bool);
195
196     bool autoScroll() const;
197     void setAutoScroll(bool);
198
199     bool selectByMouse() const;
200     void setSelectByMouse(bool);
201
202     SelectionMode mouseSelectionMode() const;
203     void setMouseSelectionMode(SelectionMode mode);
204
205     bool hasAcceptableInput() const;
206
207     void paint(QPainter *p);
208     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
209
210     QRectF boundingRect() const;
211     bool canPaste() const;
212
213     bool isInputMethodComposing() const;
214
215 Q_SIGNALS:
216     void textChanged();
217     void cursorPositionChanged();
218     void selectionStartChanged();
219     void selectionEndChanged();
220     void selectedTextChanged();
221     void accepted();
222     void acceptableInputChanged();
223     void colorChanged(const QColor &color);
224     void selectionColorChanged(const QColor &color);
225     void selectedTextColorChanged(const QColor &color);
226     void fontChanged(const QFont &font);
227     void horizontalAlignmentChanged(HAlignment alignment);
228     void readOnlyChanged(bool isReadOnly);
229     void cursorVisibleChanged(bool isCursorVisible);
230     void cursorDelegateChanged();
231     void maximumLengthChanged(int maximumLength);
232     void validatorChanged();
233     void inputMaskChanged(const QString &inputMask);
234     void echoModeChanged(EchoMode echoMode);
235     void passwordCharacterChanged();
236     void displayTextChanged();
237     void activeFocusOnPressChanged(bool activeFocusOnPress);
238     void autoScrollChanged(bool autoScroll);
239     void selectByMouseChanged(bool selectByMouse);
240     void mouseSelectionModeChanged(SelectionMode mode);
241     void canPasteChanged();
242     void inputMethodComposingChanged();
243     void effectiveHorizontalAlignmentChanged();
244
245 protected:
246     virtual void geometryChanged(const QRectF &newGeometry,
247                                  const QRectF &oldGeometry);
248
249     void mousePressEvent(QGraphicsSceneMouseEvent *event);
250     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
251     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
252     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
253     bool sceneEvent(QEvent *event);
254     void keyPressEvent(QKeyEvent* ev);
255     void inputMethodEvent(QInputMethodEvent *);
256     void mouseUngrabEvent();
257     bool event(QEvent *e);
258     void focusInEvent(QFocusEvent *event);
259     virtual void itemChange(ItemChange, const ItemChangeData &);
260
261 public Q_SLOTS:
262     void selectAll();
263     void selectWord();
264     void select(int start, int end);
265     void deselect();
266     bool isRightToLeft(int start, int end);
267 #ifndef QT_NO_CLIPBOARD
268     void cut();
269     void copy();
270     void paste();
271 #endif
272
273 private Q_SLOTS:
274     void updateSize(bool needsRedraw = true);
275     void q_textChanged();
276     void selectionChanged();
277     void createCursor();
278     void moveCursor();
279     void cursorPosChanged();
280     void updateRect(const QRect &r = QRect());
281     void q_canPasteChanged();
282
283 private:
284     Q_DECLARE_PRIVATE(QSGTextInput)
285 };
286
287 QT_END_NAMESPACE
288
289 QML_DECLARE_TYPE(QSGTextInput)
290 #ifndef QT_NO_VALIDATOR
291 QML_DECLARE_TYPE(QValidator)
292 QML_DECLARE_TYPE(QIntValidator)
293 QML_DECLARE_TYPE(QDoubleValidator)
294 QML_DECLARE_TYPE(QRegExpValidator)
295 #endif
296
297 QT_END_HEADER
298
299 #endif // QSGTEXTINPUT_P_H