diff options
Diffstat (limited to 'src/webengine/widgets/pagemenu.cpp')
-rw-r--r-- | src/webengine/widgets/pagemenu.cpp | 69 |
1 files changed, 22 insertions, 47 deletions
diff --git a/src/webengine/widgets/pagemenu.cpp b/src/webengine/widgets/pagemenu.cpp index b66c787..dc104e6 100644 --- a/src/webengine/widgets/pagemenu.cpp +++ b/src/webengine/widgets/pagemenu.cpp @@ -9,8 +9,6 @@ #include "pagemenu.h" #include "../webview.h" #include "webengine/webprofile.h" -#include <QApplication> -#include <QClipboard> #include <QFileDialog> #include <QLabel> #include <QPrintDialog> @@ -22,35 +20,37 @@ #include <QWidgetAction> PageMenu::PageMenu(WebView *parent) - : QMenu(parent) + : QMenu(tr("Page"), parent) { setMinimumWidth(240); - auto *copyUrlAction = addAction(tr("Copy page URL")); - connect(copyUrlAction, &QAction::triggered, parent, [parent]() { - qApp->clipboard()->setText(parent->url().toString()); - parent->setFocus(); - }); - - auto *loadUrlAction = addAction(tr("Load URL")); - connect(loadUrlAction, &QAction::triggered, parent, [=]() { - parent->load(QUrl::fromUserInput(qApp->clipboard()->text())); - parent->setFocus(); + auto *bookmarkAction = addAction(tr("Bookmark page")); + connect(bookmarkAction, &QAction::triggered, parent, [parent]() { + parent->profile()->addBookmark(parent->title(), parent->url().toString()); }); - auto *searchAction = addAction(tr("Search")); - connect(searchAction, &QAction::triggered, parent, [=]() { - parent->search(qApp->clipboard()->text()); + auto *savePageAction = addAction(tr("Save Page")); + connect(savePageAction, &QAction::triggered, parent, [parent]() { + parent->triggerPageAction(QWebEnginePage::SavePage); }); - connect(this, &PageMenu::aboutToShow, this, [=]() { - loadUrlAction->setText(tr("Load URL: '%1'").arg(qApp->clipboard()->text())); - searchAction->setText(tr("Search: '%1'").arg(qApp->clipboard()->text())); + auto *printAction = addAction(tr("Print Page")); + connect(printAction, &QAction::triggered, parent, [parent]() { + auto *printer = new QPrinter(QPrinterInfo::defaultPrinter()); + auto *dlg = new QPrintDialog(printer, nullptr); + if(dlg->exec() == QDialog::Accepted) { + parent->page()->print(printer, [printer](bool success) { + qDebug("print %s", success ? "ok" : "failed"); + delete printer; + }); + } + delete dlg; }); - auto *bookmarkAction = addAction(tr("Bookmark page")); - connect(bookmarkAction, &QAction::triggered, parent, [parent]() { - parent->profile()->addBookmark(parent->title(), parent->url().toString()); + auto *printPdfAction = addAction(tr("Print to PDF")); + connect(printPdfAction, &QAction::triggered, parent, [parent]() { + const QString path = QFileDialog::getSaveFileName(parent, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)")); + parent->page()->printToPdf(path); }); addSeparator(); @@ -89,29 +89,4 @@ PageMenu::PageMenu(WebView *parent) } addAction(zoomWidgetAction); - addSeparator(); - - auto *savePageAction = addAction(tr("Save Page")); - connect(savePageAction, &QAction::triggered, parent, [parent]() { - parent->triggerPageAction(QWebEnginePage::SavePage); - }); - - auto *printAction = addAction(tr("Print Page")); - connect(printAction, &QAction::triggered, parent, [parent]() { - auto *printer = new QPrinter(QPrinterInfo::defaultPrinter()); - auto *dlg = new QPrintDialog(printer, nullptr); - if(dlg->exec() == QDialog::Accepted) { - parent->page()->print(printer, [printer](bool success) { - qDebug("print %s", success ? "ok" : "failed"); - delete printer; - }); - } - delete dlg; - }); - - auto *printPdfAction = addAction(tr("Print to PDF")); - connect(printPdfAction, &QAction::triggered, parent, [parent]() { - const QString path = QFileDialog::getSaveFileName(parent, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)")); - parent->page()->printToPdf(path); - }); } |