From edbd2707620bd0d948bc71a554ec35d63b995e45 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Thu, 31 Dec 2020 11:26:14 +1100 Subject: #51: mouse buttons 4/5 for back/forward --- src/browsertab.cpp | 4 ++-- src/browsertab.hpp | 2 +- src/mainwindow.cpp | 23 ++++++++++++++++++++++- src/mainwindow.hpp | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 15c4686..65fde7f 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -155,7 +155,7 @@ void BrowserTab::navigateBack(const QModelIndex &history_index) } } -void BrowserTab::navOneBackback() +void BrowserTab::navOneBackward() { navigateBack(history.oneBackward(current_history_index)); } @@ -1039,7 +1039,7 @@ void BrowserTab::on_requestProgress(qint64 transferred) void BrowserTab::on_back_button_clicked() { - navOneBackback(); + navOneBackward(); } void BrowserTab::on_forward_button_clicked() diff --git a/src/browsertab.hpp b/src/browsertab.hpp index 6ff1e55..4e7b627 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -55,7 +55,7 @@ public: void navigateBack(const QModelIndex &history_index); - void navOneBackback(); + void navOneBackward(); void navOneForward(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b88751c..622af0a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "ioutil.hpp" #include "kristall.hpp" @@ -160,6 +161,26 @@ void MainWindow::updateWindowTitle() this->setWindowTitle(QString("%0 - %1").arg(tab->page_title, "Kristall")); } +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + QMainWindow::mousePressEvent(event); + + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if (tab == nullptr) return; + + // Navigate back/forward on mouse buttons 4/5 + if (event->buttons() == Qt::ForwardButton && + tab->history.oneForward(tab->current_history_index).isValid()) + { + tab->navOneForward(); + } + else if (event->buttons() == Qt::BackButton && + tab->history.oneBackward(tab->current_history_index).isValid()) + { + tab->navOneBackward(); + } +} + void MainWindow::on_browser_tabs_currentChanged(int index) { if(index >= 0) { @@ -327,7 +348,7 @@ void MainWindow::on_actionBackward_triggered() { BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); if(tab != nullptr) { - tab->navOneBackback(); + tab->navOneBackward(); } } diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 58c6c3e..6a1dce7 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -36,6 +36,8 @@ public: void updateWindowTitle(); + void mousePressEvent(QMouseEvent *event) override; + private slots: void on_browser_tabs_currentChanged(int index); -- cgit v1.2.3