Skip to content

Latest commit

 

History

History
464 lines (393 loc) · 14.2 KB

qquicktextinput_p_p.h

File metadata and controls

464 lines (393 loc) · 14.2 KB
 
Apr 27, 2011
Apr 27, 2011
1
2
/****************************************************************************
**
Jan 5, 2012
Jan 5, 2012
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
Jan 23, 2012
Jan 23, 2012
4
** Contact: http://www.qt-project.org/
Apr 27, 2011
Apr 27, 2011
5
**
Feb 24, 2012
Feb 24, 2012
6
** This file is part of the QtQml module of the Qt Toolkit.
Apr 27, 2011
Apr 27, 2011
7
8
9
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
Jul 8, 2011
Jul 8, 2011
10
11
12
13
14
15
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Apr 27, 2011
Apr 27, 2011
16
17
**
** In addition, as a special exception, Nokia gives you certain additional
Jul 8, 2011
Jul 8, 2011
18
** rights. These rights are described in the Nokia Qt LGPL Exception
Apr 27, 2011
Apr 27, 2011
19
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
Jul 8, 2011
Jul 8, 2011
21
22
23
24
25
26
27
28
29
30
31
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
Apr 27, 2011
Apr 27, 2011
32
33
34
35
36
**
**
**
**
**
Jan 30, 2012
Jan 30, 2012
37
**
Apr 27, 2011
Apr 27, 2011
38
39
40
41
** $QT_END_LICENSE$
**
****************************************************************************/
Oct 21, 2011
Oct 21, 2011
42
43
#ifndef QQUICKTEXTINPUT_P_P_H
#define QQUICKTEXTINPUT_P_P_H
Apr 27, 2011
Apr 27, 2011
44
Oct 21, 2011
Oct 21, 2011
45
46
47
#include "qquicktextinput_p.h"
#include "qquicktext_p.h"
#include "qquickimplicitsizeitem_p_p.h"
Apr 27, 2011
Apr 27, 2011
48
Feb 24, 2012
Feb 24, 2012
49
#include <QtQml/qqml.h>
Sep 29, 2011
Sep 29, 2011
50
#include <QtCore/qelapsedtimer.h>
Apr 27, 2011
Apr 27, 2011
51
#include <QtCore/qpointer.h>
Dec 20, 2011
Dec 20, 2011
52
#include <QtCore/qbasictimer.h>
Dec 15, 2011
Dec 15, 2011
53
#include <QtGui/qclipboard.h>
Sep 29, 2011
Sep 29, 2011
54
#include <QtGui/qguiapplication.h>
Dec 15, 2011
Dec 15, 2011
55
56
#include <QtGui/qpalette.h>
#include <QtGui/qtextlayout.h>
Sep 29, 2011
Sep 29, 2011
57
#include <QtGui/qstylehints.h>
Apr 27, 2011
Apr 27, 2011
58
Dec 20, 2011
Dec 20, 2011
59
#include "qplatformdefs.h"
Apr 27, 2011
Apr 27, 2011
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
QT_BEGIN_NAMESPACE
Oct 21, 2011
Oct 21, 2011
73
class QQuickTextNode;
Aug 19, 2011
Aug 19, 2011
74
Oct 21, 2011
Oct 21, 2011
75
class Q_AUTOTEST_EXPORT QQuickTextInputPrivate : public QQuickImplicitSizeItemPrivate
Apr 27, 2011
Apr 27, 2011
76
{
Oct 21, 2011
Oct 21, 2011
77
Q_DECLARE_PUBLIC(QQuickTextInput)
Apr 27, 2011
Apr 27, 2011
78
public:
Oct 21, 2011
Oct 21, 2011
79
QQuickTextInputPrivate()
Feb 24, 2012
Feb 24, 2012
80
81
82
: hscroll(0)
, vscroll(0)
, cursorItem(0)
Dec 15, 2011
Dec 15, 2011
83
84
, textNode(0)
, m_maskData(0)
Feb 22, 2012
Feb 22, 2012
85
86
87
, color(QRgb(0xFF000000))
, selectionColor(QRgb(0xFF000080))
, selectedTextColor(QRgb(0xFFFFFFFF))
Dec 15, 2011
Dec 15, 2011
88
89
90
91
92
93
94
95
96
, m_cursor(0)
, m_preeditCursor(0)
, m_blinkPeriod(0)
, m_blinkTimer(0)
, m_maxLength(32767)
, m_lastCursorPos(-1)
, m_undoState(0)
, m_selstart(0)
, m_selend(0)
Feb 22, 2012
Feb 22, 2012
97
, inputMethodHints(Qt::ImhNone)
Dec 15, 2011
Dec 15, 2011
98
, hAlign(QQuickTextInput::AlignLeft)
Dec 20, 2011
Dec 20, 2011
99
100
, vAlign(QQuickTextInput::AlignTop)
, wrapMode(QQuickTextInput::NoWrap)
Feb 22, 2012
Feb 22, 2012
101
102
, m_echoMode(QQuickTextInput::Normal)
, updateType(UpdatePaintNode)
Dec 15, 2011
Dec 15, 2011
103
104
105
106
107
108
109
110
, mouseSelectionMode(QQuickTextInput::SelectCharacters)
, m_layoutDirection(Qt::LayoutDirectionAuto)
, m_passwordCharacter(QLatin1Char('*'))
, focusOnPress(true)
, cursorVisible(false)
, autoScroll(true)
, selectByMouse(false)
, canPaste(false)
Dec 21, 2011
Dec 21, 2011
111
, canPasteValid(false)
Jan 12, 2012
Jan 12, 2012
112
113
, canUndo(false)
, canRedo(false)
Dec 15, 2011
Dec 15, 2011
114
115
116
, hAlignImplicit(true)
, selectPressed(false)
, textLayoutDirty(true)
Feb 2, 2012
Feb 2, 2012
117
, persistentSelection(false)
Dec 15, 2011
Dec 15, 2011
118
119
120
121
, m_hideCursor(false)
, m_separator(0)
, m_readOnly(0)
, m_textDirty(0)
Dec 20, 2011
Dec 20, 2011
122
, m_preeditDirty(0)
Dec 15, 2011
Dec 15, 2011
123
124
, m_selDirty(0)
, m_validInput(1)
Jan 20, 2012
Jan 20, 2012
125
, m_acceptableInput(1)
Dec 15, 2011
Dec 15, 2011
126
127
, m_blinkStatus(0)
, m_passwordEchoEditing(false)
Mar 22, 2012
Mar 22, 2012
128
129
, inLayout(false)
, requireImplicitWidth(false)
Apr 27, 2011
Apr 27, 2011
130
131
132
{
}
Oct 21, 2011
Oct 21, 2011
133
~QQuickTextInputPrivate()
Apr 27, 2011
Apr 27, 2011
134
135
136
137
138
139
{
}
void init();
void startCreatingCursor();
void updateHorizontalScroll();
Dec 20, 2011
Dec 20, 2011
140
void updateVerticalScroll();
Apr 27, 2011
Apr 27, 2011
141
bool determineHorizontalAlignment();
Oct 21, 2011
Oct 21, 2011
142
bool setHAlign(QQuickTextInput::HAlignment, bool forceAlign = false);
Apr 27, 2011
Apr 27, 2011
143
void mirrorChange();
Sep 1, 2011
Sep 1, 2011
144
bool sendMouseEventToInputContext(QMouseEvent *event);
Feb 22, 2012
Feb 22, 2012
145
Qt::InputMethodHints effectiveInputMethodHints() const;
Aug 19, 2011
Aug 19, 2011
146
147
void hideCursor();
void showCursor();
Apr 27, 2011
Apr 27, 2011
148
Feb 22, 2012
Feb 22, 2012
149
Dec 15, 2011
Dec 15, 2011
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
struct MaskInputData {
enum Casemode { NoCaseMode, Upper, Lower };
QChar maskChar; // either the separator char or the inputmask
bool separator;
Casemode caseMode;
};
// undo/redo handling
enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection, SetSelection };
struct Command {
inline Command() {}
inline Command(CommandType t, int p, QChar c, int ss, int se) : type(t),uc(c),pos(p),selStart(ss),selEnd(se) {}
uint type : 4;
QChar uc;
int pos, selStart, selEnd;
};
Apr 27, 2011
Apr 27, 2011
166
Dec 15, 2011
Dec 15, 2011
167
168
169
170
171
172
173
enum DrawFlags {
DrawText = 0x01,
DrawSelections = 0x02,
DrawCursor = 0x04,
DrawAll = DrawText | DrawSelections | DrawCursor
};
Feb 22, 2012
Feb 22, 2012
174
175
176
177
178
QElapsedTimer tripleClickTimer;
QRectF boundingRect;
QPointF pressPos;
QPointF tripleClickStartPoint;
Feb 24, 2012
Feb 24, 2012
179
QQmlGuard<QQmlComponent> cursorComponent;
Feb 22, 2012
Feb 22, 2012
180
#ifndef QT_NO_VALIDATOR
Feb 24, 2012
Feb 24, 2012
181
QQmlGuard<QValidator> m_validator;
Feb 22, 2012
Feb 22, 2012
182
183
#endif
Feb 24, 2012
Feb 24, 2012
184
185
186
qreal hscroll;
qreal vscroll;
Dec 15, 2011
Dec 15, 2011
187
188
189
190
191
QTextLayout m_textLayout;
QString m_text;
QString m_inputMask;
QString m_cancelText;
QString m_tentativeCommit;
Apr 27, 2011
Apr 27, 2011
192
193
QFont font;
QFont sourceFont;
Feb 22, 2012
Feb 22, 2012
194
195
QQuickItem *cursorItem;
Oct 21, 2011
Oct 21, 2011
196
QQuickTextNode *textNode;
Dec 15, 2011
Dec 15, 2011
197
MaskInputData *m_maskData;
Feb 22, 2012
Feb 22, 2012
198
Dec 15, 2011
Dec 15, 2011
199
200
QList<int> m_transactions;
QVector<Command> m_history;
Apr 27, 2011
Apr 27, 2011
201
Feb 22, 2012
Feb 22, 2012
202
203
204
205
206
207
208
QColor color;
QColor selectionColor;
QColor selectedTextColor;
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
QBasicTimer m_passwordEchoTimer;
#endif
Apr 27, 2011
Apr 27, 2011
209
210
int lastSelectionStart;
int lastSelectionEnd;
Dec 15, 2011
Dec 15, 2011
211
212
213
214
215
216
217
218
219
220
int m_cursor;
int m_preeditCursor;
int m_blinkPeriod; // 0 for non-blinking cursor
int m_blinkTimer;
int m_maxLength;
int m_lastCursorPos;
int m_undoState;
int m_selstart;
int m_selend;
Feb 22, 2012
Feb 22, 2012
221
222
223
224
225
226
227
enum UpdateType {
UpdateNone,
UpdateOnlyPreprocess,
UpdatePaintNode
};
Qt::InputMethodHints inputMethodHints;
Dec 15, 2011
Dec 15, 2011
228
QQuickTextInput::HAlignment hAlign;
Dec 20, 2011
Dec 20, 2011
229
230
QQuickTextInput::VAlignment vAlign;
QQuickTextInput::WrapMode wrapMode;
Feb 22, 2012
Feb 22, 2012
231
232
QQuickTextInput::EchoMode m_echoMode;
UpdateType updateType;
Dec 15, 2011
Dec 15, 2011
233
234
235
236
237
QQuickTextInput::SelectionMode mouseSelectionMode;
Qt::LayoutDirection m_layoutDirection;
QChar m_blank;
QChar m_passwordCharacter;
Apr 27, 2011
Apr 27, 2011
238
239
240
241
242
243
bool focusOnPress:1;
bool cursorVisible:1;
bool autoScroll:1;
bool selectByMouse:1;
bool canPaste:1;
Dec 21, 2011
Dec 21, 2011
244
bool canPasteValid:1;
Jan 12, 2012
Jan 12, 2012
245
246
bool canUndo:1;
bool canRedo:1;
Apr 27, 2011
Apr 27, 2011
247
bool hAlignImplicit:1;
May 4, 2011
May 4, 2011
248
bool selectPressed:1;
Aug 19, 2011
Aug 19, 2011
249
bool textLayoutDirty:1;
Feb 2, 2012
Feb 2, 2012
250
bool persistentSelection:1;
Feb 22, 2012
Feb 22, 2012
251
252
253
254
255
256
257
258
259
260
bool m_hideCursor : 1; // used to hide the m_cursor inside preedit areas
bool m_separator : 1;
bool m_readOnly : 1;
bool m_textDirty : 1;
bool m_preeditDirty : 1;
bool m_selDirty : 1;
bool m_validInput : 1;
bool m_acceptableInput : 1;
bool m_blinkStatus : 1;
bool m_passwordEchoEditing : 1;
Mar 22, 2012
Mar 22, 2012
261
262
bool inLayout:1;
bool requireImplicitWidth:1;
Jan 24, 2012
Jan 24, 2012
263
Oct 21, 2011
Oct 21, 2011
264
static inline QQuickTextInputPrivate *get(QQuickTextInput *t) {
Apr 27, 2011
Apr 27, 2011
265
266
return t->d_func();
}
Sep 29, 2011
Sep 29, 2011
267
268
269
bool hasPendingTripleClick() const {
return !tripleClickTimer.hasExpired(qApp->styleHints()->mouseDoubleClickInterval());
}
Dec 15, 2011
Dec 15, 2011
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
int nextMaskBlank(int pos)
{
int c = findInMask(pos, true, false);
m_separator |= (c != pos);
return (c != -1 ? c : m_maxLength);
}
int prevMaskBlank(int pos)
{
int c = findInMask(pos, false, false);
m_separator |= (c != pos);
return (c != -1 ? c : 0);
}
bool isUndoAvailable() const { return !m_readOnly && m_undoState; }
bool isRedoAvailable() const { return !m_readOnly && m_undoState < (int)m_history.size(); }
Feb 22, 2012
Feb 22, 2012
288
void clearUndo() { m_history.clear(); m_undoState = 0; }
Dec 15, 2011
Dec 15, 2011
289
290
291
292
293
294
295
296
297
298
299
300
bool allSelected() const { return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length(); }
bool hasSelectedText() const { return !m_text.isEmpty() && m_selend > m_selstart; }
void setSelection(int start, int length);
inline QString selectedText() const { return hasSelectedText() ? m_text.mid(m_selstart, m_selend - m_selstart) : QString(); }
QString textBeforeSelection() const { return hasSelectedText() ? m_text.left(m_selstart) : QString(); }
QString textAfterSelection() const { return hasSelectedText() ? m_text.mid(m_selend) : QString(); }
int selectionStart() const { return hasSelectedText() ? m_selstart : -1; }
int selectionEnd() const { return hasSelectedText() ? m_selend : -1; }
Dec 20, 2011
Dec 20, 2011
301
Feb 24, 2012
Feb 24, 2012
302
int positionAt(qreal x, qreal y, QTextLine::CursorPosition position) const;
Dec 20, 2011
Dec 20, 2011
303
304
int positionAt(const QPointF &point, QTextLine::CursorPosition position = QTextLine::CursorBetweenCharacters) const {
return positionAt(point.x(), point.y(), position);
Dec 15, 2011
Dec 15, 2011
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
}
void removeSelection()
{
int priorState = m_undoState;
removeSelectedText();
finishChange(priorState);
}
int start() const { return 0; }
int end() const { return m_text.length(); }
QString realText() const;
#ifndef QT_NO_CLIPBOARD
void copy(QClipboard::Mode mode = QClipboard::Clipboard) const;
void paste(QClipboard::Mode mode = QClipboard::Clipboard);
#endif
void commitPreedit();
Qt::CursorMoveStyle cursorMoveStyle() const { return m_textLayout.cursorMoveStyle(); }
void setCursorMoveStyle(Qt::CursorMoveStyle style) { m_textLayout.setCursorMoveStyle(style); }
void moveCursor(int pos, bool mark = false);
void cursorForward(bool mark, int steps)
{
int c = m_cursor;
if (steps > 0) {
while (steps--)
c = cursorMoveStyle() == Qt::VisualMoveStyle ? m_textLayout.rightCursorPosition(c)
: m_textLayout.nextCursorPosition(c);
} else if (steps < 0) {
while (steps++)
c = cursorMoveStyle() == Qt::VisualMoveStyle ? m_textLayout.leftCursorPosition(c)
: m_textLayout.previousCursorPosition(c);
}
moveCursor(c, mark);
}
void cursorWordForward(bool mark) { moveCursor(m_textLayout.nextCursorPosition(m_cursor, QTextLayout::SkipWords), mark); }
void cursorWordBackward(bool mark) { moveCursor(m_textLayout.previousCursorPosition(m_cursor, QTextLayout::SkipWords), mark); }
void home(bool mark) { moveCursor(0, mark); }
void end(bool mark) { moveCursor(q_func()->text().length(), mark); }
void backspace();
void del();
void deselect() { internalDeselect(); finishChange(); }
void selectAll() { m_selstart = m_selend = m_cursor = 0; moveCursor(m_text.length(), true); }
void insert(const QString &);
void clear();
void selectWordAtPos(int);
void setCursorPosition(int pos) { if (pos <= m_text.length()) moveCursor(qMax(0, pos)); }
bool fixup();
QString inputMask() const { return m_maskData ? m_inputMask + QLatin1Char(';') + m_blank : QString(); }
void setInputMask(const QString &mask)
{
parseInputMask(mask);
if (m_maskData)
moveCursor(nextMaskBlank(0));
}
// input methods
#ifndef QT_NO_IM
bool composeMode() const { return !m_textLayout.preeditAreaText().isEmpty(); }
#endif
QString preeditAreaText() const { return m_textLayout.preeditAreaText(); }
void updatePasswordEchoEditing(bool editing);
Dec 20, 2011
Dec 20, 2011
381
382
383
384
385
386
void cancelPasswordEchoTimer() {
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
m_passwordEchoTimer.stop();
#endif
}
Dec 15, 2011
Dec 15, 2011
387
388
389
Qt::LayoutDirection layoutDirection() const {
if (m_layoutDirection == Qt::LayoutDirectionAuto) {
if (m_text.isEmpty())
Feb 10, 2012
Feb 10, 2012
390
return qApp->inputMethod()->inputDirection();
Dec 15, 2011
Dec 15, 2011
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
return m_text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
}
return m_layoutDirection;
}
void setLayoutDirection(Qt::LayoutDirection direction)
{
if (direction != m_layoutDirection) {
m_layoutDirection = direction;
updateDisplayText();
}
}
void processInputMethodEvent(QInputMethodEvent *event);
void processKeyEvent(QKeyEvent* ev);
void setCursorBlinkPeriod(int msec);
Dec 20, 2011
Dec 20, 2011
408
409
void updateLayout();
Mar 22, 2012
Mar 22, 2012
410
411
qreal getImplicitWidth() const;
Dec 15, 2011
Dec 15, 2011
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
private:
void removeSelectedText();
void internalSetText(const QString &txt, int pos = -1, bool edited = true);
void updateDisplayText(bool forceUpdate = false);
void internalInsert(const QString &s);
void internalDelete(bool wasBackspace = false);
void internalRemove(int pos);
inline void internalDeselect()
{
m_selDirty |= (m_selend > m_selstart);
m_selstart = m_selend = 0;
}
void internalUndo(int until = -1);
void internalRedo();
Jan 12, 2012
Jan 12, 2012
429
void emitUndoRedoChanged();
Dec 15, 2011
Dec 15, 2011
430
Jan 17, 2012
Jan 17, 2012
431
bool emitCursorPositionChanged();
Dec 15, 2011
Dec 15, 2011
432
433
434
435
436
437
438
bool finishChange(int validateFromState = -1, bool update = false, bool edited = true);
void addCommand(const Command& cmd);
inline void separate() { m_separator = true; }
Jan 20, 2012
Jan 20, 2012
439
440
441
442
443
444
445
446
447
448
449
450
enum ValidatorState {
#ifndef QT_NO_VALIDATOR
InvalidInput = QValidator::Invalid,
IntermediateInput = QValidator::Intermediate,
AcceptableInput = QValidator::Acceptable
#else
Invalid,
Intermediate,
Acceptable
#endif
};
Dec 15, 2011
Dec 15, 2011
451
452
453
// masking
void parseInputMask(const QString &maskFields);
bool isValidInput(QChar key, QChar mask) const;
Jan 20, 2012
Jan 20, 2012
454
455
ValidatorState hasAcceptableInput(const QString &text) const;
void checkIsValid();
Dec 15, 2011
Dec 15, 2011
456
457
458
459
QString maskString(uint pos, const QString &str, bool clear = false) const;
QString clearString(uint pos, uint len) const;
QString stripString(const QString &str) const;
int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar = QChar()) const;
Apr 27, 2011
Apr 27, 2011
460
461
462
463
};
QT_END_NAMESPACE
Oct 21, 2011
Oct 21, 2011
464
#endif // QQUICKTEXTINPUT_P_P_H