From eea5b8bf8b835eb2bc96aebc6a81acd4c3ca376c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 18 Jul 2013 15:44:08 +0200 Subject: Assign icons to actions of QLineEdit context menu Icons are only set if they are valid. Change-Id: If2398cdc977a3882e7738ef1bcf5519bd7053449 Reviewed-by: Friedemann Kleint Reviewed-by: Laszlo Papp --- src/widgets/widgets/qlineedit.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/widgets/widgets/qlineedit.cpp') 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())); } -- cgit v1.2.3