From fc4c7943c79243ed027f7507c458d067a14bebb2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 8 Jul 2018 11:10:48 +0200 Subject: Remove PageMenu Move zoom widget to WebView context menu Move the other page menu actions to main window menu --- src/mainwindow/mainwindow.cpp | 61 +++++++++++++++++++++++++++++++++++++++++-- src/mainwindow/mainwindow.h | 5 ++++ src/mainwindow/mainwindow.ui | 37 +++++++++++++++++++++++--- 3 files changed, 98 insertions(+), 5 deletions(-) (limited to 'src/mainwindow') diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 741b544..ff8c911 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -32,6 +32,10 @@ #include #include "session.h" #include +#include +#include +#include +#include "profilemanager.h" #ifdef PLASMA_BLUR #include @@ -116,6 +120,38 @@ MainWindow::MainWindow(const std::unique_ptr &config, QWidget *pa subWindowAction = ui->actionCurrentWindow; } + // connect page menu + { + connect(ui->actionBookmarkPage, &QAction::triggered, this, [this]() { + if(currentView != nullptr) + emit createBookmark(currentView->title(), currentView->url().toString()); + }); + connect(ui->actionSavePage, &QAction::triggered, this, [this]() { + if(currentView != nullptr) + currentView->triggerPageAction(QWebEnginePage::SavePage); + }); + connect(ui->actionPrintPage, &QAction::triggered, this, [this]() { + if(currentView != nullptr) { + auto *printer = new QPrinter(QPrinterInfo::defaultPrinter()); + QPrintDialog dlg(printer, this); + if(dlg.exec() == QDialog::Accepted) { + currentView->page()->print(printer, [printer](bool success) { + delete printer; + }); + } + } + }); + connect(ui->actionPrintPageToPdf, &QAction::triggered, this, [this]() { + if(currentView != nullptr) { + const QString path = QFileDialog::getSaveFileName(this, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)")); + currentView->page()->printToPdf(path); + } + }); + + pageLoadProfileMenu = ui->menuPage->addMenu(tr("Load Profile")); + connect(pageLoadProfileMenu, &QMenu::aboutToShow, this, &MainWindow::updatePageLoadProfileMenu); + } + navigationToolBar = new NavigationBar(config->section("navigation"), this); navigationToolBar->setMovable(config->value("navigation.movable").value()); addToolBar(Qt::TopToolBarArea, navigationToolBar); @@ -290,7 +326,6 @@ void MainWindow::setView(WebView *view) currentView = view; if(view) { - addressBar->setPageMenu(view->pageMenu()); addressBar->setToolsMenu(view->toolsMenu()); connect(view, &WebView::urlChanged, addressBar, &AddressBar::setUrl); @@ -300,7 +335,6 @@ void MainWindow::setView(WebView *view) addressBar->setProgress(100); } else { - addressBar->setPageMenu(nullptr); addressBar->setToolsMenu(nullptr); addressBar->setUrl(QUrl()); @@ -311,6 +345,29 @@ void MainWindow::setView(WebView *view) searchBox->setView(view); } +void MainWindow::updatePageLoadProfileMenu() +{ + Q_CHECK_PTR(pageLoadProfileMenu); + pageLoadProfileMenu->clear(); + + if(currentView == nullptr) + return; + + auto *browser = qobject_cast(qApp); + Q_CHECK_PTR(browser); + + ProfileIterator it(ProfileManager::profileList()); + while(it.hasNext()) { + it.next(); + auto *profile = it.value(); + auto *loadAction = pageLoadProfileMenu->addAction(profile->name()); + + connect(loadAction, &QAction::triggered, this, [=]() { + currentView->setProfile(profile); + }); + } +} + void MainWindow::closeEvent(QCloseEvent *event) { if(mdiArea->subWindowList().count() > 1) { diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index d695dd8..3768348 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -49,12 +49,16 @@ public: const QVector subWindows() const; SubWindow *currentSubWindow() const; +signals: + void createBookmark(const QString &title, const QString &url); + public slots: void createTab(const QUrl &url); SubWindow *createSubWindow(const std::unique_ptr &config, WebProfile *profile); private slots: void setView(WebView *view); + void updatePageLoadProfileMenu(); protected: void closeEvent(QCloseEvent *event) override; @@ -63,6 +67,7 @@ private: Ui::MainWindow *ui; QAction *subWindowAction = nullptr; QMenu *toolsMenu = nullptr; + QMenu *pageLoadProfileMenu = nullptr; NavigationBar *navigationToolBar = nullptr; AddressBar *addressBar = nullptr; diff --git a/src/mainwindow/mainwindow.ui b/src/mainwindow/mainwindow.ui index 72e0b39..698e1c4 100644 --- a/src/mainwindow/mainwindow.ui +++ b/src/mainwindow/mainwindow.ui @@ -56,9 +56,20 @@ Too&ls + + + Pa&ge + + + + + + + + @@ -99,17 +110,37 @@ - Tile Windows + &Tile Windows - Cascade Windows + &Cascade Windows - Current Window + Current &Window + + + + + &Create Bookmark + + + + + &Save Page + + + + + &Print Page + + + + + P&rint to PDF -- cgit v1.2.1