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