diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-04-03 11:43:12 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-04-03 11:43:12 +0200 |
commit | c90f5caef1a8302f064b600410c6f43d6351457d (patch) | |
tree | 5dfc629b0be63e99e49531778b115ef25a6eb769 /src | |
parent | Updated pre-commit.rb (diff) | |
download | smolbote-c90f5caef1a8302f064b600410c6f43d6351457d.tar.xz |
Added page action tool buttons
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 23 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.cpp | 13 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.h | 7 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 76e4a54..307835c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -29,6 +29,9 @@ #include <QStatusBar> #include "forms/aboutdialog.h" +#include <QToolButton> +#include <QStyle> + MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : QMainWindow(parent), blocklistManager(new BlockerManager(this)), @@ -41,10 +44,13 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : { // set up UI ui->setupUi(this); + + // Dockable widget styling setDockOptions(dockOptions() | AllowTabbedDocks | ForceTabbedDocks); setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); + // Main menu QMenuBar *menuBar = new QMenuBar(this); menuBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); @@ -88,6 +94,23 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : // navigationToolBar: address bar navigationToolBar->setMovable(sSettings->value("window.ui.navtoolbarMovable", true).toBool()); + + // page actions + QToolButton *backButton = new QToolButton(this); + backButton->setIcon(style()->standardIcon(QStyle::SP_ArrowBack)); + connect(backButton, SIGNAL(clicked()), tabBar->signalMapper(), SLOT(map())); + tabBar->signalMapper()->setMapping(backButton, QWebEnginePage::Back); + QToolButton *forwardButton = new QToolButton(this); + forwardButton->setIcon(style()->standardIcon(QStyle::SP_ArrowForward)); + connect(forwardButton, SIGNAL(clicked()), tabBar->signalMapper(), SLOT(map())); + tabBar->signalMapper()->setMapping(forwardButton, QWebEnginePage::Forward); + QToolButton *reloadButton = new QToolButton(this); + reloadButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload)); + connect(reloadButton, SIGNAL(clicked()), tabBar->signalMapper(), SLOT(map())); + tabBar->signalMapper()->setMapping(reloadButton, QWebEnginePage::Reload); + navigationToolBar->addWidget(backButton); + navigationToolBar->addWidget(forwardButton); + navigationToolBar->addWidget(reloadButton); navigationToolBar->addWidget(urlLineEdit); this->addToolBar(Qt::TopToolBarArea, navigationToolBar); diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index 71d3c92..9684e11 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -56,6 +56,9 @@ WebViewTabBar::WebViewTabBar(QWidget *parent) : }); addAction(tabRightAction); } + + m_signalMapper = new QSignalMapper(this); + connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(webAction(int))); } WebViewTabBar::~WebViewTabBar() @@ -65,6 +68,11 @@ WebViewTabBar::~WebViewTabBar() m_views.clear(); } +QSignalMapper *WebViewTabBar::signalMapper() +{ + return m_signalMapper; +} + int WebViewTabBar::addTab(QWebEngineProfile *profile, const QUrl &url) { WebView *view = new WebView(0); @@ -132,3 +140,8 @@ void WebViewTabBar::updateVectorArrangement(int from, int to) { m_views.move(from, to); } + +void WebViewTabBar::webAction(int action) +{ + currentView()->pageAction(static_cast<QWebEnginePage::WebAction>(action))->trigger(); +} diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h index f7772e0..bf39efe 100644 --- a/src/widgets/webviewtabbar.h +++ b/src/widgets/webviewtabbar.h @@ -23,6 +23,7 @@ #include <QTabBar> #include "webengine/webview.h" +#include <QSignalMapper> class WebViewTabBar : public QTabBar { @@ -33,6 +34,8 @@ public: ~WebViewTabBar(); void setProfile(QWebEngineProfile *profile); + + QSignalMapper *signalMapper(); WebView *currentView(); signals: @@ -42,6 +45,8 @@ public slots: int addTab(QWebEngineProfile *profile, const QUrl &url); void removeTab(int index); + void webAction(int action); + protected: QSize tabSizeHint(int index) const; @@ -54,6 +59,8 @@ private slots: private: // store all views in a vector since tabs can only store a QVariant, and that can't easily take a pointer QVector<WebView*> m_views; + + QSignalMapper *m_signalMapper; }; #endif // WEBVIEWTABBAR_H |