diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-06-13 16:23:44 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-06 08:19:38 +0200 |
commit | 9ce12cc8de940cdd450a28f4bd079acfc3621aa3 (patch) | |
tree | ca07f5b57179b58caae43f0297be4f4d9834d8e5 /src/widgets/widgets/qlineedit.cpp | |
parent | c207724c9bb8e205e756086950063cc91656e401 (diff) |
Add side widgets to QLineEdit via QAction.
Add QLineEdit::addAction() overloads,
allowing for a variable number of icons or user-defined
widgets.
Change-Id: Id298f18c2f47cc998170357e65cc6098df851aab
Done-with: Kevin.Ottens@kdab.com
Reviewed-by: Thomas Zander <zander@kde.org>
Reviewed-by: Richard J. Moore <rich@kde.org>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/widgets/widgets/qlineedit.cpp')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 9efae802c6..c704eb5c35 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -420,6 +420,60 @@ bool QLineEdit::hasFrame() const return d->frame; } +/*! + \enum QLineEdit::ActionPosition + + This enum type describes how a line edit should display the action widgets to be + added. + + \value LeadingPosition The widget is displayed to the left of the text + when using layout direction \c Qt::LeftToRight or to + the right when using \c Qt::RightToLeft, respectively. + + \value TrailingPosition The widget is displayed to the right of the text + when using layout direction \c Qt::LeftToRight or to + the left when using \c Qt::RightToLeft, respectively. + + \sa addAction(), removeAction(), QWidget::layoutDirection + + \since 5.2 +*/ + +/*! + \fn void QLineEdit::addAction(QAction *action) + \overload + \internal +*/ + +/*! + \overload + + Adds the \a action to the list of actions at the \a position. + + \since 5.2 +*/ + +void QLineEdit::addAction(QAction *action, ActionPosition position) +{ + Q_D(QLineEdit); + QWidget::addAction(action); + d->addAction(action, 0, position); +} + +/*! + \overload + + Creates a new action with the given \a icon at the \a position. + + \since 5.2 +*/ + +QAction *QLineEdit::addAction(const QIcon &icon, ActionPosition position) +{ + QAction *result = new QAction(icon, QString(), this); + addAction(result, position); + return result; +} void QLineEdit::setFrame(bool enable) { @@ -606,7 +660,7 @@ QSize QLineEdit::sizeHint() const + d->topTextMargin + d->bottomTextMargin + d->topmargin + d->bottommargin; int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin - + d->leftTextMargin + d->rightTextMargin + + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + d->leftmargin + d->rightmargin; // "some" QStyleOptionFrameV2 opt; initStyleOption(&opt); @@ -967,7 +1021,6 @@ void QLineEdit::setDragEnabled(bool b) d->dragEnabled = b; } - /*! \property QLineEdit::cursorMoveStyle \brief the movement style of cursor in this line edit @@ -1350,8 +1403,11 @@ bool QLineEdit::event(QEvent * e) || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) d->setCursorVisible(true); } + } else if (e->type() == QEvent::ActionRemoved) { + d->removeAction(static_cast<QActionEvent *>(e)); + } else if (e->type() == QEvent::Resize) { + d->positionSideWidgets(); } - #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) { if (e->type() == QEvent::EnterEditFocus) { @@ -1777,9 +1833,9 @@ void QLineEdit::paintEvent(QPaintEvent *) initStyleOption(&panel); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this); r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.setX(r.x() + d->leftTextMargin); + r.setX(r.x() + d->effectiveLeftTextMargin()); r.setY(r.y() + d->topTextMargin); - r.setRight(r.right() - d->rightTextMargin); + r.setRight(r.right() - d->effectiveRightTextMargin()); r.setBottom(r.bottom() - d->bottomTextMargin); p.setClipRect(r); @@ -2083,8 +2139,12 @@ void QLineEdit::changeEvent(QEvent *ev) initStyleOption(&opt); d->control->setPasswordCharacter(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)); } + d->m_iconSize = QSize(); update(); break; + case QEvent::LayoutDirectionChange: + d->positionSideWidgets(); + break; default: break; } |