diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-05 10:44:38 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-05 10:44:38 +0200 |
| commit | b917b6099ab8477488f0f352339aa6fca2235c36 (patch) | |
| tree | 1a29332613259a097dbbff2aa5fa78cdc05ab11d | |
| parent | da305e17be24b9db1c2014c6125399147ec404d9 (diff) | |
| download | kristall-b917b6099ab8477488f0f352339aa6fca2235c36.tar.gz | |
Starts to implement navigation history.
| -rw-r--r-- | browsertab.cpp | 9 | ||||
| -rw-r--r-- | browsertab.hpp | 4 | ||||
| -rw-r--r-- | kristall.pro | 6 | ||||
| -rw-r--r-- | mainwindow.cpp | 4 | ||||
| -rw-r--r-- | tabbrowsinghistory.cpp | 44 | ||||
| -rw-r--r-- | tabbrowsinghistory.hpp | 33 |
6 files changed, 92 insertions, 8 deletions
diff --git a/browsertab.cpp b/browsertab.cpp index d7c974b..357454f 100644 --- a/browsertab.cpp +++ b/browsertab.cpp @@ -180,7 +180,6 @@ void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime) auto * item = this->graphics_scene.addText("Failed to load picture!"); } - this->ui->graphics_browser->fitInView(graphics_scene.sceneRect(), Qt::KeepAspectRatio); } @@ -189,6 +188,8 @@ void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime) this->ui->text_browser->setText(QString("Unsupported Mime: %1").arg(mime)); } + this->pushToHistory(this->current_location); + this->successfully_loaded = true; this->updateUI(); } @@ -330,7 +331,7 @@ void BrowserTab::setErrorMessage(const QString &msg) void BrowserTab::pushToHistory(const QUrl &url) { - this->navigation_history.append(url); + this->history.pushUrl(url); this->updateUI(); } @@ -382,8 +383,8 @@ void BrowserTab::on_text_browser_highlighted(const QUrl &url) void BrowserTab::updateUI() { - // this->ui->back_button->setEnabled(this->navigation_history.size() > 0); - // this->ui->forward_button->setEnabled(false); + this->ui->back_button->setEnabled(this->history.canGoBack()); + this->ui->forward_button->setEnabled(this->history.canGoForward()); this->ui->refresh_button->setEnabled(this->successfully_loaded); diff --git a/browsertab.hpp b/browsertab.hpp index cb6c45a..d49e2fe 100644 --- a/browsertab.hpp +++ b/browsertab.hpp @@ -7,6 +7,7 @@ #include "geminiclient.hpp" #include "documentoutlinemodel.hpp" +#include "tabbrowsinghistory.hpp" namespace Ui { class BrowserTab; @@ -89,12 +90,11 @@ public: GeminiClient gemini_client; int redirection_count = 0; - QVector<QUrl> navigation_history; - bool successfully_loaded = false; DocumentOutlineModel outline; QGraphicsScene graphics_scene; + TabBrowsingHistory history; }; #endif // BROWSERTAB_HPP diff --git a/kristall.pro b/kristall.pro index bd03af0..156c40d 100644 --- a/kristall.pro +++ b/kristall.pro @@ -21,14 +21,16 @@ SOURCES += \ favouritecollection.cpp \ geminiclient.cpp \ main.cpp \ - mainwindow.cpp + mainwindow.cpp \ + tabbrowsinghistory.cpp HEADERS += \ browsertab.hpp \ documentoutlinemodel.hpp \ favouritecollection.hpp \ geminiclient.hpp \ - mainwindow.hpp + mainwindow.hpp \ + tabbrowsinghistory.hpp FORMS += \ browsertab.ui \ diff --git a/mainwindow.cpp b/mainwindow.cpp index ae29881..4936c4a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -71,11 +71,15 @@ void MainWindow::on_browser_tabs_currentChanged(int index) if(tab != nullptr) { this->ui->outline_view->setModel(&tab->outline); this->ui->outline_view->expandAll(); + + this->ui->history_view->setModel(&tab->history); } else { this->ui->outline_view->setModel(nullptr); + this->ui->history_view->setModel(nullptr); } } else { this->ui->outline_view->setModel(nullptr); + this->ui->history_view->setModel(nullptr); } } diff --git a/tabbrowsinghistory.cpp b/tabbrowsinghistory.cpp new file mode 100644 index 0000000..1a2d07f --- /dev/null +++ b/tabbrowsinghistory.cpp @@ -0,0 +1,44 @@ +#include "tabbrowsinghistory.hpp" + +TabBrowsingHistory::TabBrowsingHistory() +{ + +} + +bool TabBrowsingHistory::canGoBack() const +{ + return this->history.size() > 0; +} + +bool TabBrowsingHistory::canGoForward() const +{ + return false; +} + +void TabBrowsingHistory::pushUrl(const QUrl &url) +{ + this->beginInsertRows(QModelIndex{}, this->history.length(),this->history.length() + 1); + + this->history.push_back(url); + + this->endInsertRows(); +} + +int TabBrowsingHistory::rowCount(const QModelIndex &parent) const +{ + return history.size(); +} + +bool TabBrowsingHistory::setData(const QModelIndex &index, const QVariant &value, int role) +{ + return false; +} + +QVariant TabBrowsingHistory::data(const QModelIndex &index, int role) const +{ + if(role != Qt::DisplayRole) { + return QVariant{}; + } + return history.at(index.row()).toString(); +} + diff --git a/tabbrowsinghistory.hpp b/tabbrowsinghistory.hpp new file mode 100644 index 0000000..55e8354 --- /dev/null +++ b/tabbrowsinghistory.hpp @@ -0,0 +1,33 @@ +#ifndef TABBROWSINGHISTORY_HPP +#define TABBROWSINGHISTORY_HPP + +#include <QAbstractListModel> +#include <QVector> +#include <QUrl> + +class TabBrowsingHistory : + public QAbstractListModel +{ + Q_OBJECT +public: + TabBrowsingHistory(); + + bool canGoBack() const; + + bool canGoForward() const; + + void pushUrl(QUrl const & url); + +public: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + +private: + QVector<QUrl> history; +}; + +#endif // TABBROWSINGHISTORY_HPP |
