diff options
author | Aurélien Gâteau <agateau@kde.org> | 2013-07-18 15:44:08 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-30 16:29:31 +0200 |
commit | eea5b8bf8b835eb2bc96aebc6a81acd4c3ca376c (patch) | |
tree | f4049bdf7ae1d779a07aa6c968d068b90bedff69 /src | |
parent | d51ce5b270869b0f12223a87410c389409e997c2 (diff) |
Assign icons to actions of QLineEdit context menu
Icons are only set if they are valid.
Change-Id: If2398cdc977a3882e7738ef1bcf5519bd7053449
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 4254ef2b27..9efae802c6 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1983,6 +1983,13 @@ void QLineEdit::contextMenuEvent(QContextMenuEvent *event) } } +static inline void setActionIcon(QAction *action, const QString &name) +{ + const QIcon icon = QIcon::fromTheme(name); + if (!icon.isNull()) + action->setIcon(icon); +} + /*! This function creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button. It is called from the default contextMenuEvent() handler. @@ -1999,10 +2006,12 @@ QMenu *QLineEdit::createStandardContextMenu() if (!isReadOnly()) { action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo)); action->setEnabled(d->control->isUndoAvailable()); + setActionIcon(action, QStringLiteral("edit-undo")); connect(action, SIGNAL(triggered()), SLOT(undo())); action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo)); action->setEnabled(d->control->isRedoAvailable()); + setActionIcon(action, QStringLiteral("edit-redo")); connect(action, SIGNAL(triggered()), SLOT(redo())); popup->addSeparator(); @@ -2013,17 +2022,20 @@ QMenu *QLineEdit::createStandardContextMenu() action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut)); action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText() && d->control->echoMode() == QLineEdit::Normal); + setActionIcon(action, QStringLiteral("edit-cut")); connect(action, SIGNAL(triggered()), SLOT(cut())); } action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy)); action->setEnabled(d->control->hasSelectedText() && d->control->echoMode() == QLineEdit::Normal); + setActionIcon(action, QStringLiteral("edit-copy")); connect(action, SIGNAL(triggered()), SLOT(copy())); if (!isReadOnly()) { action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste)); action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty()); + setActionIcon(action, QStringLiteral("edit-paste")); connect(action, SIGNAL(triggered()), SLOT(paste())); } #endif @@ -2031,6 +2043,7 @@ QMenu *QLineEdit::createStandardContextMenu() if (!isReadOnly()) { action = popup->addAction(QLineEdit::tr("Delete")); action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText()); + setActionIcon(action, QStringLiteral("edit-delete")); connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected())); } |