1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QLINEEDIT_P_H
|
---|
43 | #define QLINEEDIT_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "QtCore/qglobal.h"
|
---|
57 |
|
---|
58 | #ifndef QT_NO_LINEEDIT
|
---|
59 | #include "private/qwidget_p.h"
|
---|
60 | #include "QtGui/qlineedit.h"
|
---|
61 | #include "QtGui/qtextlayout.h"
|
---|
62 | #include "QtGui/qstyleoption.h"
|
---|
63 | #include "QtCore/qbasictimer.h"
|
---|
64 | #include "QtGui/qcompleter.h"
|
---|
65 | #include "QtCore/qpointer.h"
|
---|
66 | #include "QtGui/qlineedit.h"
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | class QLineEditPrivate : public QWidgetPrivate
|
---|
71 | {
|
---|
72 | Q_DECLARE_PUBLIC(QLineEdit)
|
---|
73 | public:
|
---|
74 |
|
---|
75 | QLineEditPrivate()
|
---|
76 | : cursor(0), preeditCursor(0), cursorTimer(0), frame(1),
|
---|
77 | cursorVisible(0), hideCursor(false), separator(0), readOnly(0),
|
---|
78 | dragEnabled(0), contextMenuEnabled(1), echoMode(0), textDirty(0),
|
---|
79 | selDirty(0), validInput(1), alignment(Qt::AlignLeading | Qt::AlignVCenter), ascent(0),
|
---|
80 | maxLength(32767), hscroll(0), vscroll(0), lastCursorPos(-1), maskData(0),
|
---|
81 | modifiedState(0), undoState(0), selstart(0), selend(0), userInput(false),
|
---|
82 | emitingEditingFinished(false), passwordEchoEditing(false)
|
---|
83 | #ifndef QT_NO_COMPLETER
|
---|
84 | , completer(0)
|
---|
85 | #endif
|
---|
86 | , leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0)
|
---|
87 | {
|
---|
88 | }
|
---|
89 |
|
---|
90 | ~QLineEditPrivate()
|
---|
91 | {
|
---|
92 | delete [] maskData;
|
---|
93 | }
|
---|
94 | void init(const QString&);
|
---|
95 |
|
---|
96 | QString text;
|
---|
97 | int cursor;
|
---|
98 | int preeditCursor;
|
---|
99 | int cursorTimer; // -1 for non blinking cursor.
|
---|
100 | QPoint tripleClick;
|
---|
101 | QBasicTimer tripleClickTimer;
|
---|
102 | uint frame : 1;
|
---|
103 | uint cursorVisible : 1;
|
---|
104 | uint hideCursor : 1; // used to hide the cursor inside preedit areas
|
---|
105 | uint separator : 1;
|
---|
106 | uint readOnly : 1;
|
---|
107 | uint dragEnabled : 1;
|
---|
108 | uint contextMenuEnabled : 1;
|
---|
109 | uint echoMode : 2;
|
---|
110 | uint textDirty : 1;
|
---|
111 | uint selDirty : 1;
|
---|
112 | uint validInput : 1;
|
---|
113 | uint alignment;
|
---|
114 | int ascent;
|
---|
115 | int maxLength;
|
---|
116 | int hscroll;
|
---|
117 | int vscroll;
|
---|
118 | int lastCursorPos;
|
---|
119 |
|
---|
120 | #ifndef QT_NO_CONTEXTMENU
|
---|
121 | QPointer<QAction> selectAllAction;
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | inline void emitCursorPositionChanged();
|
---|
125 | bool sendMouseEventToInputContext(QMouseEvent *e);
|
---|
126 |
|
---|
127 | void finishChange(int validateFromState = -1, bool update = false, bool edited = true);
|
---|
128 |
|
---|
129 | QPointer<QValidator> validator;
|
---|
130 | struct MaskInputData {
|
---|
131 | enum Casemode { NoCaseMode, Upper, Lower };
|
---|
132 | QChar maskChar; // either the separator char or the inputmask
|
---|
133 | bool separator;
|
---|
134 | Casemode caseMode;
|
---|
135 | };
|
---|
136 | QString inputMask;
|
---|
137 | QChar blank;
|
---|
138 | MaskInputData *maskData;
|
---|
139 | inline int nextMaskBlank(int pos) {
|
---|
140 | int c = findInMask(pos, true, false);
|
---|
141 | separator |= (c != pos);
|
---|
142 | return (c != -1 ? c : maxLength);
|
---|
143 | }
|
---|
144 | inline int prevMaskBlank(int pos) {
|
---|
145 | int c = findInMask(pos, false, false);
|
---|
146 | separator |= (c != pos);
|
---|
147 | return (c != -1 ? c : 0);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void setCursorVisible(bool visible);
|
---|
151 |
|
---|
152 |
|
---|
153 | // undo/redo handling
|
---|
154 | enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection, SetSelection };
|
---|
155 | struct Command {
|
---|
156 | inline Command() {}
|
---|
157 | inline Command(CommandType t, int p, QChar c, int ss, int se) : type(t),uc(c),pos(p),selStart(ss),selEnd(se) {}
|
---|
158 | uint type : 4;
|
---|
159 | QChar uc;
|
---|
160 | int pos, selStart, selEnd;
|
---|
161 | };
|
---|
162 | int modifiedState;
|
---|
163 | int undoState;
|
---|
164 | QVector<Command> history;
|
---|
165 | void addCommand(const Command& cmd);
|
---|
166 | void insert(const QString& s);
|
---|
167 | void del(bool wasBackspace = false);
|
---|
168 | void remove(int pos);
|
---|
169 |
|
---|
170 | inline void separate() { separator = true; }
|
---|
171 | void undo(int until = -1);
|
---|
172 | void redo();
|
---|
173 | inline bool isUndoAvailable() const { return !readOnly && undoState; }
|
---|
174 | inline bool isRedoAvailable() const { return !readOnly && undoState < (int)history.size(); }
|
---|
175 |
|
---|
176 | // selection
|
---|
177 | int selstart, selend;
|
---|
178 | inline bool allSelected() const { return !text.isEmpty() && selstart == 0 && selend == (int)text.length(); }
|
---|
179 | inline bool hasSelectedText() const { return !text.isEmpty() && selend > selstart; }
|
---|
180 | inline void deselect() { selDirty |= (selend > selstart); selstart = selend = 0; }
|
---|
181 | void removeSelectedText();
|
---|
182 | #ifndef QT_NO_CLIPBOARD
|
---|
183 | void copy(bool clipboard = true) const;
|
---|
184 | #endif
|
---|
185 | inline bool inSelection(int x) const
|
---|
186 | { if (selstart >= selend) return false;
|
---|
187 | int pos = xToPos(x, QTextLine::CursorOnCharacter); return pos >= selstart && pos < selend; }
|
---|
188 |
|
---|
189 | // masking
|
---|
190 | void parseInputMask(const QString &maskFields);
|
---|
191 | bool isValidInput(QChar key, QChar mask) const;
|
---|
192 | bool hasAcceptableInput(const QString &text) const;
|
---|
193 | QString maskString(uint pos, const QString &str, bool clear = false) const;
|
---|
194 | QString clearString(uint pos, uint len) const;
|
---|
195 | QString stripString(const QString &str) const;
|
---|
196 | int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar = QChar()) const;
|
---|
197 |
|
---|
198 | // input methods
|
---|
199 | bool composeMode() const { return !textLayout.preeditAreaText().isEmpty(); }
|
---|
200 |
|
---|
201 | // complex text layout
|
---|
202 | QTextLayout textLayout;
|
---|
203 | void updateTextLayout();
|
---|
204 | void moveCursor(int pos, bool mark = false);
|
---|
205 | void setText(const QString& txt, int pos = -1, bool edited = true);
|
---|
206 | int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
|
---|
207 | QRect cursorRect() const;
|
---|
208 | bool fixup();
|
---|
209 |
|
---|
210 | QRect adjustedContentsRect() const;
|
---|
211 |
|
---|
212 | #ifndef QT_NO_DRAGANDDROP
|
---|
213 | // drag and drop
|
---|
214 | QPoint dndPos;
|
---|
215 | QBasicTimer dndTimer;
|
---|
216 | void drag();
|
---|
217 | #endif
|
---|
218 |
|
---|
219 | void _q_clipboardChanged();
|
---|
220 | void _q_handleWindowActivate();
|
---|
221 | void _q_deleteSelected();
|
---|
222 | bool userInput;
|
---|
223 | bool emitingEditingFinished;
|
---|
224 |
|
---|
225 | #ifdef QT_KEYPAD_NAVIGATION
|
---|
226 | QBasicTimer deleteAllTimer; // keypad navigation
|
---|
227 | QString origText;
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | bool passwordEchoEditing;
|
---|
231 | void updatePasswordEchoEditing(bool editing);
|
---|
232 |
|
---|
233 | #ifndef QT_NO_COMPLETER
|
---|
234 | QPointer<QCompleter> completer;
|
---|
235 | void complete(int key = -1);
|
---|
236 | void _q_completionHighlighted(QString);
|
---|
237 | bool advanceToEnabledItem(int n);
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | int leftTextMargin;
|
---|
241 | int topTextMargin;
|
---|
242 | int rightTextMargin;
|
---|
243 | int bottomTextMargin;
|
---|
244 | };
|
---|
245 |
|
---|
246 | #endif // QT_NO_LINEEDIT
|
---|
247 |
|
---|
248 | QT_END_NAMESPACE
|
---|
249 |
|
---|
250 | #endif // QLINEEDIT_P_H
|
---|