[kde-doc-english] [trojita] src/Gui: GUI: refactor custom action for WebView's context menu
Jan Kundrát
jkt at kde.org
Fri Jan 29 11:36:28 UTC 2016
Git commit e1cfdc471b5e50edad049048b7f0de3883c1ea03 by Jan Kundrát.
Committed on 27/01/2016 at 14:19.
Pushed by gerrit into branch 'master'.
GUI: refactor custom action for WebView's context menu
There's really no need for the MessageView to poke within the
SimplePartWidget's internal stuff and for testing its hit contents; this
should be done by the SimplePartWidget alone.
Also reorder the resulting actions in a (subjectively) better way --
context-specific actions at the top, with the global ones at the bottom.
Change-Id: If2cec5381ad1f93fb3f16f188963d9f293e94689
M +1 -8 src/Gui/MessageView.cpp
M +12 -2 src/Gui/SimplePartWidget.cpp
M +1 -1 src/Gui/SimplePartWidget.h
http://commits.kde.org/trojita/e1cfdc471b5e50edad049048b7f0de3883c1ea03
diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index 44d6a09..5ed37e1 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -446,14 +446,7 @@ void MessageView::partContextMenuRequested(const QPoint &point)
{
if (SimplePartWidget *w = qobject_cast<SimplePartWidget *>(sender())) {
QMenu menu(w);
- Q_FOREACH(QAction *action, w->contextMenuSpecificActions())
- menu.addAction(action);
- menu.addAction(w->pageAction(QWebPage::Copy));
- menu.addAction(w->pageAction(QWebPage::SelectAll));
- if (!w->page()->mainFrame()->hitTestContent(point).linkUrl().isEmpty()) {
- menu.addSeparator();
- menu.addAction(w->pageAction(QWebPage::CopyLinkToClipboard));
- }
+ w->buildContextMenu(point, menu);
menu.exec(w->mapToGlobal(point));
}
}
diff --git a/src/Gui/SimplePartWidget.cpp b/src/Gui/SimplePartWidget.cpp
index d9eb92b..48cc1bb 100644
--- a/src/Gui/SimplePartWidget.cpp
+++ b/src/Gui/SimplePartWidget.cpp
@@ -22,6 +22,7 @@
#include <QApplication>
#include <QFileDialog>
#include <QFontDatabase>
+#include <QMenu>
#include <QNetworkReply>
#include <QWebFrame>
@@ -141,9 +142,18 @@ void SimplePartWidget::reloadContents()
EmbeddedWebView::reload();
}
-QList<QAction *> SimplePartWidget::contextMenuSpecificActions() const
+void SimplePartWidget::buildContextMenu(const QPoint &point, QMenu &menu) const
{
- return QList<QAction*>() << m_savePart << m_saveMessage << m_findAction;
+ menu.addAction(m_findAction);
+ menu.addAction(pageAction(QWebPage::Copy));
+ menu.addAction(pageAction(QWebPage::SelectAll));
+ if (!page()->mainFrame()->hitTestContent(point).linkUrl().isEmpty()) {
+ menu.addSeparator();
+ menu.addAction(pageAction(QWebPage::CopyLinkToClipboard));
+ }
+ menu.addSeparator();
+ menu.addAction(m_savePart);
+ menu.addAction(m_saveMessage);
}
void SimplePartWidget::slotDownloadPart()
diff --git a/src/Gui/SimplePartWidget.h b/src/Gui/SimplePartWidget.h
index 517b4cb..bb7f559 100644
--- a/src/Gui/SimplePartWidget.h
+++ b/src/Gui/SimplePartWidget.h
@@ -59,7 +59,7 @@ public:
MessageView *messageView);
virtual QString quoteMe() const;
virtual void reloadContents();
- QList<QAction *> contextMenuSpecificActions() const;
+ void buildContextMenu(const QPoint &point, QMenu &menu) const;
private slots:
void slotFileNameRequested(QString *fileName);
void slotMarkupPlainText();
More information about the kde-doc-english
mailing list