acf5accae807b6fed3dd2b0f0c56218b901ca037
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativetextinput_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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
58 class QValidator;
59 class QDeclarative1TextInputPrivate;
60 class Q_AUTOTEST_EXPORT QDeclarative1TextInput : public QDeclarative1ImplicitSizePaintedItem
61 {
62     Q_OBJECT
63     Q_ENUMS(HAlignment)
64     Q_ENUMS(EchoMode)
65     Q_ENUMS(SelectionMode)
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 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)
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 imHints WRITE setIMHints)
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     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)
100
101 public:
102     QDeclarative1TextInput(QDeclarativeItem* parent=0);
103     ~QDeclarative1TextInput();
104
105     enum EchoMode {//To match QLineEdit::EchoMode
106         Normal,
107         NoEcho,
108         Password,
109         PasswordEchoOnEdit
110     };
111
112     enum HAlignment {
113         AlignLeft = Qt::AlignLeft,
114         AlignRight = Qt::AlignRight,
115         AlignHCenter = Qt::AlignHCenter
116     };
117
118     enum SelectionMode {
119         SelectCharacters,
120         SelectWords
121     };
122
123     enum CursorPosition {
124         CursorBetweenCharacters,
125         CursorOnCharacter
126     };
127
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);
134
135     Q_INVOKABLE void openSoftwareInputPanel();
136     Q_INVOKABLE void closeSoftwareInputPanel();
137
138     QString text() const;
139     void setText(const QString &);
140
141     QFont font() const;
142     void setFont(const QFont &font);
143
144     QColor color() const;
145     void setColor(const QColor &c);
146
147     QColor selectionColor() const;
148     void setSelectionColor(const QColor &c);
149
150     QColor selectedTextColor() const;
151     void setSelectedTextColor(const QColor &c);
152
153     HAlignment hAlign() const;
154     void setHAlign(HAlignment align);
155     void resetHAlign();
156     HAlignment effectiveHAlign() const;
157
158     bool isReadOnly() const;
159     void setReadOnly(bool);
160
161     bool isCursorVisible() const;
162     void setCursorVisible(bool on);
163
164     int cursorPosition() const;
165     void setCursorPosition(int cp);
166
167     QRect cursorRectangle() const;
168
169     int selectionStart() const;
170     int selectionEnd() const;
171
172     QString selectedText() const;
173
174     int maxLength() const;
175     void setMaxLength(int ml);
176
177 #ifndef QT_NO_VALIDATOR
178     QValidator * validator() const;
179     void setValidator(QValidator* v);
180 #endif
181     QString inputMask() const;
182     void setInputMask(const QString &im);
183
184     EchoMode echoMode() const;
185     void setEchoMode(EchoMode echo);
186
187     QString passwordCharacter() const;
188     void setPasswordCharacter(const QString &str);
189
190     QString displayText() const;
191
192     QDeclarativeComponent* cursorDelegate() const;
193     void setCursorDelegate(QDeclarativeComponent*);
194
195     bool focusOnPress() const;
196     void setFocusOnPress(bool);
197
198     bool autoScroll() const;
199     void setAutoScroll(bool);
200
201     bool selectByMouse() const;
202     void setSelectByMouse(bool);
203
204     SelectionMode mouseSelectionMode() const;
205     void setMouseSelectionMode(SelectionMode mode);
206
207     bool hasAcceptableInput() const;
208
209     void drawContents(QPainter *p,const QRect &r);
210     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
211
212     QRectF boundingRect() const;
213     bool canPaste() const;
214
215     bool isInputMethodComposing() const;
216
217     Qt::InputMethodHints imHints() const;
218     void setIMHints(Qt::InputMethodHints hints);
219
220 Q_SIGNALS:
221     void textChanged();
222     void cursorPositionChanged();
223     void cursorRectangleChanged();
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 cursorPosChanged();
283     void updateCursorRectangle();
284     void updateRect(const QRect &r = QRect());
285     void q_canPasteChanged();
286
287 private:
288     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1TextInput)
289 };
290
291 QT_END_NAMESPACE
292
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)
299 #endif
300
301 QT_END_HEADER
302
303 #endif // QT_NO_LINEEDIT
304
305 #endif // QDECLARATIVETEXTINPUT_H