author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qlineedit.h" |
|
43 |
#include "qlineedit_p.h" |
|
44 |
||
45 |
#ifndef QT_NO_LINEEDIT |
|
46 |
#include "qaction.h" |
|
47 |
#include "qapplication.h" |
|
48 |
#include "qclipboard.h" |
|
49 |
#include "qdrag.h" |
|
50 |
#include "qdrawutil.h" |
|
51 |
#include "qevent.h" |
|
52 |
#include "qfontmetrics.h" |
|
53 |
#include "qmenu.h" |
|
54 |
#include "qpainter.h" |
|
55 |
#include "qpixmap.h" |
|
56 |
#include "qpointer.h" |
|
57 |
#include "qstringlist.h" |
|
58 |
#include "qstyle.h" |
|
59 |
#include "qstyleoption.h" |
|
60 |
#include "qtimer.h" |
|
61 |
#include "qvalidator.h" |
|
62 |
#include "qvariant.h" |
|
63 |
#include "qvector.h" |
|
64 |
#include "qwhatsthis.h" |
|
65 |
#include "qdebug.h" |
|
66 |
#include "qtextedit.h" |
|
67 |
#include <private/qtextedit_p.h> |
|
68 |
#ifndef QT_NO_ACCESSIBILITY |
|
69 |
#include "qaccessible.h" |
|
70 |
#endif |
|
71 |
#ifndef QT_NO_IM |
|
72 |
#include "qinputcontext.h" |
|
73 |
#include "qlist.h" |
|
74 |
#endif |
|
75 |
#include "qabstractitemview.h" |
|
76 |
#include "private/qstylesheetstyle_p.h" |
|
77 |
||
78 |
#ifndef QT_NO_SHORTCUT |
|
79 |
#include "private/qapplication_p.h" |
|
80 |
#include "private/qshortcutmap_p.h" |
|
81 |
#include "qkeysequence.h" |
|
82 |
#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString()) |
|
83 |
#else |
|
84 |
#define ACCEL_KEY(k) QString() |
|
85 |
#endif |
|
86 |
||
87 |
#include <limits.h> |
|
88 |
||
89 |
QT_BEGIN_NAMESPACE |
|
90 |
||
91 |
#ifdef Q_WS_MAC |
|
92 |
extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp |
|
93 |
#endif |
|
94 |
||
95 |
/*! |
|
96 |
Initialize \a option with the values from this QLineEdit. This method |
|
97 |
is useful for subclasses when they need a QStyleOptionFrame or QStyleOptionFrameV2, but don't want |
|
98 |
to fill in all the information themselves. This function will check the version |
|
99 |
of the QStyleOptionFrame and fill in the additional values for a |
|
100 |
QStyleOptionFrameV2. |
|
101 |
||
102 |
\sa QStyleOption::initFrom() |
|
103 |
*/ |
|
104 |
void QLineEdit::initStyleOption(QStyleOptionFrame *option) const |
|
105 |
{ |
|
106 |
if (!option) |
|
107 |
return; |
|
108 |
||
109 |
Q_D(const QLineEdit); |
|
110 |
option->initFrom(this); |
|
111 |
option->rect = contentsRect(); |
|
112 |
option->lineWidth = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this) |
|
113 |
: 0; |
|
114 |
option->midLineWidth = 0; |
|
115 |
option->state |= QStyle::State_Sunken; |
|
116 |
if (d->control->isReadOnly()) |
|
117 |
option->state |= QStyle::State_ReadOnly; |
|
118 |
#ifdef QT_KEYPAD_NAVIGATION |
|
119 |
if (hasEditFocus()) |
|
120 |
option->state |= QStyle::State_HasEditFocus; |
|
121 |
#endif |
|
122 |
if (QStyleOptionFrameV2 *optionV2 = qstyleoption_cast<QStyleOptionFrameV2 *>(option)) |
|
123 |
optionV2->features = QStyleOptionFrameV2::None; |
|
124 |
} |
|
125 |
||
126 |
/*! |
|
127 |
\class QLineEdit |
|
128 |
\brief The QLineEdit widget is a one-line text editor. |
|
129 |
||
130 |
\ingroup basicwidgets |
|
131 |
||
132 |
||
133 |
A line edit allows the user to enter and edit a single line of |
|
134 |
plain text with a useful collection of editing functions, |
|
135 |
including undo and redo, cut and paste, and drag and drop. |
|
136 |
||
137 |
By changing the echoMode() of a line edit, it can also be used as |
|
138 |
a "write-only" field, for inputs such as passwords. |
|
139 |
||
140 |
The length of the text can be constrained to maxLength(). The text |
|
141 |
can be arbitrarily constrained using a validator() or an |
|
142 |
inputMask(), or both. |
|
143 |
||
144 |
A related class is QTextEdit which allows multi-line, rich text |
|
145 |
editing. |
|
146 |
||
147 |
You can change the text with setText() or insert(). The text is |
|
148 |
retrieved with text(); the displayed text (which may be different, |
|
149 |
see \l{EchoMode}) is retrieved with displayText(). Text can be |
|
150 |
selected with setSelection() or selectAll(), and the selection can |
|
151 |
be cut(), copy()ied and paste()d. The text can be aligned with |
|
152 |
setAlignment(). |
|
153 |
||
154 |
When the text changes the textChanged() signal is emitted; when |
|
155 |
the text changes other than by calling setText() the textEdited() |
|
156 |
signal is emitted; when the cursor is moved the |
|
157 |
cursorPositionChanged() signal is emitted; and when the Return or |
|
158 |
Enter key is pressed the returnPressed() signal is emitted. |
|
159 |
||
160 |
When editing is finished, either because the line edit lost focus |
|
161 |
or Return/Enter is pressed the editingFinished() signal is |
|
162 |
emitted. |
|
163 |
||
164 |
Note that if there is a validator set on the line edit, the |
|
165 |
returnPressed()/editingFinished() signals will only be emitted if |
|
166 |
the validator returns QValidator::Acceptable. |
|
167 |
||
168 |
By default, QLineEdits have a frame as specified by the Windows |
|
169 |
and Motif style guides; you can turn it off by calling |
|
170 |
setFrame(false). |
|
171 |
||
172 |
The default key bindings are described below. The line edit also |
|
173 |
provides a context menu (usually invoked by a right mouse click) |
|
174 |
that presents some of these editing options. |
|
175 |
\target desc |
|
176 |
\table |
|
177 |
\header \i Keypress \i Action |
|
178 |
\row \i Left Arrow \i Moves the cursor one character to the left. |
|
179 |
\row \i Shift+Left Arrow \i Moves and selects text one character to the left. |
|
180 |
\row \i Right Arrow \i Moves the cursor one character to the right. |
|
181 |
\row \i Shift+Right Arrow \i Moves and selects text one character to the right. |
|
182 |
\row \i Home \i Moves the cursor to the beginning of the line. |
|
183 |
\row \i End \i Moves the cursor to the end of the line. |
|
184 |
\row \i Backspace \i Deletes the character to the left of the cursor. |
|
185 |
\row \i Ctrl+Backspace \i Deletes the word to the left of the cursor. |
|
186 |
\row \i Delete \i Deletes the character to the right of the cursor. |
|
187 |
\row \i Ctrl+Delete \i Deletes the word to the right of the cursor. |
|
188 |
\row \i Ctrl+A \i Select all. |
|
189 |
\row \i Ctrl+C \i Copies the selected text to the clipboard. |
|
190 |
\row \i Ctrl+Insert \i Copies the selected text to the clipboard. |
|
191 |
\row \i Ctrl+K \i Deletes to the end of the line. |
|
192 |
\row \i Ctrl+V \i Pastes the clipboard text into line edit. |
|
193 |
\row \i Shift+Insert \i Pastes the clipboard text into line edit. |
|
194 |
\row \i Ctrl+X \i Deletes the selected text and copies it to the clipboard. |
|
195 |
\row \i Shift+Delete \i Deletes the selected text and copies it to the clipboard. |
|
196 |
\row \i Ctrl+Z \i Undoes the last operation. |
|
197 |
\row \i Ctrl+Y \i Redoes the last undone operation. |
|
198 |
\endtable |
|
199 |
||
200 |
Any other key sequence that represents a valid character, will |
|
201 |
cause the character to be inserted into the line edit. |
|
202 |
||
203 |
\table 100% |
|
204 |
\row \o \inlineimage macintosh-lineedit.png Screenshot of a Macintosh style line edit |
|
205 |
\o A line edit shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. |
|
206 |
\row \o \inlineimage windows-lineedit.png Screenshot of a Windows XP style line edit |
|
207 |
\o A line edit shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}. |
|
208 |
\row \o \inlineimage plastique-lineedit.png Screenshot of a Plastique style line edit |
|
209 |
\o A line edit shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}. |
|
210 |
\endtable |
|
211 |
||
212 |
\sa QTextEdit, QLabel, QComboBox, {fowler}{GUI Design Handbook: Field, Entry}, {Line Edits Example} |
|
213 |
*/ |
|
214 |
||
215 |
||
216 |
/*! |
|
217 |
\fn void QLineEdit::textChanged(const QString &text) |
|
218 |
||
219 |
This signal is emitted whenever the text changes. The \a text |
|
220 |
argument is the new text. |
|
221 |
||
222 |
Unlike textEdited(), this signal is also emitted when the text is |
|
223 |
changed programmatically, for example, by calling setText(). |
|
224 |
*/ |
|
225 |
||
226 |
/*! |
|
227 |
\fn void QLineEdit::textEdited(const QString &text) |
|
228 |
||
229 |
This signal is emitted whenever the text is edited. The \a text |
|
230 |
argument is the next text. |
|
231 |
||
232 |
Unlike textChanged(), this signal is not emitted when the text is |
|
233 |
changed programmatically, for example, by calling setText(). |
|
234 |
*/ |
|
235 |
||
236 |
/*! |
|
237 |
\fn void QLineEdit::cursorPositionChanged(int old, int new) |
|
238 |
||
239 |
This signal is emitted whenever the cursor moves. The previous |
|
240 |
position is given by \a old, and the new position by \a new. |
|
241 |
||
242 |
\sa setCursorPosition(), cursorPosition() |
|
243 |
*/ |
|
244 |
||
245 |
/*! |
|
246 |
\fn void QLineEdit::selectionChanged() |
|
247 |
||
248 |
This signal is emitted whenever the selection changes. |
|
249 |
||
250 |
\sa hasSelectedText(), selectedText() |
|
251 |
*/ |
|
252 |
||
253 |
/*! |
|
254 |
Constructs a line edit with no text. |
|
255 |
||
256 |
The maximum text length is set to 32767 characters. |
|
257 |
||
258 |
The \a parent argument is sent to the QWidget constructor. |
|
259 |
||
260 |
\sa setText(), setMaxLength() |
|
261 |
*/ |
|
262 |
QLineEdit::QLineEdit(QWidget* parent) |
|
263 |
: QWidget(*new QLineEditPrivate, parent,0) |
|
264 |
{ |
|
265 |
Q_D(QLineEdit); |
|
266 |
d->init(QString()); |
|
267 |
} |
|
268 |
||
269 |
/*! |
|
270 |
Constructs a line edit containing the text \a contents. |
|
271 |
||
272 |
The cursor position is set to the end of the line and the maximum |
|
273 |
text length to 32767 characters. |
|
274 |
||
275 |
The \a parent and argument is sent to the QWidget |
|
276 |
constructor. |
|
277 |
||
278 |
\sa text(), setMaxLength() |
|
279 |
*/ |
|
280 |
QLineEdit::QLineEdit(const QString& contents, QWidget* parent) |
|
281 |
: QWidget(*new QLineEditPrivate, parent, 0) |
|
282 |
{ |
|
283 |
Q_D(QLineEdit); |
|
284 |
d->init(contents); |
|
285 |
} |
|
286 |
||
287 |
||
288 |
#ifdef QT3_SUPPORT |
|
289 |
/*! |
|
290 |
Constructs a line edit with no text. |
|
291 |
||
292 |
The maximum text length is set to 32767 characters. |
|
293 |
||
294 |
The \a parent and \a name arguments are sent to the QWidget constructor. |
|
295 |
||
296 |
\sa setText(), setMaxLength() |
|
297 |
*/ |
|
298 |
QLineEdit::QLineEdit(QWidget* parent, const char* name) |
|
299 |
: QWidget(*new QLineEditPrivate, parent,0) |
|
300 |
{ |
|
301 |
Q_D(QLineEdit); |
|
302 |
setObjectName(QString::fromAscii(name)); |
|
303 |
d->init(QString()); |
|
304 |
} |
|
305 |
||
306 |
/*! |
|
307 |
Constructs a line edit containing the text \a contents. |
|
308 |
||
309 |
The cursor position is set to the end of the line and the maximum |
|
310 |
text length to 32767 characters. |
|
311 |
||
312 |
The \a parent and \a name arguments are sent to the QWidget |
|
313 |
constructor. |
|
314 |
||
315 |
\sa text(), setMaxLength() |
|
316 |
*/ |
|
317 |
||
318 |
QLineEdit::QLineEdit(const QString& contents, QWidget* parent, const char* name) |
|
319 |
: QWidget(*new QLineEditPrivate, parent, 0) |
|
320 |
{ |
|
321 |
Q_D(QLineEdit); |
|
322 |
setObjectName(QString::fromAscii(name)); |
|
323 |
d->init(contents); |
|
324 |
} |
|
325 |
||
326 |
/*! |
|
327 |
Constructs a line edit with an input \a inputMask and the text \a |
|
328 |
contents. |
|
329 |
||
330 |
The cursor position is set to the end of the line and the maximum |
|
331 |
text length is set to the length of the mask (the number of mask |
|
332 |
characters and separators). |
|
333 |
||
334 |
The \a parent and \a name arguments are sent to the QWidget |
|
335 |
constructor. |
|
336 |
||
337 |
\sa setMask() text() |
|
338 |
*/ |
|
339 |
QLineEdit::QLineEdit(const QString& contents, const QString &inputMask, QWidget* parent, const char* name) |
|
340 |
: QWidget(*new QLineEditPrivate, parent, 0) |
|
341 |
{ |
|
342 |
Q_D(QLineEdit); |
|
343 |
setObjectName(QString::fromAscii(name)); |
|
344 |
d->init(contents); |
|
345 |
d->control->setInputMask(inputMask); |
|
346 |
d->control->moveCursor(d->control->nextMaskBlank(contents.length())); |
|
347 |
} |
|
348 |
#endif |
|
349 |
||
350 |
/*! |
|
351 |
Destroys the line edit. |
|
352 |
*/ |
|
353 |
||
354 |
QLineEdit::~QLineEdit() |
|
355 |
{ |
|
356 |
} |
|
357 |
||
358 |
||
359 |
/*! |
|
360 |
\property QLineEdit::text |
|
361 |
\brief the line edit's text |
|
362 |
||
363 |
Setting this property clears the selection, clears the undo/redo |
|
364 |
history, moves the cursor to the end of the line and resets the |
|
365 |
\l modified property to false. The text is not validated when |
|
366 |
inserted with setText(). |
|
367 |
||
368 |
The text is truncated to maxLength() length. |
|
369 |
||
370 |
By default, this property contains an empty string. |
|
371 |
||
372 |
\sa insert(), clear() |
|
373 |
*/ |
|
374 |
QString QLineEdit::text() const |
|
375 |
{ |
|
376 |
Q_D(const QLineEdit); |
|
377 |
return d->control->text(); |
|
378 |
} |
|
379 |
||
380 |
void QLineEdit::setText(const QString& text) |
|
381 |
{ |
|
382 |
Q_D(QLineEdit); |
|
383 |
d->control->setText(text); |
|
384 |
} |
|
385 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
\since 4.7 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
\property QLineEdit::placeholderText |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
\brief the line edit's placeholder text |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
Setting this property makes the line edit display a grayed-out |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
placeholder text as long as the text() is empty and the widget doesn't |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
have focus. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
By default, this property contains an empty string. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
\sa text() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
QString QLineEdit::placeholderText() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
Q_D(const QLineEdit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
return d->placeholderText; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
void QLineEdit::setPlaceholderText(const QString& placeholderText) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
Q_D(QLineEdit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
if (d->placeholderText != placeholderText) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
d->placeholderText = placeholderText; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
if (!hasFocus()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
update(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
} |
0 | 415 |
|
416 |
/*! |
|
417 |
\property QLineEdit::displayText |
|
418 |
\brief the displayed text |
|
419 |
||
420 |
If \l echoMode is \l Normal this returns the same as text(); if |
|
421 |
\l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of asterisks |
|
422 |
text().length() characters long, e.g. "******"; if \l EchoMode is |
|
423 |
\l NoEcho returns an empty string, "". |
|
424 |
||
425 |
By default, this property contains an empty string. |
|
426 |
||
427 |
\sa setEchoMode() text() EchoMode |
|
428 |
*/ |
|
429 |
||
430 |
QString QLineEdit::displayText() const |
|
431 |
{ |
|
432 |
Q_D(const QLineEdit); |
|
433 |
return d->control->displayText(); |
|
434 |
} |
|
435 |
||
436 |
||
437 |
/*! |
|
438 |
\property QLineEdit::maxLength |
|
439 |
\brief the maximum permitted length of the text |
|
440 |
||
441 |
If the text is too long, it is truncated at the limit. |
|
442 |
||
443 |
If truncation occurs any selected text will be unselected, the |
|
444 |
cursor position is set to 0 and the first part of the string is |
|
445 |
shown. |
|
446 |
||
447 |
If the line edit has an input mask, the mask defines the maximum |
|
448 |
string length. |
|
449 |
||
450 |
By default, this property contains a value of 32767. |
|
451 |
||
452 |
\sa inputMask |
|
453 |
*/ |
|
454 |
||
455 |
int QLineEdit::maxLength() const |
|
456 |
{ |
|
457 |
Q_D(const QLineEdit); |
|
458 |
return d->control->maxLength(); |
|
459 |
} |
|
460 |
||
461 |
void QLineEdit::setMaxLength(int maxLength) |
|
462 |
{ |
|
463 |
Q_D(QLineEdit); |
|
464 |
d->control->setMaxLength(maxLength); |
|
465 |
} |
|
466 |
||
467 |
/*! |
|
468 |
\property QLineEdit::frame |
|
469 |
\brief whether the line edit draws itself with a frame |
|
470 |
||
471 |
If enabled (the default) the line edit draws itself inside a |
|
472 |
frame, otherwise the line edit draws itself without any frame. |
|
473 |
*/ |
|
474 |
bool QLineEdit::hasFrame() const |
|
475 |
{ |
|
476 |
Q_D(const QLineEdit); |
|
477 |
return d->frame; |
|
478 |
} |
|
479 |
||
480 |
||
481 |
void QLineEdit::setFrame(bool enable) |
|
482 |
{ |
|
483 |
Q_D(QLineEdit); |
|
484 |
d->frame = enable; |
|
485 |
update(); |
|
486 |
updateGeometry(); |
|
487 |
} |
|
488 |
||
489 |
||
490 |
/*! |
|
491 |
\enum QLineEdit::EchoMode |
|
492 |
||
493 |
This enum type describes how a line edit should display its |
|
494 |
contents. |
|
495 |
||
496 |
\value Normal Display characters as they are entered. This is the |
|
497 |
default. |
|
498 |
\value NoEcho Do not display anything. This may be appropriate |
|
499 |
for passwords where even the length of the |
|
500 |
password should be kept secret. |
|
501 |
\value Password Display asterisks instead of the characters |
|
502 |
actually entered. |
|
503 |
\value PasswordEchoOnEdit Display characters as they are entered |
|
504 |
while editing otherwise display asterisks. |
|
505 |
||
506 |
\sa setEchoMode() echoMode() |
|
507 |
*/ |
|
508 |
||
509 |
||
510 |
/*! |
|
511 |
\property QLineEdit::echoMode |
|
512 |
\brief the line edit's echo mode |
|
513 |
||
514 |
The echo mode determines how the text entered in the line edit is |
|
515 |
displayed (or echoed) to the user. |
|
516 |
||
517 |
The most common setting is \l Normal, in which the text entered by the |
|
518 |
user is displayed verbatim, but QLineEdit also supports modes that allow |
|
519 |
the entered text to be suppressed or obscured: these include \l NoEcho, |
|
520 |
\l Password and \l PasswordEchoOnEdit. |
|
521 |
||
522 |
The widget's display and the ability to copy or drag the text is |
|
523 |
affected by this setting. |
|
524 |
||
525 |
By default, this property is set to \l Normal. |
|
526 |
||
527 |
\sa EchoMode displayText() |
|
528 |
*/ |
|
529 |
||
530 |
QLineEdit::EchoMode QLineEdit::echoMode() const |
|
531 |
{ |
|
532 |
Q_D(const QLineEdit); |
|
533 |
return (EchoMode) d->control->echoMode(); |
|
534 |
} |
|
535 |
||
536 |
void QLineEdit::setEchoMode(EchoMode mode) |
|
537 |
{ |
|
538 |
Q_D(QLineEdit); |
|
539 |
if (mode == (EchoMode)d->control->echoMode()) |
|
540 |
return; |
|
541 |
Qt::InputMethodHints imHints = inputMethodHints(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
542 |
if (mode == Password || mode == NoEcho) { |
0 | 543 |
imHints |= Qt::ImhHiddenText; |
544 |
} else { |
|
545 |
imHints &= ~Qt::ImhHiddenText; |
|
546 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
547 |
if (mode != Normal) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
548 |
imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
549 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
550 |
imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
551 |
} |
0 | 552 |
setInputMethodHints(imHints); |
553 |
d->control->setEchoMode(mode); |
|
554 |
update(); |
|
555 |
#ifdef Q_WS_MAC |
|
556 |
if (hasFocus()) |
|
557 |
qt_mac_secure_keyboard(mode == Password || mode == NoEcho); |
|
558 |
#endif |
|
559 |
} |
|
560 |
||
561 |
||
562 |
#ifndef QT_NO_VALIDATOR |
|
563 |
/*! |
|
564 |
Returns a pointer to the current input validator, or 0 if no |
|
565 |
validator has been set. |
|
566 |
||
567 |
\sa setValidator() |
|
568 |
*/ |
|
569 |
||
570 |
const QValidator * QLineEdit::validator() const |
|
571 |
{ |
|
572 |
Q_D(const QLineEdit); |
|
573 |
return d->control->validator(); |
|
574 |
} |
|
575 |
||
576 |
/*! |
|
577 |
Sets this line edit to only accept input that the validator, \a v, |
|
578 |
will accept. This allows you to place any arbitrary constraints on |
|
579 |
the text which may be entered. |
|
580 |
||
581 |
If \a v == 0, setValidator() removes the current input validator. |
|
582 |
The initial setting is to have no input validator (i.e. any input |
|
583 |
is accepted up to maxLength()). |
|
584 |
||
585 |
\sa validator() QIntValidator QDoubleValidator QRegExpValidator |
|
586 |
*/ |
|
587 |
||
588 |
void QLineEdit::setValidator(const QValidator *v) |
|
589 |
{ |
|
590 |
Q_D(QLineEdit); |
|
591 |
d->control->setValidator(v); |
|
592 |
} |
|
593 |
#endif // QT_NO_VALIDATOR |
|
594 |
||
595 |
#ifndef QT_NO_COMPLETER |
|
596 |
/*! |
|
597 |
\since 4.2 |
|
598 |
||
599 |
Sets this line edit to provide auto completions from the completer, \a c. |
|
600 |
The completion mode is set using QCompleter::setCompletionMode(). |
|
601 |
||
602 |
To use a QCompleter with a QValidator or QLineEdit::inputMask, you need to |
|
603 |
ensure that the model provided to QCompleter contains valid entries. You can |
|
604 |
use the QSortFilterProxyModel to ensure that the QCompleter's model contains |
|
605 |
only valid entries. |
|
606 |
||
607 |
If \a c == 0, setCompleter() removes the current completer, effectively |
|
608 |
disabling auto completion. |
|
609 |
||
610 |
\sa QCompleter |
|
611 |
*/ |
|
612 |
void QLineEdit::setCompleter(QCompleter *c) |
|
613 |
{ |
|
614 |
Q_D(QLineEdit); |
|
615 |
if (c == d->control->completer()) |
|
616 |
return; |
|
617 |
if (d->control->completer()) { |
|
618 |
disconnect(d->control->completer(), 0, this, 0); |
|
619 |
d->control->completer()->setWidget(0); |
|
620 |
if (d->control->completer()->parent() == this) |
|
621 |
delete d->control->completer(); |
|
622 |
} |
|
623 |
d->control->setCompleter(c); |
|
624 |
if (!c) |
|
625 |
return; |
|
626 |
if (c->widget() == 0) |
|
627 |
c->setWidget(this); |
|
628 |
if (hasFocus()) { |
|
629 |
QObject::connect(d->control->completer(), SIGNAL(activated(QString)), |
|
630 |
this, SLOT(setText(QString))); |
|
631 |
QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)), |
|
632 |
this, SLOT(_q_completionHighlighted(QString))); |
|
633 |
} |
|
634 |
} |
|
635 |
||
636 |
/*! |
|
637 |
\since 4.2 |
|
638 |
||
639 |
Returns the current QCompleter that provides completions. |
|
640 |
*/ |
|
641 |
QCompleter *QLineEdit::completer() const |
|
642 |
{ |
|
643 |
Q_D(const QLineEdit); |
|
644 |
return d->control->completer(); |
|
645 |
} |
|
646 |
||
647 |
#endif // QT_NO_COMPLETER |
|
648 |
||
649 |
/*! |
|
650 |
Returns a recommended size for the widget. |
|
651 |
||
652 |
The width returned, in pixels, is usually enough for about 15 to |
|
653 |
20 characters. |
|
654 |
*/ |
|
655 |
||
656 |
QSize QLineEdit::sizeHint() const |
|
657 |
{ |
|
658 |
Q_D(const QLineEdit); |
|
659 |
ensurePolished(); |
|
660 |
QFontMetrics fm(font()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
int h = qMax(fm.height(), 14) + 2*d->verticalMargin |
0 | 662 |
+ d->topTextMargin + d->bottomTextMargin |
663 |
+ d->topmargin + d->bottommargin; |
|
664 |
int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin |
|
665 |
+ d->leftTextMargin + d->rightTextMargin |
|
666 |
+ d->leftmargin + d->rightmargin; // "some" |
|
667 |
QStyleOptionFrameV2 opt; |
|
668 |
initStyleOption(&opt); |
|
669 |
return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h). |
|
670 |
expandedTo(QApplication::globalStrut()), this)); |
|
671 |
} |
|
672 |
||
673 |
||
674 |
/*! |
|
675 |
Returns a minimum size for the line edit. |
|
676 |
||
677 |
The width returned is enough for at least one character. |
|
678 |
*/ |
|
679 |
||
680 |
QSize QLineEdit::minimumSizeHint() const |
|
681 |
{ |
|
682 |
Q_D(const QLineEdit); |
|
683 |
ensurePolished(); |
|
684 |
QFontMetrics fm = fontMetrics(); |
|
685 |
int h = fm.height() + qMax(2*d->verticalMargin, fm.leading()) |
|
686 |
+ d->topmargin + d->bottommargin; |
|
687 |
int w = fm.maxWidth() + d->leftmargin + d->rightmargin; |
|
688 |
QStyleOptionFrameV2 opt; |
|
689 |
initStyleOption(&opt); |
|
690 |
return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h). |
|
691 |
expandedTo(QApplication::globalStrut()), this)); |
|
692 |
} |
|
693 |
||
694 |
||
695 |
/*! |
|
696 |
\property QLineEdit::cursorPosition |
|
697 |
\brief the current cursor position for this line edit |
|
698 |
||
699 |
Setting the cursor position causes a repaint when appropriate. |
|
700 |
||
701 |
By default, this property contains a value of 0. |
|
702 |
*/ |
|
703 |
||
704 |
int QLineEdit::cursorPosition() const |
|
705 |
{ |
|
706 |
Q_D(const QLineEdit); |
|
707 |
return d->control->cursorPosition(); |
|
708 |
} |
|
709 |
||
710 |
void QLineEdit::setCursorPosition(int pos) |
|
711 |
{ |
|
712 |
Q_D(QLineEdit); |
|
713 |
d->control->setCursorPosition(pos); |
|
714 |
} |
|
715 |
||
716 |
/*! |
|
717 |
Returns the cursor position under the point \a pos. |
|
718 |
*/ |
|
719 |
// ### What should this do if the point is outside of contentsRect? Currently returns 0. |
|
720 |
int QLineEdit::cursorPositionAt(const QPoint &pos) |
|
721 |
{ |
|
722 |
Q_D(QLineEdit); |
|
723 |
return d->xToPos(pos.x()); |
|
724 |
} |
|
725 |
||
726 |
||
727 |
#ifdef QT3_SUPPORT |
|
728 |
/*! \obsolete |
|
729 |
||
730 |
Use setText(), setCursorPosition() and setSelection() instead. |
|
731 |
*/ |
|
732 |
bool QLineEdit::validateAndSet(const QString &newText, int newPos, |
|
733 |
int newMarkAnchor, int newMarkDrag) |
|
734 |
{ |
|
735 |
// The suggested functions above in the docs don't seem to validate, |
|
736 |
// below code tries to mimic previous behaviour. |
|
737 |
QString oldText = text(); |
|
738 |
setText(newText); |
|
739 |
if(!hasAcceptableInput()){ |
|
740 |
setText(oldText); |
|
741 |
return false; |
|
742 |
} |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
743 |
int selstart = qMin(newMarkAnchor, newMarkDrag); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
744 |
int sellength = qAbs(newMarkAnchor - newMarkDrag); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
745 |
if (selstart == newPos) { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
746 |
selstart = qMax(newMarkAnchor, newMarkDrag); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
747 |
sellength = -sellength; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
748 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
749 |
//setSelection also set the position |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
750 |
setSelection(selstart, sellength); |
0 | 751 |
return true; |
752 |
} |
|
753 |
#endif //QT3_SUPPORT |
|
754 |
||
755 |
/*! |
|
756 |
\property QLineEdit::alignment |
|
757 |
\brief the alignment of the line edit |
|
758 |
||
759 |
Both horizontal and vertical alignment is allowed here, Qt::AlignJustify |
|
760 |
will map to Qt::AlignLeft. |
|
761 |
||
762 |
By default, this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter. |
|
763 |
||
764 |
\sa Qt::Alignment |
|
765 |
*/ |
|
766 |
||
767 |
Qt::Alignment QLineEdit::alignment() const |
|
768 |
{ |
|
769 |
Q_D(const QLineEdit); |
|
770 |
return QFlag(d->alignment); |
|
771 |
} |
|
772 |
||
773 |
void QLineEdit::setAlignment(Qt::Alignment alignment) |
|
774 |
{ |
|
775 |
Q_D(QLineEdit); |
|
776 |
d->alignment = alignment; |
|
777 |
update(); |
|
778 |
} |
|
779 |
||
780 |
||
781 |
/*! |
|
782 |
Moves the cursor forward \a steps characters. If \a mark is true |
|
783 |
each character moved over is added to the selection; if \a mark is |
|
784 |
false the selection is cleared. |
|
785 |
||
786 |
\sa cursorBackward() |
|
787 |
*/ |
|
788 |
||
789 |
void QLineEdit::cursorForward(bool mark, int steps) |
|
790 |
{ |
|
791 |
Q_D(QLineEdit); |
|
792 |
d->control->cursorForward(mark, steps); |
|
793 |
} |
|
794 |
||
795 |
||
796 |
/*! |
|
797 |
Moves the cursor back \a steps characters. If \a mark is true each |
|
798 |
character moved over is added to the selection; if \a mark is |
|
799 |
false the selection is cleared. |
|
800 |
||
801 |
\sa cursorForward() |
|
802 |
*/ |
|
803 |
void QLineEdit::cursorBackward(bool mark, int steps) |
|
804 |
{ |
|
805 |
cursorForward(mark, -steps); |
|
806 |
} |
|
807 |
||
808 |
/*! |
|
809 |
Moves the cursor one word forward. If \a mark is true, the word is |
|
810 |
also selected. |
|
811 |
||
812 |
\sa cursorWordBackward() |
|
813 |
*/ |
|
814 |
void QLineEdit::cursorWordForward(bool mark) |
|
815 |
{ |
|
816 |
Q_D(QLineEdit); |
|
817 |
d->control->cursorWordForward(mark); |
|
818 |
} |
|
819 |
||
820 |
/*! |
|
821 |
Moves the cursor one word backward. If \a mark is true, the word |
|
822 |
is also selected. |
|
823 |
||
824 |
\sa cursorWordForward() |
|
825 |
*/ |
|
826 |
||
827 |
void QLineEdit::cursorWordBackward(bool mark) |
|
828 |
{ |
|
829 |
Q_D(QLineEdit); |
|
830 |
d->control->cursorWordBackward(mark); |
|
831 |
} |
|
832 |
||
833 |
||
834 |
/*! |
|
835 |
If no text is selected, deletes the character to the left of the |
|
836 |
text cursor and moves the cursor one position to the left. If any |
|
837 |
text is selected, the cursor is moved to the beginning of the |
|
838 |
selected text and the selected text is deleted. |
|
839 |
||
840 |
\sa del() |
|
841 |
*/ |
|
842 |
void QLineEdit::backspace() |
|
843 |
{ |
|
844 |
Q_D(QLineEdit); |
|
845 |
d->control->backspace(); |
|
846 |
} |
|
847 |
||
848 |
/*! |
|
849 |
If no text is selected, deletes the character to the right of the |
|
850 |
text cursor. If any text is selected, the cursor is moved to the |
|
851 |
beginning of the selected text and the selected text is deleted. |
|
852 |
||
853 |
\sa backspace() |
|
854 |
*/ |
|
855 |
||
856 |
void QLineEdit::del() |
|
857 |
{ |
|
858 |
Q_D(QLineEdit); |
|
859 |
d->control->del(); |
|
860 |
} |
|
861 |
||
862 |
/*! |
|
863 |
Moves the text cursor to the beginning of the line unless it is |
|
864 |
already there. If \a mark is true, text is selected towards the |
|
865 |
first position; otherwise, any selected text is unselected if the |
|
866 |
cursor is moved. |
|
867 |
||
868 |
\sa end() |
|
869 |
*/ |
|
870 |
||
871 |
void QLineEdit::home(bool mark) |
|
872 |
{ |
|
873 |
Q_D(QLineEdit); |
|
874 |
d->control->home(mark); |
|
875 |
} |
|
876 |
||
877 |
/*! |
|
878 |
Moves the text cursor to the end of the line unless it is already |
|
879 |
there. If \a mark is true, text is selected towards the last |
|
880 |
position; otherwise, any selected text is unselected if the cursor |
|
881 |
is moved. |
|
882 |
||
883 |
\sa home() |
|
884 |
*/ |
|
885 |
||
886 |
void QLineEdit::end(bool mark) |
|
887 |
{ |
|
888 |
Q_D(QLineEdit); |
|
889 |
d->control->end(mark); |
|
890 |
} |
|
891 |
||
892 |
||
893 |
/*! |
|
894 |
\property QLineEdit::modified |
|
895 |
\brief whether the line edit's contents has been modified by the user |
|
896 |
||
897 |
The modified flag is never read by QLineEdit; it has a default value |
|
898 |
of false and is changed to true whenever the user changes the line |
|
899 |
edit's contents. |
|
900 |
||
901 |
This is useful for things that need to provide a default value but |
|
902 |
do not start out knowing what the default should be (perhaps it |
|
903 |
depends on other fields on the form). Start the line edit without |
|
904 |
the best default, and when the default is known, if modified() |
|
905 |
returns false (the user hasn't entered any text), insert the |
|
906 |
default value. |
|
907 |
||
908 |
Calling setText() resets the modified flag to false. |
|
909 |
*/ |
|
910 |
||
911 |
bool QLineEdit::isModified() const |
|
912 |
{ |
|
913 |
Q_D(const QLineEdit); |
|
914 |
return d->control->isModified(); |
|
915 |
} |
|
916 |
||
917 |
void QLineEdit::setModified(bool modified) |
|
918 |
{ |
|
919 |
Q_D(QLineEdit); |
|
920 |
d->control->setModified(modified); |
|
921 |
} |
|
922 |
||
923 |
||
924 |
/*!\fn QLineEdit::clearModified() |
|
925 |
||
926 |
Use setModified(false) instead. |
|
927 |
||
928 |
\sa isModified() |
|
929 |
*/ |
|
930 |
||
931 |
||
932 |
/*! |
|
933 |
\property QLineEdit::hasSelectedText |
|
934 |
\brief whether there is any text selected |
|
935 |
||
936 |
hasSelectedText() returns true if some or all of the text has been |
|
937 |
selected by the user; otherwise returns false. |
|
938 |
||
939 |
By default, this property is false. |
|
940 |
||
941 |
\sa selectedText() |
|
942 |
*/ |
|
943 |
||
944 |
||
945 |
bool QLineEdit::hasSelectedText() const |
|
946 |
{ |
|
947 |
Q_D(const QLineEdit); |
|
948 |
return d->control->hasSelectedText(); |
|
949 |
} |
|
950 |
||
951 |
/*! |
|
952 |
\property QLineEdit::selectedText |
|
953 |
\brief the selected text |
|
954 |
||
955 |
If there is no selected text this property's value is |
|
956 |
an empty string. |
|
957 |
||
958 |
By default, this property contains an empty string. |
|
959 |
||
960 |
\sa hasSelectedText() |
|
961 |
*/ |
|
962 |
||
963 |
QString QLineEdit::selectedText() const |
|
964 |
{ |
|
965 |
Q_D(const QLineEdit); |
|
966 |
return d->control->selectedText(); |
|
967 |
} |
|
968 |
||
969 |
/*! |
|
970 |
selectionStart() returns the index of the first selected character in the |
|
971 |
line edit or -1 if no text is selected. |
|
972 |
||
973 |
\sa selectedText() |
|
974 |
*/ |
|
975 |
||
976 |
int QLineEdit::selectionStart() const |
|
977 |
{ |
|
978 |
Q_D(const QLineEdit); |
|
979 |
return d->control->selectionStart(); |
|
980 |
} |
|
981 |
||
982 |
||
983 |
#ifdef QT3_SUPPORT |
|
984 |
||
985 |
/*! |
|
986 |
\fn void QLineEdit::lostFocus() |
|
987 |
||
988 |
This signal is emitted when the line edit has lost focus. |
|
989 |
||
990 |
Use editingFinished() instead |
|
991 |
\sa editingFinished(), returnPressed() |
|
992 |
*/ |
|
993 |
||
994 |
/*! |
|
995 |
Use isModified() instead. |
|
996 |
*/ |
|
997 |
bool QLineEdit::edited() const { return isModified(); } |
|
998 |
/*! |
|
999 |
Use setModified() or setText(). |
|
1000 |
*/ |
|
1001 |
void QLineEdit::setEdited(bool on) { setModified(on); } |
|
1002 |
||
1003 |
/*! |
|
1004 |
There exists no equivalent functionality in Qt 4. |
|
1005 |
*/ |
|
1006 |
int QLineEdit::characterAt(int xpos, QChar *chr) const |
|
1007 |
{ |
|
1008 |
Q_D(const QLineEdit); |
|
1009 |
int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + d->horizontalMargin); |
|
1010 |
QString txt = d->control->text(); |
|
1011 |
if (chr && pos < (int) txt.length()) |
|
1012 |
*chr = txt.at(pos); |
|
1013 |
return pos; |
|
1014 |
||
1015 |
} |
|
1016 |
||
1017 |
/*! |
|
1018 |
Use selectedText() and selectionStart() instead. |
|
1019 |
*/ |
|
1020 |
bool QLineEdit::getSelection(int *start, int *end) |
|
1021 |
{ |
|
1022 |
Q_D(QLineEdit); |
|
1023 |
if (d->control->hasSelectedText() && start && end) { |
|
1024 |
*start = selectionStart(); |
|
1025 |
*end = *start + selectedText().length(); |
|
1026 |
return true; |
|
1027 |
} |
|
1028 |
return false; |
|
1029 |
} |
|
1030 |
#endif |
|
1031 |
||
1032 |
||
1033 |
/*! |
|
1034 |
Selects text from position \a start and for \a length characters. |
|
1035 |
Negative lengths are allowed. |
|
1036 |
||
1037 |
\sa deselect() selectAll() selectedText() |
|
1038 |
*/ |
|
1039 |
||
1040 |
void QLineEdit::setSelection(int start, int length) |
|
1041 |
{ |
|
1042 |
Q_D(QLineEdit); |
|
1043 |
if (start < 0 || start > (int)d->control->text().length()) { |
|
1044 |
qWarning("QLineEdit::setSelection: Invalid start position (%d)", start); |
|
1045 |
return; |
|
1046 |
} |
|
1047 |
||
1048 |
d->control->setSelection(start, length); |
|
1049 |
||
1050 |
if (d->control->hasSelectedText()){ |
|
1051 |
QStyleOptionFrameV2 opt; |
|
1052 |
initStyleOption(&opt); |
|
1053 |
if (!style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) |
|
1054 |
d->setCursorVisible(false); |
|
1055 |
} |
|
1056 |
} |
|
1057 |
||
1058 |
||
1059 |
/*! |
|
1060 |
\property QLineEdit::undoAvailable |
|
1061 |
\brief whether undo is available |
|
1062 |
||
1063 |
Undo becomes available once the user has modified the text in the line edit. |
|
1064 |
||
1065 |
By default, this property is false. |
|
1066 |
*/ |
|
1067 |
||
1068 |
bool QLineEdit::isUndoAvailable() const |
|
1069 |
{ |
|
1070 |
Q_D(const QLineEdit); |
|
1071 |
return d->control->isUndoAvailable(); |
|
1072 |
} |
|
1073 |
||
1074 |
/*! |
|
1075 |
\property QLineEdit::redoAvailable |
|
1076 |
\brief whether redo is available |
|
1077 |
||
1078 |
Redo becomes available once the user has performed one or more undo operations |
|
1079 |
on text in the line edit. |
|
1080 |
||
1081 |
By default, this property is false. |
|
1082 |
*/ |
|
1083 |
||
1084 |
bool QLineEdit::isRedoAvailable() const |
|
1085 |
{ |
|
1086 |
Q_D(const QLineEdit); |
|
1087 |
return d->control->isRedoAvailable(); |
|
1088 |
} |
|
1089 |
||
1090 |
/*! |
|
1091 |
\property QLineEdit::dragEnabled |
|
1092 |
\brief whether the lineedit starts a drag if the user presses and |
|
1093 |
moves the mouse on some selected text |
|
1094 |
||
1095 |
Dragging is disabled by default. |
|
1096 |
*/ |
|
1097 |
||
1098 |
bool QLineEdit::dragEnabled() const |
|
1099 |
{ |
|
1100 |
Q_D(const QLineEdit); |
|
1101 |
return d->dragEnabled; |
|
1102 |
} |
|
1103 |
||
1104 |
void QLineEdit::setDragEnabled(bool b) |
|
1105 |
{ |
|
1106 |
Q_D(QLineEdit); |
|
1107 |
d->dragEnabled = b; |
|
1108 |
} |
|
1109 |
||
1110 |
||
1111 |
/*! |
|
1112 |
\property QLineEdit::acceptableInput |
|
1113 |
\brief whether the input satisfies the inputMask and the |
|
1114 |
validator. |
|
1115 |
||
1116 |
By default, this property is true. |
|
1117 |
||
1118 |
\sa setInputMask(), setValidator() |
|
1119 |
*/ |
|
1120 |
bool QLineEdit::hasAcceptableInput() const |
|
1121 |
{ |
|
1122 |
Q_D(const QLineEdit); |
|
1123 |
return d->control->hasAcceptableInput(); |
|
1124 |
} |
|
1125 |
||
1126 |
/*! |
|
1127 |
Sets the margins around the text inside the frame to have the |
|
1128 |
sizes \a left, \a top, \a right, and \a bottom. |
|
1129 |
\since 4.5 |
|
1130 |
||
1131 |
See also getTextMargins(). |
|
1132 |
*/ |
|
1133 |
void QLineEdit::setTextMargins(int left, int top, int right, int bottom) |
|
1134 |
{ |
|
1135 |
Q_D(QLineEdit); |
|
1136 |
d->leftTextMargin = left; |
|
1137 |
d->topTextMargin = top; |
|
1138 |
d->rightTextMargin = right; |
|
1139 |
d->bottomTextMargin = bottom; |
|
1140 |
updateGeometry(); |
|
1141 |
update(); |
|
1142 |
} |
|
1143 |
||
1144 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1145 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1146 |
Sets the \a margins around the text inside the frame. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1147 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1148 |
See also textMargins(). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1149 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1150 |
void QLineEdit::setTextMargins(const QMargins &margins) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1151 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1152 |
setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1153 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1154 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1155 |
/*! |
0 | 1156 |
Returns the widget's text margins for \a left, \a top, \a right, and \a bottom. |
1157 |
\since 4.5 |
|
1158 |
||
1159 |
\sa setTextMargins() |
|
1160 |
*/ |
|
1161 |
void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const |
|
1162 |
{ |
|
1163 |
Q_D(const QLineEdit); |
|
1164 |
if (left) |
|
1165 |
*left = d->leftTextMargin; |
|
1166 |
if (top) |
|
1167 |
*top = d->topTextMargin; |
|
1168 |
if (right) |
|
1169 |
*right = d->rightTextMargin; |
|
1170 |
if (bottom) |
|
1171 |
*bottom = d->bottomTextMargin; |
|
1172 |
} |
|
1173 |
||
1174 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1175 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1176 |
Returns the widget's text margins. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1177 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1178 |
\sa setTextMargins() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1179 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1180 |
QMargins QLineEdit::textMargins() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
Q_D(const QLineEdit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
/*! |
0 | 1187 |
\property QLineEdit::inputMask |
1188 |
\brief The validation input mask |
|
1189 |
||
1190 |
If no mask is set, inputMask() returns an empty string. |
|
1191 |
||
1192 |
Sets the QLineEdit's validation mask. Validators can be used |
|
1193 |
instead of, or in conjunction with masks; see setValidator(). |
|
1194 |
||
1195 |
Unset the mask and return to normal QLineEdit operation by passing |
|
1196 |
an empty string ("") or just calling setInputMask() with no |
|
1197 |
arguments. |
|
1198 |
||
1199 |
The table below shows the characters that can be used in an input mask. |
|
1200 |
A space character, the default character for a blank, is needed for cases |
|
1201 |
where a character is \e{permitted but not required}. |
|
1202 |
||
1203 |
\table |
|
1204 |
\header \i Character \i Meaning |
|
1205 |
\row \i \c A \i ASCII alphabetic character required. A-Z, a-z. |
|
1206 |
\row \i \c a \i ASCII alphabetic character permitted but not required. |
|
1207 |
\row \i \c N \i ASCII alphanumeric character required. A-Z, a-z, 0-9. |
|
1208 |
\row \i \c n \i ASCII alphanumeric character permitted but not required. |
|
1209 |
\row \i \c X \i Any character required. |
|
1210 |
\row \i \c x \i Any character permitted but not required. |
|
1211 |
\row \i \c 9 \i ASCII digit required. 0-9. |
|
1212 |
\row \i \c 0 \i ASCII digit permitted but not required. |
|
1213 |
\row \i \c D \i ASCII digit required. 1-9. |
|
1214 |
\row \i \c d \i ASCII digit permitted but not required (1-9). |
|
1215 |
\row \i \c # \i ASCII digit or plus/minus sign permitted but not required. |
|
1216 |
\row \i \c H \i Hexadecimal character required. A-F, a-f, 0-9. |
|
1217 |
\row \i \c h \i Hexadecimal character permitted but not required. |
|
1218 |
\row \i \c B \i Binary character required. 0-1. |
|
1219 |
\row \i \c b \i Binary character permitted but not required. |
|
1220 |
\row \i \c > \i All following alphabetic characters are uppercased. |
|
1221 |
\row \i \c < \i All following alphabetic characters are lowercased. |
|
1222 |
\row \i \c ! \i Switch off case conversion. |
|
1223 |
\row \i \tt{\\} \i Use \tt{\\} to escape the special |
|
1224 |
characters listed above to use them as |
|
1225 |
separators. |
|
1226 |
\endtable |
|
1227 |
||
1228 |
The mask consists of a string of mask characters and separators, |
|
1229 |
optionally followed by a semicolon and the character used for |
|
1230 |
blanks. The blank characters are always removed from the text |
|
1231 |
after editing. |
|
1232 |
||
1233 |
Examples: |
|
1234 |
\table |
|
1235 |
\header \i Mask \i Notes |
|
1236 |
\row \i \c 000.000.000.000;_ \i IP address; blanks are \c{_}. |
|
1237 |
\row \i \c HH:HH:HH:HH:HH:HH;_ \i MAC address |
|
1238 |
\row \i \c 0000-00-00 \i ISO Date; blanks are \c space |
|
1239 |
\row \i \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \i License number; |
|
1240 |
blanks are \c - and all (alphabetic) characters are converted to |
|
1241 |
uppercase. |
|
1242 |
\endtable |
|
1243 |
||
1244 |
To get range control (e.g., for an IP address) use masks together |
|
1245 |
with \link setValidator() validators\endlink. |
|
1246 |
||
1247 |
\sa maxLength |
|
1248 |
*/ |
|
1249 |
QString QLineEdit::inputMask() const |
|
1250 |
{ |
|
1251 |
Q_D(const QLineEdit); |
|
1252 |
return d->control->inputMask(); |
|
1253 |
} |
|
1254 |
||
1255 |
void QLineEdit::setInputMask(const QString &inputMask) |
|
1256 |
{ |
|
1257 |
Q_D(QLineEdit); |
|
1258 |
d->control->setInputMask(inputMask); |
|
1259 |
} |
|
1260 |
||
1261 |
/*! |
|
1262 |
Selects all the text (i.e. highlights it) and moves the cursor to |
|
1263 |
the end. This is useful when a default value has been inserted |
|
1264 |
because if the user types before clicking on the widget, the |
|
1265 |
selected text will be deleted. |
|
1266 |
||
1267 |
\sa setSelection() deselect() |
|
1268 |
*/ |
|
1269 |
||
1270 |
void QLineEdit::selectAll() |
|
1271 |
{ |
|
1272 |
Q_D(QLineEdit); |
|
1273 |
d->control->selectAll(); |
|
1274 |
} |
|
1275 |
||
1276 |
/*! |
|
1277 |
Deselects any selected text. |
|
1278 |
||
1279 |
\sa setSelection() selectAll() |
|
1280 |
*/ |
|
1281 |
||
1282 |
void QLineEdit::deselect() |
|
1283 |
{ |
|
1284 |
Q_D(QLineEdit); |
|
1285 |
d->control->deselect(); |
|
1286 |
} |
|
1287 |
||
1288 |
||
1289 |
/*! |
|
1290 |
Deletes any selected text, inserts \a newText, and validates the |
|
1291 |
result. If it is valid, it sets it as the new contents of the line |
|
1292 |
edit. |
|
1293 |
||
1294 |
\sa setText(), clear() |
|
1295 |
*/ |
|
1296 |
void QLineEdit::insert(const QString &newText) |
|
1297 |
{ |
|
1298 |
// q->resetInputContext(); //#### FIX ME IN QT |
|
1299 |
Q_D(QLineEdit); |
|
1300 |
d->control->insert(newText); |
|
1301 |
} |
|
1302 |
||
1303 |
/*! |
|
1304 |
Clears the contents of the line edit. |
|
1305 |
||
1306 |
\sa setText(), insert() |
|
1307 |
*/ |
|
1308 |
void QLineEdit::clear() |
|
1309 |
{ |
|
1310 |
Q_D(QLineEdit); |
|
1311 |
resetInputContext(); |
|
1312 |
d->control->clear(); |
|
1313 |
} |
|
1314 |
||
1315 |
/*! |
|
1316 |
Undoes the last operation if undo is \link |
|
1317 |
QLineEdit::undoAvailable available\endlink. Deselects any current |
|
1318 |
selection, and updates the selection start to the current cursor |
|
1319 |
position. |
|
1320 |
*/ |
|
1321 |
void QLineEdit::undo() |
|
1322 |
{ |
|
1323 |
Q_D(QLineEdit); |
|
1324 |
resetInputContext(); |
|
1325 |
d->control->undo(); |
|
1326 |
} |
|
1327 |
||
1328 |
/*! |
|
1329 |
Redoes the last operation if redo is \link |
|
1330 |
QLineEdit::redoAvailable available\endlink. |
|
1331 |
*/ |
|
1332 |
void QLineEdit::redo() |
|
1333 |
{ |
|
1334 |
Q_D(QLineEdit); |
|
1335 |
resetInputContext(); |
|
1336 |
d->control->redo(); |
|
1337 |
} |
|
1338 |
||
1339 |
||
1340 |
/*! |
|
1341 |
\property QLineEdit::readOnly |
|
1342 |
\brief whether the line edit is read only. |
|
1343 |
||
1344 |
In read-only mode, the user can still copy the text to the |
|
1345 |
clipboard, or drag and drop the text (if echoMode() is \l Normal), |
|
1346 |
but cannot edit it. |
|
1347 |
||
1348 |
QLineEdit does not show a cursor in read-only mode. |
|
1349 |
||
1350 |
By default, this property is false. |
|
1351 |
||
1352 |
\sa setEnabled() |
|
1353 |
*/ |
|
1354 |
||
1355 |
bool QLineEdit::isReadOnly() const |
|
1356 |
{ |
|
1357 |
Q_D(const QLineEdit); |
|
1358 |
return d->control->isReadOnly(); |
|
1359 |
} |
|
1360 |
||
1361 |
void QLineEdit::setReadOnly(bool enable) |
|
1362 |
{ |
|
1363 |
Q_D(QLineEdit); |
|
1364 |
if (d->control->isReadOnly() != enable) { |
|
1365 |
d->control->setReadOnly(enable); |
|
1366 |
setAttribute(Qt::WA_MacShowFocusRect, !enable); |
|
1367 |
setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod()); |
|
1368 |
#ifndef QT_NO_CURSOR |
|
1369 |
setCursor(enable ? Qt::ArrowCursor : Qt::IBeamCursor); |
|
1370 |
#endif |
|
1371 |
update(); |
|
1372 |
} |
|
1373 |
} |
|
1374 |
||
1375 |
||
1376 |
#ifndef QT_NO_CLIPBOARD |
|
1377 |
/*! |
|
1378 |
Copies the selected text to the clipboard and deletes it, if there |
|
1379 |
is any, and if echoMode() is \l Normal. |
|
1380 |
||
1381 |
If the current validator disallows deleting the selected text, |
|
1382 |
cut() will copy without deleting. |
|
1383 |
||
1384 |
\sa copy() paste() setValidator() |
|
1385 |
*/ |
|
1386 |
||
1387 |
void QLineEdit::cut() |
|
1388 |
{ |
|
1389 |
if (hasSelectedText()) { |
|
1390 |
copy(); |
|
1391 |
del(); |
|
1392 |
} |
|
1393 |
} |
|
1394 |
||
1395 |
||
1396 |
/*! |
|
1397 |
Copies the selected text to the clipboard, if there is any, and if |
|
1398 |
echoMode() is \l Normal. |
|
1399 |
||
1400 |
\sa cut() paste() |
|
1401 |
*/ |
|
1402 |
||
1403 |
void QLineEdit::copy() const |
|
1404 |
{ |
|
1405 |
Q_D(const QLineEdit); |
|
1406 |
d->control->copy(); |
|
1407 |
} |
|
1408 |
||
1409 |
/*! |
|
1410 |
Inserts the clipboard's text at the cursor position, deleting any |
|
1411 |
selected text, providing the line edit is not \link |
|
1412 |
QLineEdit::readOnly read-only\endlink. |
|
1413 |
||
1414 |
If the end result would not be acceptable to the current |
|
1415 |
\link setValidator() validator\endlink, nothing happens. |
|
1416 |
||
1417 |
\sa copy() cut() |
|
1418 |
*/ |
|
1419 |
||
1420 |
void QLineEdit::paste() |
|
1421 |
{ |
|
1422 |
Q_D(QLineEdit); |
|
1423 |
d->control->paste(); |
|
1424 |
} |
|
1425 |
||
1426 |
#endif // !QT_NO_CLIPBOARD |
|
1427 |
||
1428 |
/*! \reimp |
|
1429 |
*/ |
|
1430 |
bool QLineEdit::event(QEvent * e) |
|
1431 |
{ |
|
1432 |
Q_D(QLineEdit); |
|
1433 |
if (e->type() == QEvent::Timer) { |
|
1434 |
// should be timerEvent, is here for binary compatibility |
|
1435 |
int timerId = ((QTimerEvent*)e)->timerId(); |
|
1436 |
if (false) { |
|
1437 |
#ifndef QT_NO_DRAGANDDROP |
|
1438 |
} else if (timerId == d->dndTimer.timerId()) { |
|
1439 |
d->drag(); |
|
1440 |
#endif |
|
1441 |
} |
|
1442 |
else if (timerId == d->tripleClickTimer.timerId()) |
|
1443 |
d->tripleClickTimer.stop(); |
|
1444 |
} else if (e->type() == QEvent::ContextMenu) { |
|
1445 |
#ifndef QT_NO_IM |
|
1446 |
if (d->control->composeMode()) |
|
1447 |
return true; |
|
1448 |
#endif |
|
1449 |
//d->separate(); |
|
1450 |
} else if (e->type() == QEvent::WindowActivate) { |
|
1451 |
QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate())); |
|
1452 |
}else if(e->type() == QEvent::ShortcutOverride){ |
|
1453 |
d->control->processEvent(e); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1454 |
} else if (e->type() == QEvent::KeyRelease) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1455 |
d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1456 |
} else if (e->type() == QEvent::Show) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1457 |
//In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1458 |
if (hasFocus()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1459 |
d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1460 |
QStyleOptionFrameV2 opt; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1461 |
initStyleOption(&opt); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1462 |
if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1463 |
|| style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1464 |
d->setCursorVisible(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1465 |
} |
0 | 1466 |
} |
1467 |
||
1468 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1469 |
if (QApplication::keypadNavigationEnabled()) { |
|
1470 |
if (e->type() == QEvent::EnterEditFocus) { |
|
1471 |
end(false); |
|
1472 |
d->setCursorVisible(true); |
|
1473 |
d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
|
1474 |
} else if (e->type() == QEvent::LeaveEditFocus) { |
|
1475 |
d->setCursorVisible(false); |
|
1476 |
d->control->setCursorBlinkPeriod(0); |
|
1477 |
if (d->control->hasAcceptableInput() || d->control->fixup()) |
|
1478 |
emit editingFinished(); |
|
1479 |
} |
|
1480 |
} |
|
1481 |
#endif |
|
1482 |
return QWidget::event(e); |
|
1483 |
} |
|
1484 |
||
1485 |
/*! \reimp |
|
1486 |
*/ |
|
1487 |
void QLineEdit::mousePressEvent(QMouseEvent* e) |
|
1488 |
{ |
|
1489 |
Q_D(QLineEdit); |
|
1490 |
if (d->sendMouseEventToInputContext(e)) |
|
1491 |
return; |
|
1492 |
if (e->button() == Qt::RightButton) |
|
1493 |
return; |
|
1494 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1495 |
if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { |
|
1496 |
setEditFocus(true); |
|
1497 |
// Get the completion list to pop up. |
|
1498 |
if (d->control->completer()) |
|
1499 |
d->control->completer()->complete(); |
|
1500 |
} |
|
1501 |
#endif |
|
1502 |
if (d->tripleClickTimer.isActive() && (e->pos() - d->tripleClick).manhattanLength() < |
|
1503 |
QApplication::startDragDistance()) { |
|
1504 |
selectAll(); |
|
1505 |
return; |
|
1506 |
} |
|
1507 |
bool mark = e->modifiers() & Qt::ShiftModifier; |
|
1508 |
int cursor = d->xToPos(e->pos().x()); |
|
1509 |
#ifndef QT_NO_DRAGANDDROP |
|
1510 |
if (!mark && d->dragEnabled && d->control->echoMode() == Normal && |
|
1511 |
e->button() == Qt::LeftButton && d->control->inSelection(e->pos().x())) { |
|
1512 |
d->dndPos = e->pos(); |
|
1513 |
if (!d->dndTimer.isActive()) |
|
1514 |
d->dndTimer.start(QApplication::startDragTime(), this); |
|
1515 |
} else |
|
1516 |
#endif |
|
1517 |
{ |
|
1518 |
d->control->moveCursor(cursor, mark); |
|
1519 |
} |
|
1520 |
} |
|
1521 |
||
1522 |
/*! \reimp |
|
1523 |
*/ |
|
1524 |
void QLineEdit::mouseMoveEvent(QMouseEvent * e) |
|
1525 |
{ |
|
1526 |
Q_D(QLineEdit); |
|
1527 |
if (d->sendMouseEventToInputContext(e)) |
|
1528 |
return; |
|
1529 |
||
1530 |
if (e->buttons() & Qt::LeftButton) { |
|
1531 |
#ifndef QT_NO_DRAGANDDROP |
|
1532 |
if (d->dndTimer.isActive()) { |
|
1533 |
if ((d->dndPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) |
|
1534 |
d->drag(); |
|
1535 |
} else |
|
1536 |
#endif |
|
1537 |
{ |
|
1538 |
d->control->moveCursor(d->xToPos(e->pos().x()), true); |
|
1539 |
} |
|
1540 |
} |
|
1541 |
} |
|
1542 |
||
1543 |
/*! \reimp |
|
1544 |
*/ |
|
1545 |
void QLineEdit::mouseReleaseEvent(QMouseEvent* e) |
|
1546 |
{ |
|
1547 |
Q_D(QLineEdit); |
|
1548 |
if (d->sendMouseEventToInputContext(e)) |
|
1549 |
return; |
|
1550 |
#ifndef QT_NO_DRAGANDDROP |
|
1551 |
if (e->button() == Qt::LeftButton) { |
|
1552 |
if (d->dndTimer.isActive()) { |
|
1553 |
d->dndTimer.stop(); |
|
1554 |
deselect(); |
|
1555 |
return; |
|
1556 |
} |
|
1557 |
} |
|
1558 |
#endif |
|
1559 |
#ifndef QT_NO_CLIPBOARD |
|
1560 |
if (QApplication::clipboard()->supportsSelection()) { |
|
1561 |
if (e->button() == Qt::LeftButton) { |
|
1562 |
d->control->copy(QClipboard::Selection); |
|
1563 |
} else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) { |
|
1564 |
deselect(); |
|
1565 |
insert(QApplication::clipboard()->text(QClipboard::Selection)); |
|
1566 |
} |
|
1567 |
} |
|
1568 |
#endif |
|
1569 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1570 |
if (!isReadOnly() && rect().contains(e->pos())) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1571 |
d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus); |
0 | 1572 |
d->clickCausedFocus = 0; |
1573 |
} |
|
1574 |
||
1575 |
/*! \reimp |
|
1576 |
*/ |
|
1577 |
void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e) |
|
1578 |
{ |
|
1579 |
Q_D(QLineEdit); |
|
1580 |
if (d->sendMouseEventToInputContext(e)) |
|
1581 |
return; |
|
1582 |
if (e->button() == Qt::LeftButton) { |
|
1583 |
d->control->selectWordAtPos(d->xToPos(e->pos().x())); |
|
1584 |
d->tripleClickTimer.start(QApplication::doubleClickInterval(), this); |
|
1585 |
d->tripleClick = e->pos(); |
|
1586 |
} |
|
1587 |
} |
|
1588 |
||
1589 |
/*! |
|
1590 |
\fn void QLineEdit::returnPressed() |
|
1591 |
||
1592 |
This signal is emitted when the Return or Enter key is pressed. |
|
1593 |
Note that if there is a validator() or inputMask() set on the line |
|
1594 |
edit, the returnPressed() signal will only be emitted if the input |
|
1595 |
follows the inputMask() and the validator() returns |
|
1596 |
QValidator::Acceptable. |
|
1597 |
*/ |
|
1598 |
||
1599 |
/*! |
|
1600 |
\fn void QLineEdit::editingFinished() |
|
1601 |
||
1602 |
This signal is emitted when the Return or Enter key is pressed or |
|
1603 |
the line edit loses focus. Note that if there is a validator() or |
|
1604 |
inputMask() set on the line edit and enter/return is pressed, the |
|
1605 |
editingFinished() signal will only be emitted if the input follows |
|
1606 |
the inputMask() and the validator() returns QValidator::Acceptable. |
|
1607 |
*/ |
|
1608 |
||
1609 |
/*! |
|
1610 |
Converts the given key press \a event into a line edit action. |
|
1611 |
||
1612 |
If Return or Enter is pressed and the current text is valid (or |
|
1613 |
can be \link QValidator::fixup() made valid\endlink by the |
|
1614 |
validator), the signal returnPressed() is emitted. |
|
1615 |
||
1616 |
The default key bindings are listed in the class's detailed |
|
1617 |
description. |
|
1618 |
*/ |
|
1619 |
||
1620 |
void QLineEdit::keyPressEvent(QKeyEvent *event) |
|
1621 |
{ |
|
1622 |
Q_D(QLineEdit); |
|
1623 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1624 |
bool select = false; |
|
1625 |
switch (event->key()) { |
|
1626 |
case Qt::Key_Select: |
|
1627 |
if (QApplication::keypadNavigationEnabled()) { |
|
1628 |
if (hasEditFocus()) { |
|
1629 |
setEditFocus(false); |
|
1630 |
if (d->control->completer() && d->control->completer()->popup()->isVisible()) |
|
1631 |
d->control->completer()->popup()->hide(); |
|
1632 |
select = true; |
|
1633 |
} |
|
1634 |
} |
|
1635 |
break; |
|
1636 |
case Qt::Key_Back: |
|
1637 |
case Qt::Key_No: |
|
1638 |
if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) { |
|
1639 |
event->ignore(); |
|
1640 |
return; |
|
1641 |
} |
|
1642 |
break; |
|
1643 |
default: |
|
1644 |
if (QApplication::keypadNavigationEnabled()) { |
|
1645 |
if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) { |
|
1646 |
if (!event->text().isEmpty() && event->text().at(0).isPrint() |
|
1647 |
&& !isReadOnly()) |
|
1648 |
setEditFocus(true); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1649 |
else { |
0 | 1650 |
event->ignore(); |
1651 |
return; |
|
1652 |
} |
|
1653 |
} |
|
1654 |
} |
|
1655 |
} |
|
1656 |
||
1657 |
||
1658 |
||
1659 |
if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) { |
|
1660 |
setEditFocus(true); |
|
1661 |
if (event->key() == Qt::Key_Select) |
|
1662 |
return; // Just start. No action. |
|
1663 |
} |
|
1664 |
#endif |
|
1665 |
d->control->processKeyEvent(event); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1666 |
if (event->isAccepted()) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1667 |
if (layoutDirection() != d->control->layoutDirection()) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1668 |
setLayoutDirection(d->control->layoutDirection()); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1669 |
d->control->setCursorBlinkPeriod(0); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1670 |
} |
0 | 1671 |
} |
1672 |
||
1673 |
/*! |
|
1674 |
\since 4.4 |
|
1675 |
||
1676 |
Returns a rectangle that includes the lineedit cursor. |
|
1677 |
*/ |
|
1678 |
QRect QLineEdit::cursorRect() const |
|
1679 |
{ |
|
1680 |
Q_D(const QLineEdit); |
|
1681 |
return d->cursorRect(); |
|
1682 |
} |
|
1683 |
||
1684 |
/*! \reimp |
|
1685 |
*/ |
|
1686 |
void QLineEdit::inputMethodEvent(QInputMethodEvent *e) |
|
1687 |
{ |
|
1688 |
Q_D(QLineEdit); |
|
1689 |
if (d->control->isReadOnly()) { |
|
1690 |
e->ignore(); |
|
1691 |
return; |
|
1692 |
} |
|
1693 |
||
1694 |
if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) { |
|
1695 |
// Clear the edit and reset to normal echo mode while entering input |
|
1696 |
// method data; the echo mode switches back when the edit loses focus. |
|
1697 |
// ### changes a public property, resets current content. |
|
1698 |
d->updatePasswordEchoEditing(true); |
|
1699 |
clear(); |
|
1700 |
} |
|
1701 |
||
1702 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1703 |
// Focus in if currently in navigation focus on the widget |
|
1704 |
// Only focus in on preedits, to allow input methods to |
|
1705 |
// commit text as they focus out without interfering with focus |
|
1706 |
if (QApplication::keypadNavigationEnabled() |
|
1707 |
&& hasFocus() && !hasEditFocus() |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1708 |
&& !e->preeditString().isEmpty()) |
0 | 1709 |
setEditFocus(true); |
1710 |
#endif |
|
1711 |
||
1712 |
d->control->processInputMethodEvent(e); |
|
1713 |
||
1714 |
#ifndef QT_NO_COMPLETER |
|
1715 |
if (!e->commitString().isEmpty()) |
|
1716 |
d->control->complete(Qt::Key_unknown); |
|
1717 |
#endif |
|
1718 |
} |
|
1719 |
||
1720 |
/*!\reimp |
|
1721 |
*/ |
|
1722 |
QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const |
|
1723 |
{ |
|
1724 |
Q_D(const QLineEdit); |
|
1725 |
switch(property) { |
|
1726 |
case Qt::ImMicroFocus: |
|
1727 |
return d->cursorRect(); |
|
1728 |
case Qt::ImFont: |
|
1729 |
return font(); |
|
1730 |
case Qt::ImCursorPosition: |
|
1731 |
return QVariant(d->control->cursor()); |
|
1732 |
case Qt::ImSurroundingText: |
|
1733 |
return QVariant(text()); |
|
1734 |
case Qt::ImCurrentSelection: |
|
1735 |
return QVariant(selectedText()); |
|
1736 |
case Qt::ImMaximumTextLength: |
|
1737 |
return QVariant(maxLength()); |
|
1738 |
case Qt::ImAnchorPosition: |
|
1739 |
if (d->control->selectionStart() == d->control->selectionEnd()) |
|
1740 |
return QVariant(d->control->cursor()); |
|
1741 |
else if (d->control->selectionStart() == d->control->cursor()) |
|
1742 |
return QVariant(d->control->selectionEnd()); |
|
1743 |
else |
|
1744 |
return QVariant(d->control->selectionStart()); |
|
1745 |
default: |
|
1746 |
return QVariant(); |
|
1747 |
} |
|
1748 |
} |
|
1749 |
||
1750 |
/*!\reimp |
|
1751 |
*/ |
|
1752 |
||
1753 |
void QLineEdit::focusInEvent(QFocusEvent *e) |
|
1754 |
{ |
|
1755 |
Q_D(QLineEdit); |
|
1756 |
if (e->reason() == Qt::TabFocusReason || |
|
1757 |
e->reason() == Qt::BacktabFocusReason || |
|
1758 |
e->reason() == Qt::ShortcutFocusReason) { |
|
1759 |
if (!d->control->inputMask().isEmpty()) |
|
1760 |
d->control->moveCursor(d->control->nextMaskBlank(0)); |
|
1761 |
else if (!d->control->hasSelectedText()) |
|
1762 |
selectAll(); |
|
1763 |
} else if (e->reason() == Qt::MouseFocusReason) { |
|
1764 |
d->clickCausedFocus = 1; |
|
1765 |
} |
|
1766 |
#ifdef QT_KEYPAD_NAVIGATION |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1767 |
if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1768 |
#ifdef Q_OS_SYMBIAN |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1769 |
|| e->reason() == Qt::ActiveWindowFocusReason |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1770 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1771 |
))) { |
0 | 1772 |
#endif |
1773 |
d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
|
1774 |
QStyleOptionFrameV2 opt; |
|
1775 |
initStyleOption(&opt); |
|
1776 |
if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) |
|
1777 |
|| style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) |
|
1778 |
d->setCursorVisible(true); |
|
1779 |
#ifdef Q_WS_MAC |
|
1780 |
if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) |
|
1781 |
qt_mac_secure_keyboard(true); |
|
1782 |
#endif |
|
1783 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1784 |
d->control->setCancelText(d->control->text()); |
|
1785 |
} |
|
1786 |
#endif |
|
1787 |
#ifndef QT_NO_COMPLETER |
|
1788 |
if (d->control->completer()) { |
|
1789 |
d->control->completer()->setWidget(this); |
|
1790 |
QObject::connect(d->control->completer(), SIGNAL(activated(QString)), |
|
1791 |
this, SLOT(setText(QString))); |
|
1792 |
QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)), |
|
1793 |
this, SLOT(_q_completionHighlighted(QString))); |
|
1794 |
} |
|
1795 |
#endif |
|
1796 |
update(); |
|
1797 |
} |
|
1798 |
||
1799 |
/*!\reimp |
|
1800 |
*/ |
|
1801 |
||
1802 |
void QLineEdit::focusOutEvent(QFocusEvent *e) |
|
1803 |
{ |
|
1804 |
Q_D(QLineEdit); |
|
1805 |
if (d->control->passwordEchoEditing()) { |
|
1806 |
// Reset the echomode back to PasswordEchoOnEdit when the widget loses |
|
1807 |
// focus. |
|
1808 |
d->updatePasswordEchoEditing(false); |
|
1809 |
} |
|
1810 |
||
1811 |
Qt::FocusReason reason = e->reason(); |
|
1812 |
if (reason != Qt::ActiveWindowFocusReason && |
|
1813 |
reason != Qt::PopupFocusReason) |
|
1814 |
deselect(); |
|
1815 |
||
1816 |
d->setCursorVisible(false); |
|
1817 |
d->control->setCursorBlinkPeriod(0); |
|
1818 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1819 |
// editingFinished() is already emitted on LeaveEditFocus |
|
1820 |
if (!QApplication::keypadNavigationEnabled()) |
|
1821 |
#endif |
|
1822 |
if (reason != Qt::PopupFocusReason |
|
1823 |
|| !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) { |
|
1824 |
if (hasAcceptableInput() || d->control->fixup()) |
|
1825 |
emit editingFinished(); |
|
1826 |
#ifdef QT3_SUPPORT |
|
1827 |
emit lostFocus(); |
|
1828 |
#endif |
|
1829 |
} |
|
1830 |
#ifdef Q_WS_MAC |
|
1831 |
if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) |
|
1832 |
qt_mac_secure_keyboard(false); |
|
1833 |
#endif |
|
1834 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1835 |
d->control->setCancelText(QString()); |
|
1836 |
#endif |
|
1837 |
#ifndef QT_NO_COMPLETER |
|
1838 |
if (d->control->completer()) { |
|
1839 |
QObject::disconnect(d->control->completer(), 0, this, 0); |
|
1840 |
} |
|
1841 |
#endif |
|
1842 |
update(); |
|
1843 |
} |
|
1844 |
||
1845 |
/*!\reimp |
|
1846 |
*/ |
|
1847 |
void QLineEdit::paintEvent(QPaintEvent *) |
|
1848 |
{ |
|
1849 |
Q_D(QLineEdit); |
|
1850 |
QPainter p(this); |
|
1851 |
||
1852 |
QRect r = rect(); |
|
1853 |
QPalette pal = palette(); |
|
1854 |
||
1855 |
QStyleOptionFrameV2 panel; |
|
1856 |
initStyleOption(&panel); |
|
1857 |
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this); |
|
1858 |
r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); |
|
1859 |
r.setX(r.x() + d->leftTextMargin); |
|
1860 |
r.setY(r.y() + d->topTextMargin); |
|
1861 |
r.setRight(r.right() - d->rightTextMargin); |
|
1862 |
r.setBottom(r.bottom() - d->bottomTextMargin); |
|
1863 |
p.setClipRect(r); |
|
1864 |
||
1865 |
QFontMetrics fm = fontMetrics(); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1866 |
Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment)); |
0 | 1867 |
switch (va & Qt::AlignVertical_Mask) { |
1868 |
case Qt::AlignBottom: |
|
1869 |
d->vscroll = r.y() + r.height() - fm.height() - d->verticalMargin; |
|
1870 |
break; |
|
1871 |
case Qt::AlignTop: |
|
1872 |
d->vscroll = r.y() + d->verticalMargin; |
|
1873 |
break; |
|
1874 |
default: |
|
1875 |
//center |
|
1876 |
d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2; |
|
1877 |
break; |
|
1878 |
} |
|
1879 |
QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height()); |
|
1880 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1881 |
int minLB = qMax(0, -fm.minLeftBearing()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1882 |
int minRB = qMax(0, -fm.minRightBearing()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1883 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1884 |
if (d->control->text().isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1885 |
if (!hasFocus() && !d->placeholderText.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1886 |
QColor col = pal.text().color(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1887 |
col.setAlpha(128); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1888 |
QPen oldpen = p.pen(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1889 |
p.setPen(col); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1890 |
lineRect.adjust(minLB, 0, 0, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1891 |
QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
1892 |
p.drawText(lineRect, va, elidedText); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1893 |
p.setPen(oldpen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1894 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1895 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1896 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1897 |
|
0 | 1898 |
int cix = qRound(d->control->cursorToX()); |
1899 |
||
1900 |
// horizontal scrolling. d->hscroll is the left indent from the beginning |
|
1901 |
// of the text line to the left edge of lineRect. we update this value |
|
1902 |
// depending on the delta from the last paint event; in effect this means |
|
1903 |
// the below code handles all scrolling based on the textline (widthUsed, |
|
1904 |
// minLB, minRB), the line edit rect (lineRect) and the cursor position |
|
1905 |
// (cix). |
|
1906 |
int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; |
|
1907 |
if ((minLB + widthUsed) <= lineRect.width()) { |
|
1908 |
// text fits in lineRect; use hscroll for alignment |
|
1909 |
switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) { |
|
1910 |
case Qt::AlignRight: |
|
1911 |
d->hscroll = widthUsed - lineRect.width() + 1; |
|
1912 |
break; |
|
1913 |
case Qt::AlignHCenter: |
|
1914 |
d->hscroll = (widthUsed - lineRect.width()) / 2; |
|
1915 |
break; |
|
1916 |
default: |
|
1917 |
// Left |
|
1918 |
d->hscroll = 0; |
|
1919 |
break; |
|
1920 |
} |
|
1921 |
d->hscroll -= minLB; |
|
1922 |
} else if (cix - d->hscroll >= lineRect.width()) { |
|
1923 |
// text doesn't fit, cursor is to the right of lineRect (scroll right) |
|
1924 |
d->hscroll = cix - lineRect.width() + 1; |
|
1925 |
} else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) { |
|
1926 |
// text doesn't fit, cursor is to the left of lineRect (scroll left) |
|
1927 |
d->hscroll = cix; |
|
1928 |
} else if (widthUsed - d->hscroll < lineRect.width()) { |
|
1929 |
// text doesn't fit, text document is to the left of lineRect; align |
|
1930 |
// right |
|
1931 |
d->hscroll = widthUsed - lineRect.width() + 1; |
|
1932 |
} |
|
1933 |
// the y offset is there to keep the baseline constant in case we have script changes in the text. |
|
1934 |
QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent()); |
|
1935 |
||
1936 |
// draw text, selections and cursors |
|
1937 |
#ifndef QT_NO_STYLE_STYLESHEET |
|
1938 |
if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) { |
|
1939 |
cssStyle->styleSheetPalette(this, &panel, &pal); |
|
1940 |
} |
|
1941 |
#endif |
|
1942 |
p.setPen(pal.text().color()); |
|
1943 |
||
1944 |
int flags = QLineControl::DrawText; |
|
1945 |
||
1946 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1947 |
if (!QApplication::keypadNavigationEnabled() || hasEditFocus()) |
|
1948 |
#endif |
|
1949 |
if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){ |
|
1950 |
flags |= QLineControl::DrawSelections; |
|
1951 |
// Palette only used for selections/mask and may not be in sync |
|
1952 |
if(d->control->palette() != pal) |
|
1953 |
d->control->setPalette(pal); |
|
1954 |
} |
|
1955 |
||
1956 |
// Asian users see an IM selection text as cursor on candidate |
|
1957 |
// selection phase of input method, so the ordinary cursor should be |
|
1958 |
// invisible if we have a preedit string. |
|
1959 |
if (d->cursorVisible && !d->control->isReadOnly()) |
|
1960 |
flags |= QLineControl::DrawCursor; |
|
1961 |
||
1962 |
d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth)); |
|
1963 |
d->control->draw(&p, topLeft, r, flags); |
|
1964 |
||
1965 |
} |
|
1966 |
||
1967 |
||
1968 |
#ifndef QT_NO_DRAGANDDROP |
|
1969 |
/*!\reimp |
|
1970 |
*/ |
|
1971 |
void QLineEdit::dragMoveEvent(QDragMoveEvent *e) |
|
1972 |
{ |
|
1973 |
Q_D(QLineEdit); |
|
1974 |
if (!d->control->isReadOnly() && e->mimeData()->hasFormat(QLatin1String("text/plain"))) { |
|
1975 |
e->acceptProposedAction(); |
|
1976 |
d->control->moveCursor(d->xToPos(e->pos().x()), false); |
|
1977 |
d->cursorVisible = true; |
|
1978 |
update(); |
|
1979 |
} |
|
1980 |
} |
|
1981 |
||
1982 |
/*!\reimp */ |
|
1983 |
void QLineEdit::dragEnterEvent(QDragEnterEvent * e) |
|
1984 |
{ |
|
1985 |
QLineEdit::dragMoveEvent(e); |
|
1986 |
} |
|
1987 |
||
1988 |
/*!\reimp */ |
|
1989 |
void QLineEdit::dragLeaveEvent(QDragLeaveEvent *) |
|
1990 |
{ |
|
1991 |
Q_D(QLineEdit); |
|
1992 |
if (d->cursorVisible) { |
|
1993 |
d->cursorVisible = false; |
|
1994 |
update(); |
|
1995 |
} |
|
1996 |
} |
|
1997 |
||
1998 |
/*!\reimp */ |
|
1999 |
void QLineEdit::dropEvent(QDropEvent* e) |
|
2000 |
{ |
|
2001 |
Q_D(QLineEdit); |
|
2002 |
QString str = e->mimeData()->text(); |
|
2003 |
||
2004 |
if (!str.isNull() && !d->control->isReadOnly()) { |
|
2005 |
if (e->source() == this && e->dropAction() == Qt::CopyAction) |
|
2006 |
deselect(); |
|
2007 |
int cursorPos = d->xToPos(e->pos().x()); |
|
2008 |
int selStart = cursorPos; |
|
2009 |
int oldSelStart = d->control->selectionStart(); |
|
2010 |
int oldSelEnd = d->control->selectionEnd(); |
|
2011 |
d->control->moveCursor(cursorPos, false); |
|
2012 |
d->cursorVisible = false; |
|
2013 |
e->acceptProposedAction(); |
|
2014 |
insert(str); |
|
2015 |
if (e->source() == this) { |
|
2016 |
if (e->dropAction() == Qt::MoveAction) { |
|
2017 |
if (selStart > oldSelStart && selStart <= oldSelEnd) |
|
2018 |
setSelection(oldSelStart, str.length()); |
|
2019 |
else if (selStart > oldSelEnd) |
|
2020 |
setSelection(selStart - str.length(), str.length()); |
|
2021 |
else |
|
2022 |
setSelection(selStart, str.length()); |
|
2023 |
} else { |
|
2024 |
setSelection(selStart, str.length()); |
|
2025 |
} |
|
2026 |
} |
|
2027 |
} else { |
|
2028 |
e->ignore(); |
|
2029 |
update(); |
|
2030 |
} |
|
2031 |
} |
|
2032 |
||
2033 |
#endif // QT_NO_DRAGANDDROP |
|
2034 |
||
2035 |
#ifndef QT_NO_CONTEXTMENU |
|
2036 |
/*! |
|
2037 |
Shows the standard context menu created with |
|
2038 |
createStandardContextMenu(). |
|
2039 |
||
2040 |
If you do not want the line edit to have a context menu, you can set |
|
2041 |
its \l contextMenuPolicy to Qt::NoContextMenu. If you want to |
|
2042 |
customize the context menu, reimplement this function. If you want |
|
2043 |
to extend the standard context menu, reimplement this function, call |
|
2044 |
createStandardContextMenu() and extend the menu returned. |
|
2045 |
||
2046 |
\snippet doc/src/snippets/code/src_gui_widgets_qlineedit.cpp 0 |
|
2047 |
||
2048 |
The \a event parameter is used to obtain the position where |
|
2049 |
the mouse cursor was when the event was generated. |
|
2050 |
||
2051 |
\sa setContextMenuPolicy() |
|
2052 |
*/ |
|
2053 |
void QLineEdit::contextMenuEvent(QContextMenuEvent *event) |
|
2054 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2055 |
if (QMenu *menu = createStandardContextMenu()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2056 |
menu->setAttribute(Qt::WA_DeleteOnClose); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2057 |
menu->popup(event->globalPos()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2058 |
} |
0 | 2059 |
} |
2060 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2061 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
0 | 2062 |
extern bool qt_use_rtl_extensions; |
2063 |
#endif |
|
2064 |
||
2065 |
/*! This function creates the standard context menu which is shown |
|
2066 |
when the user clicks on the line edit with the right mouse |
|
2067 |
button. It is called from the default contextMenuEvent() handler. |
|
2068 |
The popup menu's ownership is transferred to the caller. |
|
2069 |
*/ |
|
2070 |
||
2071 |
QMenu *QLineEdit::createStandardContextMenu() |
|
2072 |
{ |
|
2073 |
Q_D(QLineEdit); |
|
2074 |
QMenu *popup = new QMenu(this); |
|
2075 |
popup->setObjectName(QLatin1String("qt_edit_menu")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2076 |
QAction *action = 0; |
0 | 2077 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2078 |
if (!isReadOnly()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2079 |
action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2080 |
action->setEnabled(d->control->isUndoAvailable()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2081 |
connect(action, SIGNAL(triggered()), SLOT(undo())); |
0 | 2082 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2083 |
action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2084 |
action->setEnabled(d->control->isRedoAvailable()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2085 |
connect(action, SIGNAL(triggered()), SLOT(redo())); |
0 | 2086 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2087 |
popup->addSeparator(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2088 |
} |
0 | 2089 |
|
2090 |
#ifndef QT_NO_CLIPBOARD |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2091 |
if (!isReadOnly()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2092 |
action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2093 |
action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2094 |
&& d->control->echoMode() == QLineEdit::Normal); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2095 |
connect(action, SIGNAL(triggered()), SLOT(cut())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2096 |
} |
0 | 2097 |
|
2098 |
action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy)); |
|
2099 |
action->setEnabled(d->control->hasSelectedText() |
|
2100 |
&& d->control->echoMode() == QLineEdit::Normal); |
|
2101 |
connect(action, SIGNAL(triggered()), SLOT(copy())); |
|
2102 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2103 |
if (!isReadOnly()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2104 |
action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2105 |
action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2106 |
connect(action, SIGNAL(triggered()), SLOT(paste())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2107 |
} |
0 | 2108 |
#endif |
2109 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2110 |
if (!isReadOnly()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2111 |
action = popup->addAction(QLineEdit::tr("Delete")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2112 |
action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2113 |
connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2114 |
} |
0 | 2115 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2116 |
if (!popup->isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2117 |
popup->addSeparator(); |
0 | 2118 |
|
2119 |
action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll)); |
|
2120 |
action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected()); |
|
2121 |
d->selectAllAction = action; |
|
2122 |
connect(action, SIGNAL(triggered()), SLOT(selectAll())); |
|
2123 |
||
2124 |
#if !defined(QT_NO_IM) |
|
2125 |
QInputContext *qic = inputContext(); |
|
2126 |
if (qic) { |
|
2127 |
QList<QAction *> imActions = qic->actions(); |
|
2128 |
for (int i = 0; i < imActions.size(); ++i) |
|
2129 |
popup->addAction(imActions.at(i)); |
|
2130 |
} |
|
2131 |
#endif |
|
2132 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
2133 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
0 | 2134 |
if (!d->control->isReadOnly() && qt_use_rtl_extensions) { |
2135 |
#else |
|
2136 |
if (!d->control->isReadOnly()) { |
|
2137 |
#endif |
|
2138 |
popup->addSeparator(); |
|
2139 |
QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup); |
|
2140 |
popup->addMenu(ctrlCharacterMenu); |
|
2141 |
} |
|
2142 |
return popup; |
|
2143 |
} |
|
2144 |
#endif // QT_NO_CONTEXTMENU |
|
2145 |
||
2146 |
/*! \reimp */ |
|
2147 |
void QLineEdit::changeEvent(QEvent *ev) |
|
2148 |
{ |
|
2149 |
Q_D(QLineEdit); |
|
2150 |
switch(ev->type()) |
|
2151 |
{ |
|
2152 |
case QEvent::ActivationChange: |
|
2153 |
if (!palette().isEqual(QPalette::Active, QPalette::Inactive)) |
|
2154 |
update(); |
|
2155 |
break; |
|
2156 |
case QEvent::FontChange: |
|
2157 |
d->control->setFont(font()); |
|
2158 |
break; |
|
2159 |
case QEvent::StyleChange: |
|
2160 |
{ |
|
2161 |
QStyleOptionFrameV2 opt; |
|
2162 |
initStyleOption(&opt); |
|
2163 |
d->control->setPasswordCharacter(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)); |
|
2164 |
} |
|
2165 |
update(); |
|
2166 |
break; |
|
2167 |
default: |
|
2168 |
break; |
|
2169 |
} |
|
2170 |
QWidget::changeEvent(ev); |
|
2171 |
} |
|
2172 |
||
2173 |
/*! |
|
2174 |
\fn void QLineEdit::repaintArea(int a, int b) |
|
2175 |
||
2176 |
Use update() instead. |
|
2177 |
*/ |
|
2178 |
||
2179 |
/*! |
|
2180 |
\fn void QLineEdit::cursorLeft(bool mark, int steps) |
|
2181 |
||
2182 |
Use cursorForward() with a negative number of steps instead. For |
|
2183 |
example, cursorForward(mark, -steps). |
|
2184 |
*/ |
|
2185 |
||
2186 |
/*! |
|
2187 |
\fn void QLineEdit::cursorRight(bool mark, int steps) |
|
2188 |
||
2189 |
Use cursorForward() instead. |
|
2190 |
*/ |
|
2191 |
||
2192 |
/*! |
|
2193 |
\fn bool QLineEdit::frame() const |
|
2194 |
||
2195 |
Use hasFrame() instead. |
|
2196 |
*/ |
|
2197 |
||
2198 |
/*! |
|
2199 |
\fn void QLineEdit::clearValidator() |
|
2200 |
||
2201 |
Use setValidator(0) instead. |
|
2202 |
*/ |
|
2203 |
||
2204 |
/*! |
|
2205 |
\fn bool QLineEdit::hasMarkedText() const |
|
2206 |
||
2207 |
Use hasSelectedText() instead. |
|
2208 |
*/ |
|
2209 |
||
2210 |
/*! |
|
2211 |
\fn QString QLineEdit::markedText() const |
|
2212 |
||
2213 |
Use selectedText() instead. |
|
2214 |
*/ |
|
2215 |
||
2216 |
/*! |
|
2217 |
\fn void QLineEdit::setFrameRect(QRect) |
|
2218 |
\internal |
|
2219 |
*/ |
|
2220 |
||
2221 |
/*! |
|
2222 |
\fn QRect QLineEdit::frameRect() const |
|
2223 |
\internal |
|
2224 |
*/ |
|
2225 |
/*! |
|
2226 |
\enum QLineEdit::DummyFrame |
|
2227 |
\internal |
|
2228 |
||
2229 |
\value Box |
|
2230 |
\value Sunken |
|
2231 |
\value Plain |
|
2232 |
\value Raised |
|
2233 |
\value MShadow |
|
2234 |
\value NoFrame |
|
2235 |
\value Panel |
|
2236 |
\value StyledPanel |
|
2237 |
\value HLine |
|
2238 |
\value VLine |
|
2239 |
\value GroupBoxPanel |
|
2240 |
\value WinPanel |
|
2241 |
\value ToolBarPanel |
|
2242 |
\value MenuBarPanel |
|
2243 |
\value PopupPanel |
|
2244 |
\value LineEditPanel |
|
2245 |
\value TabWidgetPanel |
|
2246 |
\value MShape |
|
2247 |
*/ |
|
2248 |
||
2249 |
/*! |
|
2250 |
\fn void QLineEdit::setFrameShadow(DummyFrame) |
|
2251 |
\internal |
|
2252 |
*/ |
|
2253 |
||
2254 |
/*! |
|
2255 |
\fn DummyFrame QLineEdit::frameShadow() const |
|
2256 |
\internal |
|
2257 |
*/ |
|
2258 |
||
2259 |
/*! |
|
2260 |
\fn void QLineEdit::setFrameShape(DummyFrame) |
|
2261 |
\internal |
|
2262 |
*/ |
|
2263 |
||
2264 |
/*! |
|
2265 |
\fn DummyFrame QLineEdit::frameShape() const |
|
2266 |
\internal |
|
2267 |
*/ |
|
2268 |
||
2269 |
/*! |
|
2270 |
\fn void QLineEdit::setFrameStyle(int) |
|
2271 |
\internal |
|
2272 |
*/ |
|
2273 |
||
2274 |
/*! |
|
2275 |
\fn int QLineEdit::frameStyle() const |
|
2276 |
\internal |
|
2277 |
*/ |
|
2278 |
||
2279 |
/*! |
|
2280 |
\fn int QLineEdit::frameWidth() const |
|
2281 |
\internal |
|
2282 |
*/ |
|
2283 |
||
2284 |
/*! |
|
2285 |
\fn void QLineEdit::setLineWidth(int) |
|
2286 |
\internal |
|
2287 |
*/ |
|
2288 |
||
2289 |
/*! |
|
2290 |
\fn int QLineEdit::lineWidth() const |
|
2291 |
\internal |
|
2292 |
*/ |
|
2293 |
||
2294 |
/*! |
|
2295 |
\fn void QLineEdit::setMargin(int margin) |
|
2296 |
Sets the width of the margin around the contents of the widget to \a margin. |
|
2297 |
||
2298 |
Use QWidget::setContentsMargins() instead. |
|
2299 |
\sa margin(), QWidget::setContentsMargins() |
|
2300 |
*/ |
|
2301 |
||
2302 |
/*! |
|
2303 |
\fn int QLineEdit::margin() const |
|
2304 |
Returns the width of the margin around the contents of the widget. |
|
2305 |
||
2306 |
Use QWidget::getContentsMargins() instead. |
|
2307 |
\sa setMargin(), QWidget::getContentsMargins() |
|
2308 |
*/ |
|
2309 |
||
2310 |
/*! |
|
2311 |
\fn void QLineEdit::setMidLineWidth(int) |
|
2312 |
\internal |
|
2313 |
*/ |
|
2314 |
||
2315 |
/*! |
|
2316 |
\fn int QLineEdit::midLineWidth() const |
|
2317 |
\internal |
|
2318 |
*/ |
|
2319 |
||
2320 |
QT_END_NAMESPACE |
|
2321 |
||
2322 |
#include "moc_qlineedit.cpp" |
|
2323 |
||
2324 |
#endif // QT_NO_LINEEDIT |