mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-09 14:52:39 +01:00
external tools for nonwebengine viewer
This commit is contained in:
parent
04a87c8a23
commit
830939f5e6
@ -3,9 +3,13 @@
|
||||
#include "gui/messagetextbrowser.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/externaltool.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QFileIconProvider>
|
||||
|
||||
MessageTextBrowser::MessageTextBrowser(QWidget* parent) : QTextBrowser(parent) {
|
||||
setAutoFillBackground(true);
|
||||
setFrameShape(QFrame::StyledPanel);
|
||||
@ -44,6 +48,50 @@ QSize MessageTextBrowser::sizeHint() const {
|
||||
return doc_size;
|
||||
}
|
||||
|
||||
void MessageTextBrowser::contextMenuEvent(QContextMenuEvent* event) {
|
||||
event->accept();
|
||||
|
||||
auto* menu = createStandardContextMenu();
|
||||
|
||||
if (menu == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto anchor = anchorAt(event->pos());
|
||||
|
||||
if (!anchor.isEmpty()) {
|
||||
QFileIconProvider icon_provider;
|
||||
QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), menu);
|
||||
auto tools = ExternalTool::toolsFromSettings();
|
||||
|
||||
menu_ext_tools->setIcon(qApp->icons()->fromTheme(QSL("document-open")));
|
||||
|
||||
for (const ExternalTool& tool : qAsConst(tools)) {
|
||||
QAction* act_tool = new QAction(QFileInfo(tool.executable()).fileName(), menu_ext_tools);
|
||||
|
||||
act_tool->setIcon(icon_provider.icon(tool.executable()));
|
||||
act_tool->setToolTip(tool.executable());
|
||||
act_tool->setData(QVariant::fromValue(tool));
|
||||
menu_ext_tools->addAction(act_tool);
|
||||
|
||||
connect(act_tool, &QAction::triggered, this, [act_tool, anchor]() {
|
||||
act_tool->data().value<ExternalTool>().run(anchor);
|
||||
});
|
||||
}
|
||||
|
||||
if (menu_ext_tools->actions().isEmpty()) {
|
||||
QAction* act_not_tools = new QAction("No external tools activated");
|
||||
|
||||
act_not_tools->setEnabled(false);
|
||||
menu_ext_tools->addAction(act_not_tools);
|
||||
}
|
||||
|
||||
menu->addMenu(menu_ext_tools);
|
||||
}
|
||||
|
||||
menu->popup(event->globalPos());
|
||||
}
|
||||
|
||||
void MessageTextBrowser::wheelEvent(QWheelEvent* event) {
|
||||
QTextBrowser::wheelEvent(event);
|
||||
qApp->settings()->setValue(GROUP(Messages), Messages::PreviewerFontStandard, font().toString());
|
||||
|
@ -18,6 +18,7 @@ class MessageTextBrowser : public QTextBrowser {
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
protected:
|
||||
virtual void contextMenuEvent(QContextMenuEvent* event);
|
||||
virtual void wheelEvent(QWheelEvent* event);
|
||||
virtual void resizeEvent (QResizeEvent* event);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user