source: trunk/src/gui/widgets/qlineedit.cpp@ 1054

Last change on this file since 1054 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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