qlineedit_p.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qlineedit_p.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
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 https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qlineedit.h"-
41#include "qlineedit_p.h"-
42-
43#ifndef QT_NO_LINEEDIT-
44-
45#include "qvariant.h"-
46#include "qabstractitemview.h"-
47#include "qdrag.h"-
48#include "qwidgetaction.h"-
49#include "qclipboard.h"-
50#ifndef QT_NO_ACCESSIBILITY-
51#include "qaccessible.h"-
52#endif-
53#ifndef QT_NO_IM-
54#include "qinputmethod.h"-
55#include "qlist.h"-
56#endif-
57#include <qpropertyanimation.h>-
58-
59QT_BEGIN_NAMESPACE-
60-
61const int QLineEditPrivate::verticalMargin(1);-
62const int QLineEditPrivate::horizontalMargin(2);-
63-
64QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const-
65{-
66 QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect();
!rect.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
67 QRect cr = adjustedContentsRect();-
68 int cix = cr.x() - hscroll + horizontalMargin;-
69 return widgetRect.translated(QPoint(cix, vscroll));
never executed: return widgetRect.translated(QPoint(cix, vscroll));
0
70}-
71-
72int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const-
73{-
74 QRect cr = adjustedContentsRect();-
75 x-= cr.x() - hscroll + horizontalMargin;-
76 return control->xToPos(x, betweenOrOn);
never executed: return control->xToPos(x, betweenOrOn);
0
77}-
78-
79bool QLineEditPrivate::inSelection(int x) const-
80{-
81 x -= adjustedContentsRect().x() - hscroll + horizontalMargin;-
82 return control->inSelection(x);
never executed: return control->inSelection(x);
0
83}-
84-
85QRect QLineEditPrivate::cursorRect() const-
86{-
87 return adjustedControlRect(control->cursorRect());
never executed: return adjustedControlRect(control->cursorRect());
0
88}-
89-
90#ifndef QT_NO_COMPLETER-
91-
92void QLineEditPrivate::_q_completionHighlighted(const QString &newText)-
93{-
94 Q_Q(QLineEdit);-
95 if (control->completer()->completionMode() != QCompleter::InlineCompletion) {
control->compl...lineCompletionDescription
TRUEnever evaluated
FALSEnever evaluated
0
96 q->setText(newText);-
97 } else {
never executed: end of block
0
98 int c = control->cursor();-
99 QString text = control->text();-
100 q->setText(text.leftRef(c) + newText.midRef(c));-
101 control->moveCursor(control->end(), false);-
102#ifndef Q_OS_ANDROID-
103 const bool mark = true;-
104#else-
105 const bool mark = (imHints & Qt::ImhNoPredictiveText);-
106#endif-
107 control->moveCursor(c, mark);-
108 }
never executed: end of block
0
109}-
110-
111#endif // QT_NO_COMPLETER-
112-
113void QLineEditPrivate::_q_handleWindowActivate()-
114{-
115 Q_Q(QLineEdit);-
116 if (!q->hasFocus() && control->hasSelectedText())
!q->hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
control->hasSelectedText()Description
TRUEnever evaluated
FALSEnever evaluated
0
117 control->deselect();
never executed: control->deselect();
0
118}
never executed: end of block
0
119-
120void QLineEditPrivate::_q_textEdited(const QString &text)-
121{-
122 Q_Q(QLineEdit);-
123 emit q->textEdited(text);-
124#ifndef QT_NO_COMPLETER-
125 if (control->completer()
control->completer()Description
TRUEnever evaluated
FALSEnever evaluated
0
126 && control->completer()->completionMode() != QCompleter::InlineCompletion)
control->compl...lineCompletionDescription
TRUEnever evaluated
FALSEnever evaluated
0
127 control->complete(-1); // update the popup on cut/paste/del
never executed: control->complete(-1);
0
128#endif-
129}
never executed: end of block
0
130-
131void QLineEditPrivate::_q_cursorPositionChanged(int from, int to)-
132{-
133 Q_Q(QLineEdit);-
134 q->update();-
135 emit q->cursorPositionChanged(from, to);-
136}
never executed: end of block
0
137-
138#ifdef QT_KEYPAD_NAVIGATION-
139void QLineEditPrivate::_q_editFocusChange(bool e)-
140{-
141 Q_Q(QLineEdit);-
142 q->setEditFocus(e);-
143}-
144#endif-
145-
146void QLineEditPrivate::_q_selectionChanged()-
147{-
148 Q_Q(QLineEdit);-
149 if (control->preeditAreaText().isEmpty()) {
control->preed...xt().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
150 QStyleOptionFrame opt;-
151 q->initStyleOption(&opt);-
152 bool showCursor = control->hasSelectedText() ?
control->hasSelectedText()Description
TRUEnever evaluated
FALSEnever evaluated
0
153 q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q):-
154 q->hasFocus();-
155 setCursorVisible(showCursor);-
156 }
never executed: end of block
0
157-
158 emit q->selectionChanged();-
159#ifndef QT_NO_ACCESSIBILITY-
160 QAccessibleTextSelectionEvent ev(q, control->selectionStart(), control->selectionEnd());-
161 ev.setCursorPosition(control->cursorPosition());-
162 QAccessible::updateAccessibility(&ev);-
163#endif-
164}
never executed: end of block
0
165-
166void QLineEditPrivate::_q_updateNeeded(const QRect &rect)-
167{-
168 q_func()->update(adjustedControlRect(rect));-
169}
never executed: end of block
0
170-
171void QLineEditPrivate::init(const QString& txt)-
172{-
173 Q_Q(QLineEdit);-
174 control = new QWidgetLineControl(txt);-
175 control->setParent(q);-
176 control->setFont(q->font());-
177 QObject::connect(control, SIGNAL(textChanged(QString)),-
178 q, SIGNAL(textChanged(QString)));-
179 QObject::connect(control, SIGNAL(textEdited(QString)),-
180 q, SLOT(_q_textEdited(QString)));-
181 QObject::connect(control, SIGNAL(cursorPositionChanged(int,int)),-
182 q, SLOT(_q_cursorPositionChanged(int,int)));-
183 QObject::connect(control, SIGNAL(selectionChanged()),-
184 q, SLOT(_q_selectionChanged()));-
185 QObject::connect(control, SIGNAL(accepted()),-
186 q, SIGNAL(returnPressed()));-
187 QObject::connect(control, SIGNAL(editingFinished()),-
188 q, SIGNAL(editingFinished()));-
189#ifdef QT_KEYPAD_NAVIGATION-
190 QObject::connect(control, SIGNAL(editFocusChange(bool)),-
191 q, SLOT(_q_editFocusChange(bool)));-
192#endif-
193 QObject::connect(control, SIGNAL(cursorPositionChanged(int,int)),-
194 q, SLOT(updateMicroFocus()));-
195-
196 QObject::connect(control, SIGNAL(textChanged(QString)),-
197 q, SLOT(updateMicroFocus()));-
198-
199 // for now, going completely overboard with updates.-
200 QObject::connect(control, SIGNAL(selectionChanged()),-
201 q, SLOT(update()));-
202-
203 QObject::connect(control, SIGNAL(selectionChanged()),-
204 q, SLOT(updateMicroFocus()));-
205-
206 QObject::connect(control, SIGNAL(displayTextChanged(QString)),-
207 q, SLOT(update()));-
208-
209 QObject::connect(control, SIGNAL(updateNeeded(QRect)),-
210 q, SLOT(_q_updateNeeded(QRect)));-
211-
212 QStyleOptionFrame opt;-
213 q->initStyleOption(&opt);-
214 control->setPasswordCharacter(q->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, q));-
215 control->setPasswordMaskDelay(q->style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, q));-
216#ifndef QT_NO_CURSOR-
217 q->setCursor(Qt::IBeamCursor);-
218#endif-
219 q->setFocusPolicy(Qt::StrongFocus);-
220 q->setAttribute(Qt::WA_InputMethodEnabled);-
221 // Specifies that this widget can use more, but is able to survive on-
222 // less, horizontal space; and is fixed vertically.-
223 q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit));-
224 q->setBackgroundRole(QPalette::Base);-
225 q->setAttribute(Qt::WA_KeyCompression);-
226 q->setMouseTracking(true);-
227 q->setAcceptDrops(true);-
228-
229 q->setAttribute(Qt::WA_MacShowFocusRect);-
230}
never executed: end of block
0
231-
232QRect QLineEditPrivate::adjustedContentsRect() const-
233{-
234 Q_Q(const QLineEdit);-
235 QStyleOptionFrame opt;-
236 q->initStyleOption(&opt);-
237 QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q);-
238 r.setX(r.x() + effectiveLeftTextMargin());-
239 r.setY(r.y() + topTextMargin);-
240 r.setRight(r.right() - effectiveRightTextMargin());-
241 r.setBottom(r.bottom() - bottomTextMargin);-
242 return r;
never executed: return r;
0
243}-
244-
245void QLineEditPrivate::setCursorVisible(bool visible)-
246{-
247 Q_Q(QLineEdit);-
248 if ((bool)cursorVisible == visible)
(bool)cursorVisible == visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
249 return;
never executed: return;
0
250 cursorVisible = visible;-
251 if (control->inputMask().isEmpty())
control->inputMask().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
252 q->update(cursorRect());
never executed: q->update(cursorRect());
0
253 else-
254 q->update();
never executed: q->update();
0
255}-
256-
257void QLineEditPrivate::updatePasswordEchoEditing(bool editing)-
258{-
259 Q_Q(QLineEdit);-
260 control->updatePasswordEchoEditing(editing);-
261 q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod());-
262}
never executed: end of block
0
263-
264void QLineEditPrivate::resetInputMethod()-
265{-
266 Q_Q(QLineEdit);-
267 if (q->hasFocus() && qApp) {
q->hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
(static_cast<Q...::instance()))Description
TRUEnever evaluated
FALSEnever evaluated
0
268 QGuiApplication::inputMethod()->reset();-
269 }
never executed: end of block
0
270}
never executed: end of block
0
271-
272/*!-
273 This function is not intended as polymorphic usage. Just a shared code-
274 fragment that calls QInputMethod::invokeAction for this-
275 class.-
276*/-
277bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e )-
278{-
279#if !defined QT_NO_IM-
280 if ( control->composeMode() ) {
control->composeMode()Description
TRUEnever evaluated
FALSEnever evaluated
0
281 int tmp_cursor = xToPos(e->pos().x());-
282 int mousePos = tmp_cursor - control->cursor();-
283 if ( mousePos < 0 || mousePos > control->preeditAreaText().length() )
mousePos < 0Description
TRUEnever evaluated
FALSEnever evaluated
mousePos > con...ext().length()Description
TRUEnever evaluated
FALSEnever evaluated
0
284 mousePos = -1;
never executed: mousePos = -1;
0
285-
286 if (mousePos >= 0) {
mousePos >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
287 if (e->type() == QEvent::MouseButtonRelease)
e->type() == Q...eButtonReleaseDescription
TRUEnever evaluated
FALSEnever evaluated
0
288 QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, mousePos);
never executed: QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, mousePos);
0
289-
290 return true;
never executed: return true;
0
291 }-
292 }
never executed: end of block
0
293#else-
294 Q_UNUSED(e);-
295#endif-
296-
297 return false;
never executed: return false;
0
298}-
299-
300#ifndef QT_NO_DRAGANDDROP-
301void QLineEditPrivate::drag()-
302{-
303 Q_Q(QLineEdit);-
304 dndTimer.stop();-
305 QMimeData *data = new QMimeData;-
306 data->setText(control->selectedText());-
307 QDrag *drag = new QDrag(q);-
308 drag->setMimeData(data);-
309 Qt::DropAction action = drag->start();-
310 if (action == Qt::MoveAction && !control->isReadOnly() && drag->target() != q)
action == Qt::MoveActionDescription
TRUEnever evaluated
FALSEnever evaluated
!control->isReadOnly()Description
TRUEnever evaluated
FALSEnever evaluated
drag->target() != qDescription
TRUEnever evaluated
FALSEnever evaluated
0
311 control->removeSelection();
never executed: control->removeSelection();
0
312}
never executed: end of block
0
313-
314#endif // QT_NO_DRAGANDDROP-
315-
316QLineEditIconButton::QLineEditIconButton(QWidget *parent)-
317 : QToolButton(parent)-
318 , m_opacity(0)-
319{-
320 setFocusPolicy(Qt::NoFocus);-
321}
never executed: end of block
0
322-
323QLineEditPrivate *QLineEditIconButton::lineEditPrivate() const-
324{-
325 QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget());-
326 return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : Q_NULLPTR;
never executed: return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : nullptr;
0
327}-
328-
329void QLineEditIconButton::paintEvent(QPaintEvent *)-
330{-
331 QPainter painter(this);-
332 QWindow *window = Q_NULLPTR;-
333 if (const QWidget *nativeParent = nativeParentWidget())
const QWidget ...ParentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
334 window = nativeParent->windowHandle();
never executed: window = nativeParent->windowHandle();
0
335 // Note isDown should really use the active state but in most styles-
336 // this has no proper feedback-
337 QIcon::Mode state = QIcon::Disabled;-
338 if (isEnabled())
isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
339 state = isDown() ? QIcon::Selected : QIcon::Normal;
never executed: state = isDown() ? QIcon::Selected : QIcon::Normal;
isDown()Description
TRUEnever evaluated
FALSEnever evaluated
0
340 const QLineEditPrivate *lep = lineEditPrivate();-
341 const int iconWidth = lep ? lep->sideWidgetParameters().iconSize : 16;
lepDescription
TRUEnever evaluated
FALSEnever evaluated
0
342 const QSize iconSize(iconWidth, iconWidth);-
343 const QPixmap iconPixmap = icon().pixmap(window, iconSize, state, QIcon::Off);-
344 QRect pixmapRect = QRect(QPoint(0, 0), iconSize);-
345 pixmapRect.moveCenter(rect().center());-
346 painter.setOpacity(m_opacity);-
347 painter.drawPixmap(pixmapRect, iconPixmap);-
348}
never executed: end of block
0
349-
350void QLineEditIconButton::actionEvent(QActionEvent *e)-
351{-
352 switch (e->type()) {-
353 case QEvent::ActionChanged: {
never executed: case QEvent::ActionChanged:
0
354 const QAction *action = e->action();-
355 if (isVisibleTo(parentWidget()) != action->isVisible()) {
isVisibleTo(pa...n->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
356 setVisible(action->isVisible());-
357 if (QLineEditPrivate *lep = lineEditPrivate())
QLineEditPriva...eEditPrivate()Description
TRUEnever evaluated
FALSEnever evaluated
0
358 lep->positionSideWidgets();
never executed: lep->positionSideWidgets();
0
359 }
never executed: end of block
0
360 }-
361 break;
never executed: break;
0
362 default:
never executed: default:
0
363 break;
never executed: break;
0
364 }-
365 QToolButton::actionEvent(e);-
366}
never executed: end of block
0
367-
368void QLineEditIconButton::setOpacity(qreal value)-
369{-
370 if (!qFuzzyCompare(m_opacity, value)) {
!qFuzzyCompare...pacity, value)Description
TRUEnever evaluated
FALSEnever evaluated
0
371 m_opacity = value;-
372 updateCursor();-
373 update();-
374 }
never executed: end of block
0
375}
never executed: end of block
0
376-
377#ifndef QT_NO_ANIMATION-
378void QLineEditIconButton::startOpacityAnimation(qreal endValue)-
379{-
380 QPropertyAnimation *animation = new QPropertyAnimation(this, QByteArrayLiteral("opacity"));
never executed: return ba;
0
381 animation->setDuration(160);-
382 animation->setEndValue(endValue);-
383 animation->start(QAbstractAnimation::DeleteWhenStopped);-
384}
never executed: end of block
0
385#endif-
386-
387void QLineEditIconButton::updateCursor()-
388{-
389#ifndef QT_NO_CURSOR-
390 setCursor(qFuzzyCompare(m_opacity, qreal(1.0)) || !parentWidget() ? QCursor(Qt::ArrowCursor) : parentWidget()->cursor());-
391#endif-
392}
never executed: end of block
0
393-
394void QLineEditPrivate::_q_textChanged(const QString &text)-
395{-
396 if (hasSideWidgets()) {
hasSideWidgets()Description
TRUEnever evaluated
FALSEnever evaluated
0
397 const int newTextSize = text.size();-
398 if (!newTextSize || !lastTextSize) {
!newTextSizeDescription
TRUEnever evaluated
FALSEnever evaluated
!lastTextSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
399 lastTextSize = newTextSize;-
400#ifndef QT_NO_ANIMATION-
401 const bool fadeIn = newTextSize > 0;-
402 for (const SideWidgetEntry &e : leadingSideWidgets) {-
403 if (e.flags & SideWidgetFadeInWithText)
e.flags & Side...FadeInWithTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
404 static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn);
never executed: static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn);
0
405 }
never executed: end of block
0
406 for (const SideWidgetEntry &e : trailingSideWidgets) {-
407 if (e.flags & SideWidgetFadeInWithText)
e.flags & Side...FadeInWithTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
408 static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn);
never executed: static_cast<QLineEditIconButton *>(e.widget)->animateShow(fadeIn);
0
409 }
never executed: end of block
0
410#endif-
411 }
never executed: end of block
0
412 }
never executed: end of block
0
413}
never executed: end of block
0
414-
415void QLineEditPrivate::_q_clearButtonClicked()-
416{-
417 Q_Q(QLineEdit);-
418 if (!q->text().isEmpty()) {
!q->text().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
419 q->clear();-
420 emit q->textEdited(QString());-
421 }
never executed: end of block
0
422}
never executed: end of block
0
423-
424QLineEditPrivate::SideWidgetParameters QLineEditPrivate::sideWidgetParameters() const-
425{-
426 Q_Q(const QLineEdit);-
427 SideWidgetParameters result;-
428 result.iconSize = q->height() < 34 ? 16 : 32;
q->height() < 34Description
TRUEnever evaluated
FALSEnever evaluated
0
429 result.margin = result.iconSize / 4;-
430 result.widgetWidth = result.iconSize + 6;-
431 result.widgetHeight = result.iconSize + 2;-
432 return result;
never executed: return result;
0
433}-
434-
435QIcon QLineEditPrivate::clearButtonIcon() const-
436{-
437 Q_Q(const QLineEdit);-
438 QStyleOptionFrame styleOption;-
439 q->initStyleOption(&styleOption);-
440 return q->style()->standardIcon(QStyle::SP_LineEditClearButton, &styleOption, q);
never executed: return q->style()->standardIcon(QStyle::SP_LineEditClearButton, &styleOption, q);
0
441}-
442-
443void QLineEditPrivate::setClearButtonEnabled(bool enabled)-
444{-
445 for (const SideWidgetEntry &e : trailingSideWidgets) {-
446 if (e.flags & SideWidgetClearButton) {
e.flags & Side...getClearButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
447 e.action->setEnabled(enabled);-
448 break;
never executed: break;
0
449 }-
450 }
never executed: end of block
0
451}
never executed: end of block
0
452-
453void QLineEditPrivate::positionSideWidgets()-
454{-
455 Q_Q(QLineEdit);-
456 if (hasSideWidgets()) {
hasSideWidgets()Description
TRUEnever evaluated
FALSEnever evaluated
0
457 const QRect contentRect = q->rect();-
458 const SideWidgetParameters p = sideWidgetParameters();-
459 const int delta = p.margin + p.widgetWidth;-
460 QRect widgetGeometry(QPoint(p.margin, (contentRect.height() - p.widgetHeight) / 2),-
461 QSize(p.widgetWidth, p.widgetHeight));-
462 for (const SideWidgetEntry &e : leftSideWidgetList()) {-
463 e.widget->setGeometry(widgetGeometry);-
464 if (e.action->isVisible())
e.action->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
465 widgetGeometry.moveLeft(widgetGeometry.left() + delta);
never executed: widgetGeometry.moveLeft(widgetGeometry.left() + delta);
0
466 }
never executed: end of block
0
467 widgetGeometry.moveLeft(contentRect.width() - p.widgetWidth - p.margin);-
468 for (const SideWidgetEntry &e : rightSideWidgetList()) {-
469 e.widget->setGeometry(widgetGeometry);-
470 if (e.action->isVisible())
e.action->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
471 widgetGeometry.moveLeft(widgetGeometry.left() - delta);
never executed: widgetGeometry.moveLeft(widgetGeometry.left() - delta);
0
472 }
never executed: end of block
0
473 }
never executed: end of block
0
474}
never executed: end of block
0
475-
476QLineEditPrivate::PositionIndexPair QLineEditPrivate::findSideWidget(const QAction *a) const-
477{-
478 int i = 0;-
479 for (const auto &e : leadingSideWidgets) {-
480 if (a == e.action)
a == e.actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
481 return PositionIndexPair(QLineEdit::LeadingPosition, i);
never executed: return PositionIndexPair(QLineEdit::LeadingPosition, i);
0
482 ++i;-
483 }
never executed: end of block
0
484 i = 0;-
485 for (const auto &e : trailingSideWidgets) {-
486 if (a == e.action)
a == e.actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
487 return PositionIndexPair(QLineEdit::TrailingPosition, i);
never executed: return PositionIndexPair(QLineEdit::TrailingPosition, i);
0
488 ++i;-
489 }
never executed: end of block
0
490 return PositionIndexPair(QLineEdit::LeadingPosition, -1);
never executed: return PositionIndexPair(QLineEdit::LeadingPosition, -1);
0
491}-
492-
493QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition position, int flags)-
494{-
495 Q_Q(QLineEdit);-
496 if (!newAction)
!newActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
497 return 0;
never executed: return 0;
0
498 if (!hasSideWidgets()) { // initial setup.
!hasSideWidgets()Description
TRUEnever evaluated
FALSEnever evaluated
0
499 QObject::connect(q, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString)));-
500 lastTextSize = q->text().size();-
501 }
never executed: end of block
0
502 QWidget *w = 0;-
503 // Store flags about QWidgetAction here since removeAction() may be called from ~QAction,-
504 // in which a qobject_cast<> no longer works.-
505 if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(newAction)) {
QWidgetAction ... *>(newAction)Description
TRUEnever evaluated
FALSEnever evaluated
0
506 if ((w = widgetAction->requestWidget(q)))
(w = widgetAct...uestWidget(q))Description
TRUEnever evaluated
FALSEnever evaluated
0
507 flags |= SideWidgetCreatedByWidgetAction;
never executed: flags |= SideWidgetCreatedByWidgetAction;
0
508 }
never executed: end of block
0
509 if (!w) {
!wDescription
TRUEnever evaluated
FALSEnever evaluated
0
510 QLineEditIconButton *toolButton = new QLineEditIconButton(q);-
511 toolButton->setIcon(newAction->icon());-
512 toolButton->setOpacity(lastTextSize > 0 || !(flags & SideWidgetFadeInWithText) ? 1 : 0);-
513 if (flags & SideWidgetClearButton)
flags & SideWidgetClearButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
514 QObject::connect(toolButton, SIGNAL(clicked()), q, SLOT(_q_clearButtonClicked()));
never executed: QObject::connect(toolButton, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "514"), q, qFlagLocation("1""_q_clearButtonClicked()" "\0" __FILE__ ":" "514"));
0
515 toolButton->setDefaultAction(newAction);-
516 w = toolButton;-
517 }
never executed: end of block
0
518 // If there is a 'before' action, it takes preference-
519 PositionIndexPair positionIndex = before ? findSideWidget(before) : PositionIndexPair(position, -1);
beforeDescription
TRUEnever evaluated
FALSEnever evaluated
0
520 SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets;
positionIndex....ailingPositionDescription
TRUEnever evaluated
FALSEnever evaluated
0
521 if (positionIndex.second < 0)
positionIndex.second < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
522 positionIndex.second = int(list.size());
never executed: positionIndex.second = int(list.size());
0
523 list.insert(list.begin() + positionIndex.second, SideWidgetEntry(w, newAction, flags));-
524 positionSideWidgets();-
525 w->show();-
526 return w;
never executed: return w;
0
527}-
528-
529void QLineEditPrivate::removeAction(QAction *action)-
530{-
531 Q_Q(QLineEdit);-
532 const PositionIndexPair positionIndex = findSideWidget(action);-
533 if (positionIndex.second == -1)
positionIndex.second == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
534 return;
never executed: return;
0
535 SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets;
positionIndex....ailingPositionDescription
TRUEnever evaluated
FALSEnever evaluated
0
536 SideWidgetEntry entry = list[positionIndex.second];-
537 list.erase(list.begin() + positionIndex.second);-
538 if (entry.flags & SideWidgetCreatedByWidgetAction)
entry.flags & ...ByWidgetActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
539 static_cast<QWidgetAction *>(entry.action)->releaseWidget(entry.widget);
never executed: static_cast<QWidgetAction *>(entry.action)->releaseWidget(entry.widget);
0
540 else-
541 delete entry.widget;
never executed: delete entry.widget;
0
542 positionSideWidgets();-
543 if (!hasSideWidgets()) // Last widget, remove connection
!hasSideWidgets()Description
TRUEnever evaluated
FALSEnever evaluated
0
544 QObject::disconnect(q, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString)));
never executed: QObject::disconnect(q, qFlagLocation("2""textChanged(QString)" "\0" __FILE__ ":" "544"), q, qFlagLocation("1""_q_textChanged(QString)" "\0" __FILE__ ":" "544"));
0
545 q->update();-
546}
never executed: end of block
0
547-
548static bool isSideWidgetVisible(const QLineEditPrivate::SideWidgetEntry &e)-
549{-
550 return e.widget->isVisible();
never executed: return e.widget->isVisible();
0
551}-
552-
553int QLineEditPrivate::effectiveLeftTextMargin() const-
554{-
555 int result = leftTextMargin;-
556 if (!leftSideWidgetList().empty()) {
!leftSideWidgetList().empty()Description
TRUEnever evaluated
FALSEnever evaluated
0
557 const SideWidgetParameters p = sideWidgetParameters();-
558 result += (p.margin + p.widgetWidth)-
559 * int(std::count_if(leftSideWidgetList().begin(), leftSideWidgetList().end(),-
560 isSideWidgetVisible));-
561 }
never executed: end of block
0
562 return result;
never executed: return result;
0
563}-
564-
565int QLineEditPrivate::effectiveRightTextMargin() const-
566{-
567 int result = rightTextMargin;-
568 if (!rightSideWidgetList().empty()) {
!rightSideWidgetList().empty()Description
TRUEnever evaluated
FALSEnever evaluated
0
569 const SideWidgetParameters p = sideWidgetParameters();-
570 result += (p.margin + p.widgetWidth)-
571 * int(std::count_if(rightSideWidgetList().begin(), rightSideWidgetList().end(),-
572 isSideWidgetVisible));-
573 }
never executed: end of block
0
574 return result;
never executed: return result;
0
575}-
576-
577-
578QT_END_NAMESPACE-
579-
580#include "moc_qlineedit_p.cpp"-
581-
582#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9