aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow')
-rw-r--r--src/mainwindow/mainwindow.cpp61
-rw-r--r--src/mainwindow/mainwindow.h5
-rw-r--r--src/mainwindow/mainwindow.ui37
3 files changed, 98 insertions, 5 deletions
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 <webprofile.h>
#include "session.h"
#include <QFileDialog>
+#include <QPrinter>
+#include <QPrinterInfo>
+#include <QPrintDialog>
+#include "profilemanager.h"
#ifdef PLASMA_BLUR
#include <KWindowEffects>
@@ -116,6 +120,38 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &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<bool>("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<Browser *>(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<SubWindow *> 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<Configuration> &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 @@
<string>Too&amp;ls</string>
</property>
</widget>
+ <widget class="QMenu" name="menuPage">
+ <property name="title">
+ <string>Pa&amp;ge</string>
+ </property>
+ <addaction name="actionBookmarkPage"/>
+ <addaction name="actionSavePage"/>
+ <addaction name="actionPrintPage"/>
+ <addaction name="actionPrintPageToPdf"/>
+ <addaction name="separator"/>
+ </widget>
<addaction name="menusmolbote"/>
<addaction name="menuSession"/>
<addaction name="menuWindow"/>
+ <addaction name="menuPage"/>
<addaction name="menuTools"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
@@ -99,17 +110,37 @@
</action>
<action name="actionTileWindows">
<property name="text">
- <string>Tile Windows</string>
+ <string>&amp;Tile Windows</string>
</property>
</action>
<action name="actionCascadeWindows">
<property name="text">
- <string>Cascade Windows</string>
+ <string>&amp;Cascade Windows</string>
</property>
</action>
<action name="actionCurrentWindow">
<property name="text">
- <string>Current Window</string>
+ <string>Current &amp;Window</string>
+ </property>
+ </action>
+ <action name="actionBookmarkPage">
+ <property name="text">
+ <string>&amp;Create Bookmark</string>
+ </property>
+ </action>
+ <action name="actionSavePage">
+ <property name="text">
+ <string>&amp;Save Page</string>
+ </property>
+ </action>
+ <action name="actionPrintPage">
+ <property name="text">
+ <string>&amp;Print Page</string>
+ </property>
+ </action>
+ <action name="actionPrintPageToPdf">
+ <property name="text">
+ <string>P&amp;rint to PDF</string>
</property>
</action>
</widget>