| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qlineedit_p.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | const int QLineEditPrivate::verticalMargin(1); | - | ||||||||||||
| 12 | const int QLineEditPrivate::horizontalMargin(2); | - | ||||||||||||
| 13 | - | |||||||||||||
| 14 | QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const | - | ||||||||||||
| 15 | { | - | ||||||||||||
| 16 | QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect(); | - | ||||||||||||
| 17 | QRect cr = adjustedContentsRect(); | - | ||||||||||||
| 18 | int cix = cr.x() - hscroll + horizontalMargin; | - | ||||||||||||
| 19 | return widgetRect.translated(QPoint(cix, vscroll)); | - | ||||||||||||
| 20 | } | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const | - | ||||||||||||
| 23 | { | - | ||||||||||||
| 24 | QRect cr = adjustedContentsRect(); | - | ||||||||||||
| 25 | x-= cr.x() - hscroll + horizontalMargin; | - | ||||||||||||
| 26 | return control->xToPos(x, betweenOrOn); | - | ||||||||||||
| 27 | } | - | ||||||||||||
| 28 | - | |||||||||||||
| 29 | bool QLineEditPrivate::inSelection(int x) const | - | ||||||||||||
| 30 | { | - | ||||||||||||
| 31 | x -= adjustedContentsRect().x() - hscroll + horizontalMargin; | - | ||||||||||||
| 32 | return control->inSelection(x); | - | ||||||||||||
| 33 | } | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | QRect QLineEditPrivate::cursorRect() const | - | ||||||||||||
| 36 | { | - | ||||||||||||
| 37 | return adjustedControlRect(control->cursorRect()); | - | ||||||||||||
| 38 | } | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | - | |||||||||||||
| 41 | - | |||||||||||||
| 42 | void QLineEditPrivate::_q_completionHighlighted(const QString &newText) | - | ||||||||||||
| 43 | { | - | ||||||||||||
| 44 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 45 |     if (control->completer()->completionMode() != QCompleter::InlineCompletion
  | 0 | ||||||||||||
| 46 | q->setText(newText); | - | ||||||||||||
| 47 |     } never executed:   else {end of block | 0 | ||||||||||||
| 48 | int c = control->cursor(); | - | ||||||||||||
| 49 | QString text = control->text(); | - | ||||||||||||
| 50 | q->setText(text.leftleftRef(c) + newText.midmidRef(c)); | - | ||||||||||||
| 51 | control->moveCursor(control->end(), false); | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | const bool mark = true; | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | - | |||||||||||||
| 56 | - | |||||||||||||
| 57 | control->moveCursor(c, mark); | - | ||||||||||||
| 58 |     } never executed:  end of block | 0 | ||||||||||||
| 59 | } | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | void QLineEditPrivate::_q_handleWindowActivate() | - | ||||||||||||
| 64 | { | - | ||||||||||||
| 65 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 66 | if (!q->hasFocus() && control->hasSelectedText()) | - | ||||||||||||
| 67 | control->deselect(); | - | ||||||||||||
| 68 | } | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | void QLineEditPrivate::_q_textEdited(const QString &text) | - | ||||||||||||
| 71 | { | - | ||||||||||||
| 72 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 73 | q->textEdited(text); | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | if (control->completer() | - | ||||||||||||
| 76 | && control->completer()->completionMode() != QCompleter::InlineCompletion) | - | ||||||||||||
| 77 | control->complete(-1); | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | void QLineEditPrivate::_q_cursorPositionChanged(int from, int to) | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 84 | q->update(); | - | ||||||||||||
| 85 | q->cursorPositionChanged(from, to); | - | ||||||||||||
| 86 | } | - | ||||||||||||
| 87 | void QLineEditPrivate::_q_selectionChanged() | - | ||||||||||||
| 88 | { | - | ||||||||||||
| 89 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 90 | if (control->preeditAreaText().isEmpty()) { | - | ||||||||||||
| 91 | QStyleOptionFrame opt; | - | ||||||||||||
| 92 | q->initStyleOption(&opt); | - | ||||||||||||
| 93 | bool showCursor = control->hasSelectedText() ? | - | ||||||||||||
| 94 | q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q): | - | ||||||||||||
| 95 | q->hasFocus(); | - | ||||||||||||
| 96 | setCursorVisible(showCursor); | - | ||||||||||||
| 97 | } | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | q->selectionChanged(); | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | QAccessibleTextSelectionEvent ev(q, control->selectionStart(), control->selectionEnd()); | - | ||||||||||||
| 102 | ev.setCursorPosition(control->cursorPosition()); | - | ||||||||||||
| 103 | QAccessible::updateAccessibility(&ev); | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | } | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | void QLineEditPrivate::_q_updateNeeded(const QRect &rect) | - | ||||||||||||
| 108 | { | - | ||||||||||||
| 109 | q_func()->update(adjustedControlRect(rect)); | - | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | void QLineEditPrivate::init(const QString& txt) | - | ||||||||||||
| 113 | { | - | ||||||||||||
| 114 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 115 | control = new QWidgetLineControl(txt); | - | ||||||||||||
| 116 | control->setParent(q); | - | ||||||||||||
| 117 | control->setFont(q->font()); | - | ||||||||||||
| 118 | QObject::connect(control, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "171""177"), | - | ||||||||||||
| 119 | q, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "172""178")); | - | ||||||||||||
| 120 | QObject::connect(control, qFlagLocation("2""textEdited(QString)" "\0" __FILE__ ":" "173""179"), | - | ||||||||||||
| 121 | q, qFlagLocation("1""_q_textEdited(QString)" "\0" __FILE__ ":" "174""180")); | - | ||||||||||||
| 122 | QObject::connect(control, qFlagLocation("2""cursorPositionChanged(int,int)" "\0" __FILE__ ":" "175""181"), | - | ||||||||||||
| 123 | q, qFlagLocation("1""_q_cursorPositionChanged(int,int)" "\0" __FILE__ ":" "176""182")); | - | ||||||||||||
| 124 | QObject::connect(control, qFlagLocation("2""selectionChanged()" "\0" __FILE__ ":" "177""183"), | - | ||||||||||||
| 125 | q, qFlagLocation("1""_q_selectionChanged()" "\0" __FILE__ ":" "178""184")); | - | ||||||||||||
| 126 | QObject::connect(control, qFlagLocation("2""accepted()" "\0" __FILE__ ":" "179""185"), | - | ||||||||||||
| 127 | q, qFlagLocation("2""returnPressed()" "\0" __FILE__ ":" "180""186")); | - | ||||||||||||
| 128 | QObject::connect(control, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "181""187"), | - | ||||||||||||
| 129 | q, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "182""188")); | - | ||||||||||||
| 130 | - | |||||||||||||
| 131 | - | |||||||||||||
| 132 | - | |||||||||||||
| 133 | - | |||||||||||||
| 134 | QObject::connect(control, qFlagLocation("2""cursorPositionChanged(int,int)" "\0" __FILE__ ":" "187""193"), | - | ||||||||||||
| 135 | q, qFlagLocation("1""updateMicroFocus()" "\0" __FILE__ ":" "188""194")); | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | QObject::connect(control, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "190""196"), | - | ||||||||||||
| 138 | q, qFlagLocation("1""updateMicroFocus()" "\0" __FILE__ ":" "191""197")); | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | - | |||||||||||||
| 141 | QObject::connect(control, qFlagLocation("2""selectionChanged()" "\0" __FILE__ ":" "194""200"), | - | ||||||||||||
| 142 | q, qFlagLocation("1""update()" "\0" __FILE__ ":" "195""201")); | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | QObject::connect(control, qFlagLocation("2""selectionChanged()" "\0" __FILE__ ":" "197""203"), | - | ||||||||||||
| 145 | q, qFlagLocation("1""updateMicroFocus()" "\0" __FILE__ ":" "198""204")); | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | QObject::connect(control, qFlagLocation("2""displayTextChanged(QString)" "\0" __FILE__ ":" "200""206"), | - | ||||||||||||
| 148 | q, qFlagLocation("1""update()" "\0" __FILE__ ":" "201""207")); | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | QObject::connect(control, qFlagLocation("2""updateNeeded(QRect)" "\0" __FILE__ ":" "203""209"), | - | ||||||||||||
| 151 | q, qFlagLocation("1""_q_updateNeeded(QRect)" "\0" __FILE__ ":" "204""210")); | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | QStyleOptionFrame opt; | - | ||||||||||||
| 154 | q->initStyleOption(&opt); | - | ||||||||||||
| 155 | control->setPasswordCharacter(q->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, q)); | - | ||||||||||||
| 156 | control->setPasswordMaskDelay(q->style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, q)); | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | q->setCursor(Qt::IBeamCursor); | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | q->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||
| 161 | q->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | - | |||||||||||||
| 164 | q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit)); | - | ||||||||||||
| 165 | q->setBackgroundRole(QPalette::Base); | - | ||||||||||||
| 166 | q->setAttribute(Qt::WA_KeyCompression); | - | ||||||||||||
| 167 | q->setMouseTracking(true); | - | ||||||||||||
| 168 | q->setAcceptDrops(true); | - | ||||||||||||
| 169 | - | |||||||||||||
| 170 | q->setAttribute(Qt::WA_MacShowFocusRect); | - | ||||||||||||
| 171 | } | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | QRect QLineEditPrivate::adjustedContentsRect() const | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | const QLineEdit * const q = q_func(); | - | ||||||||||||
| 176 | QStyleOptionFrame opt; | - | ||||||||||||
| 177 | q->initStyleOption(&opt); | - | ||||||||||||
| 178 | QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q); | - | ||||||||||||
| 179 | r.setX(r.x() + effectiveLeftTextMargin()); | - | ||||||||||||
| 180 | r.setY(r.y() + topTextMargin); | - | ||||||||||||
| 181 | r.setRight(r.right() - effectiveRightTextMargin()); | - | ||||||||||||
| 182 | r.setBottom(r.bottom() - bottomTextMargin); | - | ||||||||||||
| 183 | return r; | - | ||||||||||||
| 184 | } | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | void QLineEditPrivate::setCursorVisible(bool visible) | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 189 | if ((bool)cursorVisible == visible) | - | ||||||||||||
| 190 | return; | - | ||||||||||||
| 191 | cursorVisible = visible; | - | ||||||||||||
| 192 | if (control->inputMask().isEmpty()) | - | ||||||||||||
| 193 | q->update(cursorRect()); | - | ||||||||||||
| 194 | else | - | ||||||||||||
| 195 | q->update(); | - | ||||||||||||
| 196 | } | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | void QLineEditPrivate::updatePasswordEchoEditing(bool editing) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 201 | control->updatePasswordEchoEditing(editing); | - | ||||||||||||
| 202 | q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod()); | - | ||||||||||||
| 203 | } | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | void QLineEditPrivate::resetInputMethod() | - | ||||||||||||
| 206 | { | - | ||||||||||||
| 207 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 208 | if (q->hasFocus() && (static_cast<QApplication *>(QCoreApplication::instance()))) { | - | ||||||||||||
| 209 | QGuiApplication::inputMethod()->reset(); | - | ||||||||||||
| 210 | } | - | ||||||||||||
| 211 | } | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | - | |||||||||||||
| 214 | - | |||||||||||||
| 215 | - | |||||||||||||
| 216 | - | |||||||||||||
| 217 | - | |||||||||||||
| 218 | bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e ) | - | ||||||||||||
| 219 | { | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | if ( control->composeMode() ) { | - | ||||||||||||
| 222 | int tmp_cursor = xToPos(e->pos().x()); | - | ||||||||||||
| 223 | int mousePos = tmp_cursor - control->cursor(); | - | ||||||||||||
| 224 | if ( mousePos < 0 || mousePos > control->preeditAreaText().length() ) | - | ||||||||||||
| 225 | mousePos = -1; | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | if (mousePos >= 0) { | - | ||||||||||||
| 228 | if (e->type() == QEvent::MouseButtonRelease) | - | ||||||||||||
| 229 | QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, mousePos); | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | return true; | - | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | } | - | ||||||||||||
| 234 | - | |||||||||||||
| 235 | - | |||||||||||||
| 236 | - | |||||||||||||
| 237 | - | |||||||||||||
| 238 | return false; | - | ||||||||||||
| 239 | } | - | ||||||||||||
| 240 | - | |||||||||||||
| 241 | - | |||||||||||||
| 242 | void QLineEditPrivate::drag() | - | ||||||||||||
| 243 | { | - | ||||||||||||
| 244 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 245 | dndTimer.stop(); | - | ||||||||||||
| 246 | QMimeData *data = new QMimeData; | - | ||||||||||||
| 247 | data->setText(control->selectedText()); | - | ||||||||||||
| 248 | QDrag *drag = new QDrag(q); | - | ||||||||||||
| 249 | drag->setMimeData(data); | - | ||||||||||||
| 250 | Qt::DropAction action = drag->start(); | - | ||||||||||||
| 251 | if (action == Qt::MoveAction && !control->isReadOnly() && drag->target() != q) | - | ||||||||||||
| 252 | control->removeSelection(); | - | ||||||||||||
| 253 | } | - | ||||||||||||
| 254 | - | |||||||||||||
| 255 | - | |||||||||||||
| 256 | - | |||||||||||||
| 257 | QLineEditIconButton::QLineEditIconButton(QWidget *parent) | - | ||||||||||||
| 258 | : QToolButton(parent) | - | ||||||||||||
| 259 | , m_opacity(0) | - | ||||||||||||
| 260 | { | - | ||||||||||||
| 261 | setFocusPolicy(Qt::NoFocus); | - | ||||||||||||
| 262 | } | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | QLineEditPrivate *QLineEditIconButton::lineEditPrivate() const | - | ||||||||||||
| 265 | { | - | ||||||||||||
| 266 | QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget()); | - | ||||||||||||
| 267 | return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : nullptr; | - | ||||||||||||
| 268 | } | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | void QLineEditIconButton::paintEvent(QPaintEvent *) | - | ||||||||||||
| 271 | { | - | ||||||||||||
| 272 | QPainter painter(this); | - | ||||||||||||
| 273 | QWindow *window = nullptr; | - | ||||||||||||
| 274 | if (const QWidget *nativeParent = nativeParentWidget()) | - | ||||||||||||
| 275 | window = nativeParent->windowHandle(); | - | ||||||||||||
| 276 | - | |||||||||||||
| 277 | - | |||||||||||||
| 278 | QIcon::Mode state = QIcon::Disabled; | - | ||||||||||||
| 279 | if (isEnabled()) | - | ||||||||||||
| 280 | state = isDown() ? QIcon::Selected : QIcon::Normal; | - | ||||||||||||
| 281 | const QLineEditPrivate *lep = lineEditPrivate(); | - | ||||||||||||
| 282 | const int iconWidth = lep ? lep->sideWidgetParameters().iconSize : 16; | - | ||||||||||||
| 283 | const QSize iconSize(iconWidth, iconWidth); | - | ||||||||||||
| 284 | const QPixmap iconPixmap = icon().pixmap(window, iconSize, state, QIcon::Off); | - | ||||||||||||
| 285 | QRect pixmapRect = QRect(QPoint(0, 0), iconSize); | - | ||||||||||||
| 286 | pixmapRect.moveCenter(rect().center()); | - | ||||||||||||
| 287 | painter.setOpacity(m_opacity); | - | ||||||||||||
| 288 | painter.drawPixmap(pixmapRect, iconPixmap); | - | ||||||||||||
| 289 | } | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | void QLineEditIconButton::actionEvent(QActionEvent *e) | - | ||||||||||||
| 292 | { | - | ||||||||||||
| 293 | switch (e->type()) { | - | ||||||||||||
| 294 | case QEvent::ActionChanged: { | - | ||||||||||||
| 295 | const QAction *action = e->action(); | - | ||||||||||||
| 296 | if (isVisibleTo(parentWidget()) != action->isVisible()) { | - | ||||||||||||
| 297 | setVisible(action->isVisible()); | - | ||||||||||||
| 298 | if (QLineEditPrivate *lep = lineEditPrivate()) | - | ||||||||||||
| 299 | lep->positionSideWidgets(); | - | ||||||||||||
| 300 | } | - | ||||||||||||
| 301 | } | - | ||||||||||||
| 302 | break; | - | ||||||||||||
| 303 | default: | - | ||||||||||||
| 304 | break; | - | ||||||||||||
| 305 | } | - | ||||||||||||
| 306 | QToolButton::actionEvent(e); | - | ||||||||||||
| 307 | } | - | ||||||||||||
| 308 | - | |||||||||||||
| 309 | void QLineEditIconButton::setOpacity(qreal value) | - | ||||||||||||
| 310 | { | - | ||||||||||||
| 311 | if (!qFuzzyCompare(m_opacity, value)) { | - | ||||||||||||
| 312 | m_opacity = value; | - | ||||||||||||
| 313 | updateCursor(); | - | ||||||||||||
| 314 | update(); | - | ||||||||||||
| 315 | } | - | ||||||||||||
| 316 | } | - | ||||||||||||
| 317 | - | |||||||||||||
| 318 | - | |||||||||||||
| 319 | void QLineEditIconButton::startOpacityAnimation(qreal endValue) | - | ||||||||||||
| 320 | { | - | ||||||||||||
| 321 | QPropertyAnimation *animation = new QPropertyAnimation(this, ([]() -> QByteArray { enum { Size = sizeof("opacity") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "opacity" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())); | - | ||||||||||||
| 322 | animation->setDuration(160); | - | ||||||||||||
| 323 | animation->setEndValue(endValue); | - | ||||||||||||
| 324 | animation->start(QAbstractAnimation::DeleteWhenStopped); | - | ||||||||||||
| 325 | } | - | ||||||||||||
| 326 | - | |||||||||||||
| 327 | - | |||||||||||||
| 328 | void QLineEditIconButton::updateCursor() | - | ||||||||||||
| 329 | { | - | ||||||||||||
| 330 | - | |||||||||||||
| 331 | setCursor(qFuzzyCompare(m_opacity, qreal(1.0)) || !parentWidget() ? QCursor(Qt::ArrowCursor) : parentWidget()->cursor()); | - | ||||||||||||
| 332 | - | |||||||||||||
| 333 | } | - | ||||||||||||
| 334 | - | |||||||||||||
| 335 | void QLineEditPrivate::_q_textChanged(const QString &text) | - | ||||||||||||
| 336 | { | - | ||||||||||||
| 337 |     if (hasSideWidgets()
  | 0 | ||||||||||||
| 338 | const int newTextSize = text.size(); | - | ||||||||||||
| 339 |         if (!newTextSize
 
  | 0 | ||||||||||||
| 340 | lastTextSize = newTextSize; | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | const bool fadeIn = newTextSize > 0; | - | ||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(leadingSideWidgets)>::type> _container_((leadingSideWidgets)); _container_.control && _container_.i != _container_.e; | ||||||||||||||
| 343 | ++_container_.i, _container_.control ^= 1)for (const SideWidgetEntry &e = *_container_.i; _container_.control; _container_.control = 0: leadingSideWidgets) { | - | ||||||||||||
| 344 |                 if (e.flags & SideWidgetFadeInWithText
  | 0 | ||||||||||||
| 345 |                    static_cast< never executed:  QLineEditIconButton *>(e.widget)->animateShow(fadeIn);static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn);never executed:  static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn); | 0 | ||||||||||||
| 346 |             } never executed:  end of block | 0 | ||||||||||||
| 347 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(trailingSideWidgets)>::type> _container_((trailingSideWidgets)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const SideWidgetEntry &e = *_container_.i; _container_.control; _container_.control = 0: trailingSideWidgets) { | - | ||||||||||||
| 348 |                 if (e.flags & SideWidgetFadeInWithText
  | 0 | ||||||||||||
| 349 |                    static_cast< never executed:  QLineEditIconButton *>(e.widget)->animateShow(fadeIn);static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn);never executed:  static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn); | 0 | ||||||||||||
| 350 |             } never executed:  end of block | 0 | ||||||||||||
| 351 | - | |||||||||||||
| 352 |         } never executed:  end of block | 0 | ||||||||||||
| 353 |     } never executed:  end of block | 0 | ||||||||||||
| 354 | } never executed:  end of block | 0 | ||||||||||||
| 355 | - | |||||||||||||
| 356 | void QLineEditPrivate::_q_clearButtonClicked() | - | ||||||||||||
| 357 | { | - | ||||||||||||
| 358 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 359 | if (!q->text().isEmpty()) { | - | ||||||||||||
| 360 | q->clear(); | - | ||||||||||||
| 361 | q->textEdited(QString()); | - | ||||||||||||
| 362 | } | - | ||||||||||||
| 363 | } | - | ||||||||||||
| 364 | - | |||||||||||||
| 365 | QLineEditPrivate::SideWidgetParameters QLineEditPrivate::sideWidgetParameters() const | - | ||||||||||||
| 366 | { | - | ||||||||||||
| 367 | const QLineEdit * const q = q_func(); | - | ||||||||||||
| 368 | SideWidgetParameters result; | - | ||||||||||||
| 369 | result.iconSize = q->height() < 34 ? 16 : 32; | - | ||||||||||||
| 370 | result.margin = result.iconSize / 4; | - | ||||||||||||
| 371 | result.widgetWidth = result.iconSize + 6; | - | ||||||||||||
| 372 | result.widgetHeight = result.iconSize + 2; | - | ||||||||||||
| 373 | return result; | - | ||||||||||||
| 374 | } | - | ||||||||||||
| 375 | - | |||||||||||||
| 376 | QIcon QLineEditPrivate::clearButtonIcon() const | - | ||||||||||||
| 377 | { | - | ||||||||||||
| 378 | const QLineEdit * const q = q_func(); | - | ||||||||||||
| 379 | QStyleOptionFrame styleOption; | - | ||||||||||||
| 380 | q->initStyleOption(&styleOption); | - | ||||||||||||
| 381 | return q->style()->standardIcon(QStyle::SP_LineEditClearButton, &styleOption, q); | - | ||||||||||||
| 382 | } | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | void QLineEditPrivate::setClearButtonEnabled(bool enabled) | - | ||||||||||||
| 385 | { | - | ||||||||||||
| 386 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(trailingSideWidgets)>::type> _container_((trailingSideWidgets)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const SideWidgetEntry &e = *_container_.i; _container_.control; _container_.control = 0: trailingSideWidgets) { | - | ||||||||||||
| 387 |         if (e.flags & SideWidgetClearButton
  | 0 | ||||||||||||
| 388 | e.action->setEnabled(enabled); | - | ||||||||||||
| 389 |             break; never executed:  break; | 0 | ||||||||||||
| 390 | } | - | ||||||||||||
| 391 |     } never executed:  end of block | 0 | ||||||||||||
| 392 | } never executed:  end of block | 0 | ||||||||||||
| 393 | - | |||||||||||||
| 394 | void QLineEditPrivate::positionSideWidgets() | - | ||||||||||||
| 395 | { | - | ||||||||||||
| 396 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 397 |     if (hasSideWidgets()
  | 0 | ||||||||||||
| 398 | const QRect contentRect = q->rect(); | - | ||||||||||||
| 399 | const SideWidgetParameters p = sideWidgetParameters(); | - | ||||||||||||
| 400 | const int delta = p.margin + p.widgetWidth; | - | ||||||||||||
| 401 | QRect widgetGeometry(QPoint(p.margin, (contentRect.height() - p.widgetHeight) / 2), | - | ||||||||||||
| 402 | QSize(p.widgetWidth, p.widgetHeight)); | - | ||||||||||||
| 403 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(leftSideWidgetList())>::type> _container_((leftSideWidgetList())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const SideWidgetEntry &e = *_container_.i; _container_.control; _container_.control = 0): leftSideWidgetList()) { | - | ||||||||||||
| 404 | e.widget->setGeometry(widgetGeometry); | - | ||||||||||||
| 405 |             if (e.action->isVisible()
  | 0 | ||||||||||||
| 406 |                 widgetGeometry.moveLeft(widgetGeometry.left() + delta); never executed:  widgetGeometry.moveLeft(widgetGeometry.left() + delta); | 0 | ||||||||||||
| 407 |         } never executed:  end of block | 0 | ||||||||||||
| 408 | widgetGeometry.moveLeft(contentRect.width() - p.widgetWidth - p.margin); | - | ||||||||||||
| 409 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(rightSideWidgetList())>::type> _container_((rightSideWidgetList())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const SideWidgetEntry &e = *_container_.i; _container_.control; _container_.control = 0): rightSideWidgetList()) { | - | ||||||||||||
| 410 | e.widget->setGeometry(widgetGeometry); | - | ||||||||||||
| 411 |             if (e.action->isVisible()
  | 0 | ||||||||||||
| 412 |                 widgetGeometry.moveLeft(widgetGeometry.left() - delta); never executed:  widgetGeometry.moveLeft(widgetGeometry.left() - delta); | 0 | ||||||||||||
| 413 |         } never executed:  end of block | 0 | ||||||||||||
| 414 |     } never executed:  end of block | 0 | ||||||||||||
| 415 | } never executed:  end of block | 0 | ||||||||||||
| 416 | - | |||||||||||||
| 417 | QLineEditPrivate::PositionIndexPair QLineEditPrivate::findSideWidget(const QAction *a) const | - | ||||||||||||
| 418 | { | - | ||||||||||||
| 419 | for (int i = 0; | - | ||||||||||||
| 420 | i <for (const auto &e : leadingSideWidgets.size(); ++i) { | - | ||||||||||||
| 421 |         if (a == leadingSideWidgetse.at(i).action
  | 0 | ||||||||||||
| 422 |             return never executed:   PositionIndexPair(QLineEdit::LeadingPosition, i);return PositionIndexPair(QLineEdit::LeadingPosition, i);never executed:  return PositionIndexPair(QLineEdit::LeadingPosition, i); | 0 | ||||||||||||
| 423 | ++i; | - | ||||||||||||
| 424 |     } never executed:  end of block | 0 | ||||||||||||
| 425 | for (inti = 0; | - | ||||||||||||
| 426 | i <for (const auto &e : trailingSideWidgets.size(); ++i) { | - | ||||||||||||
| 427 |         if (a == trailingSideWidgetse.at(i).action
  | 0 | ||||||||||||
| 428 |             return never executed:   PositionIndexPair(QLineEdit::TrailingPosition, i);return PositionIndexPair(QLineEdit::TrailingPosition, i);never executed:  return PositionIndexPair(QLineEdit::TrailingPosition, i); | 0 | ||||||||||||
| 429 | ++i; | - | ||||||||||||
| 430 |     } never executed:  end of block | 0 | ||||||||||||
| 431 |     return never executed:   PositionIndexPair(QLineEdit::LeadingPosition, -1);return PositionIndexPair(QLineEdit::LeadingPosition, -1);never executed:  return PositionIndexPair(QLineEdit::LeadingPosition, -1); | 0 | ||||||||||||
| 432 | } | - | ||||||||||||
| 433 | - | |||||||||||||
| 434 | QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition position, int flags) | - | ||||||||||||
| 435 | { | - | ||||||||||||
| 436 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 437 |     if (!newAction
  | 0 | ||||||||||||
| 438 |         return never executed:   0;return 0;never executed:  return 0; | 0 | ||||||||||||
| 439 |     if (!hasSideWidgets()
  | 0 | ||||||||||||
| 440 | QObject::connect(q, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "489""499"), q, qFlagLocation("1""_q_textChanged(QString)" "\0" __FILE__ ":" "489""499")); | - | ||||||||||||
| 441 | lastTextSize = q->text().size(); | - | ||||||||||||
| 442 |     } never executed:  end of block | 0 | ||||||||||||
| 443 | QWidget *w = 0; | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | - | |||||||||||||
| 446 |     if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(newAction)
  | 0 | ||||||||||||
| 447 |         if ((
 
  | 0 | ||||||||||||
| 448 |             flags |= SideWidgetCreatedByWidgetAction; never executed:  flags |= SideWidgetCreatedByWidgetAction; | 0 | ||||||||||||
| 449 |     } never executed:  end of block | 0 | ||||||||||||
| 450 |     if (!w
  | 0 | ||||||||||||
| 451 | QLineEditIconButton *toolButton = new QLineEditIconButton(q); | - | ||||||||||||
| 452 | toolButton->setIcon(newAction->icon()); | - | ||||||||||||
| 453 | toolButton->setOpacity(lastTextSize > 0 || !(flags & SideWidgetFadeInWithText) ? 1 : 0); | - | ||||||||||||
| 454 |         if (flags & SideWidgetClearButton
  | 0 | ||||||||||||
| 455 |             QObject::connect(toolButton, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "504""514"), q, qFlagLocation("1""_q_clearButtonClicked()" "\0" __FILE__ ":" "504""514")); never executed:  QObject::connect(toolButton, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "514"), q, qFlagLocation("1""_q_clearButtonClicked()" "\0" __FILE__ ":" "514")); | 0 | ||||||||||||
| 456 | toolButton->setDefaultAction(newAction); | - | ||||||||||||
| 457 | w = toolButton; | - | ||||||||||||
| 458 |     } never executed:  end of block | 0 | ||||||||||||
| 459 | - | |||||||||||||
| 460 |     PositionIndexPair positionIndex = before
  | 0 | ||||||||||||
| 461 |     SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition
  | 0 | ||||||||||||
| 462 |     if (positionIndex.second < 0
  | 0 | ||||||||||||
| 463 |         positionIndex.second = int(list.size();()); never executed:  positionIndex.second = int(list.size()); | 0 | ||||||||||||
| 464 | list.insert(list.begin() + positionIndex.second, SideWidgetEntry(w, newAction, flags)); | - | ||||||||||||
| 465 | positionSideWidgets(); | - | ||||||||||||
| 466 | w->show(); | - | ||||||||||||
| 467 |     return never executed:   w;return w;never executed:  return w; | 0 | ||||||||||||
| 468 | } | - | ||||||||||||
| 469 | - | |||||||||||||
| 470 | void QLineEditPrivate::removeAction(QAction *action) | - | ||||||||||||
| 471 | { | - | ||||||||||||
| 472 | QLineEdit * const q = q_func(); | - | ||||||||||||
| 473 | const PositionIndexPair positionIndex = findSideWidget(action); | - | ||||||||||||
| 474 |     if (positionIndex.second == -1
  | 0 | ||||||||||||
| 475 |         return; never executed:  return; | 0 | ||||||||||||
| 476 |      SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition
  | 0 | ||||||||||||
| 477 | SideWidgetEntry entry = list[positionIndex.takeAtsecond]; | - | ||||||||||||
| 478 | list.erase(list.begin() + positionIndex.second); | - | ||||||||||||
| 479 |      if (entry.flags & SideWidgetCreatedByWidgetAction
  | 0 | ||||||||||||
| 480 |          static_cast< never executed:  QWidgetAction *>(entry.action)->releaseWidget(entry.widget);static_cast<QWidgetAction *>(entry.action)->releaseWidget(entry.widget);never executed:  static_cast<QWidgetAction *>(entry.action)->releaseWidget(entry.widget); | 0 | ||||||||||||
| 481 | else | - | ||||||||||||
| 482 |          delete entry.widget; never executed:  delete entry.widget; | 0 | ||||||||||||
| 483 | positionSideWidgets(); | - | ||||||||||||
| 484 |      if (!hasSideWidgets()
  | 0 | ||||||||||||
| 485 |          QObject::disconnect(q, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "533""544"), q, qFlagLocation("1""_q_textChanged(QString)" "\0" __FILE__ ":" "533""544")); never executed:  QObject::disconnect(q, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "544"), q, qFlagLocation("1""_q_textChanged(QString)" "\0" __FILE__ ":" "544")); | 0 | ||||||||||||
| 486 | q->update(); | - | ||||||||||||
| 487 | } never executed:  end of block | 0 | ||||||||||||
| 488 | - | |||||||||||||
| 489 | static bool isSideWidgetVisible(const QLineEditPrivate::SideWidgetEntry &e) | - | ||||||||||||
| 490 | { | - | ||||||||||||
| 491 |    return never executed:   e.widget->isVisible();return e.widget->isVisible();never executed:  return e.widget->isVisible(); | 0 | ||||||||||||
| 492 | } | - | ||||||||||||
| 493 | - | |||||||||||||
| 494 | int QLineEditPrivate::effectiveLeftTextMargin() const | - | ||||||||||||
| 495 | { | - | ||||||||||||
| 496 | int result = leftTextMargin; | - | ||||||||||||
| 497 |     if (!leftSideWidgetList().empty()
  | 0 | ||||||||||||
| 498 | const SideWidgetParameters p = sideWidgetParameters(); | - | ||||||||||||
| 499 | result += (p.margin + p.widgetWidth) | - | ||||||||||||
| 500 | * int(std::count_if(leftSideWidgetList().begin(), leftSideWidgetList().end(), | - | ||||||||||||
| 501 | isSideWidgetVisible)); | - | ||||||||||||
| 502 |     } never executed:  end of block | 0 | ||||||||||||
| 503 |     return never executed:   result;return result;never executed:  return result; | 0 | ||||||||||||
| 504 | } | - | ||||||||||||
| 505 | - | |||||||||||||
| 506 | int QLineEditPrivate::effectiveRightTextMargin() const | - | ||||||||||||
| 507 | { | - | ||||||||||||
| 508 | int result = rightTextMargin; | - | ||||||||||||
| 509 |     if (!rightSideWidgetList().empty()
  | 0 | ||||||||||||
| 510 | const SideWidgetParameters p = sideWidgetParameters(); | - | ||||||||||||
| 511 | result += (p.margin + p.widgetWidth) | - | ||||||||||||
| 512 | * int(std::count_if(rightSideWidgetList().begin(), rightSideWidgetList().end(), | - | ||||||||||||
| 513 | isSideWidgetVisible)); | - | ||||||||||||
| 514 |     } never executed:  end of block | 0 | ||||||||||||
| 515 |     return never executed:   result;return result;never executed:  return result; | 0 | ||||||||||||
| 516 | } | - | ||||||||||||
| 517 | - | |||||||||||||
| 518 | - | |||||||||||||
| 519 | - | |||||||||||||
| 520 | - | |||||||||||||
| Switch to Source code | Preprocessed file |