Qt 4.8
qdeclarativetextinput_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
54 
56 
57 QT_MODULE(Declarative)
58 
60 class QValidator;
62 {
63  Q_OBJECT
67 
69  QColor color;
70  QColor selectionColor;
71  QColor selectedTextColor;
72  QFont font;
73  HAlignment horizontalAlignment;
74  bool readOnly;
75  bool cursorVisible;
76  int cursorPosition;
77  QRect cursorRectangle;
78  QDeclarativeComponent *cursorDelegate;
79  int selectionStart;
80  int selectionEnd;
81  QString selectedText;
82 
83  int maximumLength;
84 #ifndef QT_NO_VALIDATOR
86 #endif
88  Qt::InputMethodHints inputMethodHints;
89 
95  bool autoScroll;
98  bool canPaste;
100 
101 public:
104 
105  enum EchoMode {//To match QLineEdit::EchoMode
109  PasswordEchoOnEdit
110  };
111 
112  enum HAlignment {
116  };
117 
120  SelectWords
121  };
122 
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);
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 
250 protected:
251  virtual void geometryChanged(const QRectF &newGeometry,
252  const QRectF &oldGeometry);
253 
254  void mousePressEvent(QGraphicsSceneMouseEvent *event);
255  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
256  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
257  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
258  bool sceneEvent(QEvent *event);
259  void keyPressEvent(QKeyEvent* ev);
260  void inputMethodEvent(QInputMethodEvent *);
261  bool event(QEvent *e);
262  void focusInEvent(QFocusEvent *event);
263 
264 public Q_SLOTS:
265  void selectAll();
266  void selectWord();
267  void select(int start, int end);
268  Q_REVISION(1) void deselect();
269  Q_REVISION(1) bool isRightToLeft(int start, int end);
270 #ifndef QT_NO_CLIPBOARD
271  void cut();
272  void copy();
273  void paste();
274 #endif
275 
276 private Q_SLOTS:
277  void updateSize(bool needsRedraw = true);
278  void q_textChanged();
279  void selectionChanged();
280  void createCursor();
281  void cursorPosChanged();
282  void updateCursorRectangle();
283  void updateRect(const QRect &r = QRect());
284  void q_canPasteChanged();
285 
286 private:
288 };
289 
291 
293 #ifndef QT_NO_VALIDATOR
298 #endif
299 
301 
302 #endif // QT_NO_LINEEDIT
303 
304 #endif // QDECLARATIVETEXTINPUT_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QRegExpValidator class is used to check a string against a regular expression.
Definition: qvalidator.h:182
The QKeyEvent class describes a key event.
Definition: qevent.h:224
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition: qvalidator.h:96
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QDeclarativeComponent class encapsulates a QML component definition.
The QDeclarativeItem class provides the most basic of all visual items in QML.
QVariant data(int key) const
Returns this item&#39;s custom data for the key key as a QVariant.
Qt::InputMethodHints inputMethodHints
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PRIVATE_D(Dptr, Class)
Definition: qglobal.h:2472
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
virtual void drawContents(QPainter *, const QRect &)
This function is called when the cache needs to be refreshed.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
const char * property
Definition: qwizard.cpp:138
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
#define text
Definition: qobjectdefs.h:80
The QDoubleValidator class provides range checking of floating-point numbers.
Definition: qvalidator.h:134