diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-18 20:24:11 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-18 11:23:23 +0100 |
| commit | 42813aa9ef1b6ada776cf0938ba02dad48a17422 (patch) | |
| tree | 71b65bc669b693cde7ba2b1be5ab1b7f14bcc283 /src | |
| parent | 415a5bd7b8288316b52338f359f5cd1280eff0bd (diff) | |
| download | kristall-42813aa9ef1b6ada776cf0938ba02dad48a17422.tar.gz | |
Add optional root/parent toolbar buttons
Diffstat (limited to 'src')
| -rw-r--r-- | src/browsertab.cpp | 50 | ||||
| -rw-r--r-- | src/browsertab.hpp | 10 | ||||
| -rw-r--r-- | src/browsertab.ui | 32 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.cpp | 12 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.hpp | 2 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.ui | 16 | ||||
| -rw-r--r-- | src/icons.qrc | 4 | ||||
| -rw-r--r-- | src/icons/dark/actions/go-top.svg | 4 | ||||
| -rw-r--r-- | src/icons/dark/actions/go-up.svg | 2 | ||||
| -rw-r--r-- | src/icons/light/actions/go-top.svg | 4 | ||||
| -rw-r--r-- | src/icons/light/actions/go-up.svg | 2 | ||||
| -rw-r--r-- | src/kristall.hpp | 6 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 25 |
14 files changed, 150 insertions, 23 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 997f10b..783b503 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -160,6 +160,8 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr), kristall::favourites.editFavouriteGroup(this->current_location, popup->fav_group->currentText()); }); + + refreshOptionalToolbarItems(); } BrowserTab::~BrowserTab() @@ -224,6 +226,33 @@ void BrowserTab::navOneForward() navigateBack(history.oneForward(current_history_index)); } +void BrowserTab::navigateToRoot() +{ + if(this->is_internal_location) return; + + QUrl url = this->current_location; + url.setPath("/"); + navigateTo(url, BrowserTab::PushImmediate); +} + +void BrowserTab::navigateToParent() +{ + if(this->is_internal_location) return; + + QUrl url = this->current_location; + + // Make sure we have a trailing slash, or else + // QUrl::resolved will not work + if (!url.path().endsWith("/")) + { + url.setPath(url.path() + "/"); + } + + // Go up one directory + url = url.resolved(QUrl{".."}); + navigateTo(url, BrowserTab::PushImmediate); +} + void BrowserTab::scrollToAnchor(QString const &anchor) { qDebug() << "scroll to anchor" << anchor; @@ -347,7 +376,17 @@ void BrowserTab::on_url_bar_blurred() void BrowserTab::on_refresh_button_clicked() { - reloadPage(); + this->reloadPage(); +} + +void BrowserTab::on_root_button_clicked() +{ + this->navigateToRoot(); +} + +void BrowserTab::on_parent_button_clicked() +{ + this->navigateToParent(); } void BrowserTab::on_networkError(ProtocolHandler::NetworkError error_code, const QString &reason) @@ -1232,8 +1271,6 @@ void BrowserTab::updateUI() this->ui->back_button->setEnabled(history.oneBackward(current_history_index).isValid()); this->ui->forward_button->setEnabled(history.oneForward(current_history_index).isValid()); - this->ui->home_button->setVisible(kristall::options.enable_home_btn); - bool in_progress = (this->current_handler != nullptr) and this->current_handler->isInProgress(); this->ui->refresh_button->setVisible(not in_progress); @@ -1374,6 +1411,13 @@ void BrowserTab::updatePageMargins() this->ui->text_browser->setDocument(this->current_document.get()); } +void BrowserTab::refreshOptionalToolbarItems() +{ + this->ui->home_button->setVisible(kristall::options.enable_home_btn); + this->ui->root_button->setVisible(kristall::options.enable_root_btn); + this->ui->parent_button->setVisible(kristall::options.enable_parent_btn); +} + bool BrowserTab::trySetClientCertificate(const QString &query) { CertificateSelectionDialog dialog{this}; diff --git a/src/browsertab.hpp b/src/browsertab.hpp index bce1f76..355aa8d 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -75,6 +75,10 @@ public: void navOneForward(); + void navigateToRoot(); + + void navigateToParent(); + void scrollToAnchor(QString const & anchor); void reloadPage(); @@ -103,6 +107,8 @@ public: void updatePageMargins(); + void refreshOptionalToolbarItems(); + signals: void titleChanged(QString const & title); void locationChanged(QUrl const & url); @@ -120,6 +126,10 @@ private slots: void on_refresh_button_clicked(); + void on_root_button_clicked(); + + void on_parent_button_clicked(); + void on_fav_button_clicked(); void on_text_browser_anchorClicked(const QUrl &arg1, bool open_in_new_tab); diff --git a/src/browsertab.ui b/src/browsertab.ui index 8454735..7db1862 100644 --- a/src/browsertab.ui +++ b/src/browsertab.ui @@ -112,6 +112,38 @@ </widget> </item> <item> + <widget class="QToolButton" name="root_button"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Go the root path of current location</string> + </property> + <property name="text"> + <string>/</string> + </property> + <property name="icon"> + <iconset theme="go-top"/> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="parent_button"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Go the parent path of current location</string> + </property> + <property name="text"> + <string>P</string> + </property> + <property name="icon"> + <iconset theme="go-up"/> + </property> + </widget> + </item> + <item> <widget class="SearchBar" name="url_bar"> <property name="placeholderText"> <string>gemini://</string> diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp index b943a56..f441824 100644 --- a/src/dialogs/settingsdialog.cpp +++ b/src/dialogs/settingsdialog.cpp @@ -297,6 +297,8 @@ void SettingsDialog::setOptions(const GenericSettings &options) this->ui->enable_home_btn->setChecked(this->current_options.enable_home_btn); this->ui->enable_newtab_btn->setChecked(this->current_options.enable_newtab_btn); + this->ui->enable_root_btn->setChecked(this->current_options.enable_root_btn); + this->ui->enable_parent_btn->setChecked(this->current_options.enable_parent_btn); this->ui->cache_limit->setValue(this->current_options.cache_limit); this->ui->cache_threshold->setValue(this->current_options.cache_threshold); @@ -825,6 +827,16 @@ void SettingsDialog::on_enable_newtab_btn_clicked(bool checked) this->current_options.enable_newtab_btn = checked; } +void SettingsDialog::on_enable_root_btn_clicked(bool checked) +{ + this->current_options.enable_root_btn = checked; +} + +void SettingsDialog::on_enable_parent_btn_clicked(bool checked) +{ + this->current_options.enable_parent_btn = checked; +} + void SettingsDialog::on_cache_limit_valueChanged(int limit) { this->current_options.cache_limit = limit; diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp index 80afcc6..67612c8 100644 --- a/src/dialogs/settingsdialog.hpp +++ b/src/dialogs/settingsdialog.hpp @@ -153,6 +153,8 @@ private slots: void on_enable_home_btn_clicked(bool arg1); void on_enable_newtab_btn_clicked(bool arg1); + void on_enable_root_btn_clicked(bool arg1); + void on_enable_parent_btn_clicked(bool arg1); void on_cache_limit_valueChanged(int limit); void on_cache_threshold_valueChanged(int thres); diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui index c32489c..c5e65ba 100644 --- a/src/dialogs/settingsdialog.ui +++ b/src/dialogs/settingsdialog.ui @@ -433,6 +433,20 @@ </widget> </item> <item> + <widget class="QCheckBox" name="enable_root_btn"> + <property name="text"> + <string>Root (/)</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="enable_parent_btn"> + <property name="text"> + <string>Parent (..)</string> + </property> + </widget> + </item> + <item> <widget class="QCheckBox" name="enable_newtab_btn"> <property name="text"> <string>New tab</string> @@ -1436,6 +1450,8 @@ <tabstop>network_timeout</tabstop> <tabstop>enable_home_btn</tabstop> <tabstop>enable_newtab_btn</tabstop> + <tabstop>enable_root_btn</tabstop> + <tabstop>enable_parent_btn</tabstop> <tabstop>cache_limit</tabstop> <tabstop>cache_threshold</tabstop> <tabstop>cache_life</tabstop> diff --git a/src/icons.qrc b/src/icons.qrc index efee842..a9be58b 100644 --- a/src/icons.qrc +++ b/src/icons.qrc @@ -21,6 +21,8 @@ <file>icons/light/actions/edit-delete.svg</file> <file>icons/light/actions/go-previous.svg</file> <file>icons/light/actions/go-next.svg</file> + <file>icons/light/actions/go-up.svg</file> + <file>icons/light/actions/go-top.svg</file> <file>icons/light/actions/media-playback-pause.svg</file> <file>icons/light/actions/media-playback-start.svg</file> <file>icons/light/actions/view-refresh.svg</file> @@ -56,6 +58,8 @@ <file>icons/dark/actions/edit-delete.svg</file> <file>icons/dark/actions/go-previous.svg</file> <file>icons/dark/actions/go-next.svg</file> + <file>icons/dark/actions/go-up.svg</file> + <file>icons/dark/actions/go-top.svg</file> <file>icons/dark/actions/media-playback-pause.svg</file> <file>icons/dark/actions/media-playback-start.svg</file> <file>icons/dark/actions/view-refresh.svg</file> diff --git a/src/icons/dark/actions/go-top.svg b/src/icons/dark/actions/go-top.svg new file mode 100644 index 0000000..1137086 --- /dev/null +++ b/src/icons/dark/actions/go-top.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> + <path d="m8 20 2 0.8 7-17-2-0.8z" fill="#fff" stroke-width=".8"/> +</svg> diff --git a/src/icons/dark/actions/go-up.svg b/src/icons/dark/actions/go-up.svg new file mode 100644 index 0000000..4f42a70 --- /dev/null +++ b/src/icons/dark/actions/go-up.svg @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m11 20h2v-12l6 6 1-1-8-8-8 8 1 1 6-6z"/><path d="m11 14v-6l-6 6-1-1 8-8 8 8-1 1-6-6v12h-2z" fill="#fff" stroke-width=".03"/><path d="m11 14v-6l-6 6-1-1 8-8 8 8-1 1-6-6v12h-2z" fill="#fff" stroke-width=".03"/></svg> diff --git a/src/icons/light/actions/go-top.svg b/src/icons/light/actions/go-top.svg new file mode 100644 index 0000000..593235f --- /dev/null +++ b/src/icons/light/actions/go-top.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> + <path d="m8 20 2 0.8 7-17-2-0.8z" stroke-width=".8"/> +</svg> diff --git a/src/icons/light/actions/go-up.svg b/src/icons/light/actions/go-up.svg new file mode 100644 index 0000000..0178769 --- /dev/null +++ b/src/icons/light/actions/go-up.svg @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m11 20h2v-12l6 6 1-1-8-8-8 8 1 1 6-6z"/><path d="m11 14v-6l-6 6-1-1 8-8 8 8-1 1-6-6v12h-2z" stroke-width=".03"/><path d="m11 14v-6l-6 6-1-1 8-8 8 8-1 1-6-6v12h-2z" stroke-width=".03"/></svg> diff --git a/src/kristall.hpp b/src/kristall.hpp index 1717d71..6147aac 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -80,8 +80,10 @@ struct GenericSettings int network_timeout = 5000; // Additional toolbar items - bool enable_home_btn = false; - bool enable_newtab_btn = true; + bool enable_home_btn = false, + enable_newtab_btn = true, + enable_root_btn = false, + enable_parent_btn = false; // In-memory caching int cache_limit = 1000; diff --git a/src/main.cpp b/src/main.cpp index 6fb5280..476a333 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -380,6 +380,8 @@ void GenericSettings::load(QSettings &settings) enable_home_btn = settings.value("enable_home_btn", false).toBool(); enable_newtab_btn = settings.value("enable_newtab_btn", true).toBool(); + enable_root_btn = settings.value("enable_root_btn", false).toBool(); + enable_parent_btn = settings.value("enable_parent_btn", false).toBool(); cache_limit = settings.value("cache_limit", 1000).toInt(); cache_threshold = settings.value("cache_threshold", 125).toInt(); @@ -426,6 +428,8 @@ void GenericSettings::save(QSettings &settings) const settings.setValue("network_timeout", network_timeout); settings.setValue("enable_home_btn", enable_home_btn); settings.setValue("enable_newtab_btn", enable_newtab_btn); + settings.setValue("enable_root_btn", enable_root_btn); + settings.setValue("enable_parent_btn", enable_parent_btn); settings.setValue("cache_limit", cache_limit); settings.setValue("cache_threshold", cache_threshold); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3008c0b..2851c84 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -436,7 +436,9 @@ void MainWindow::on_actionSettings_triggered() // changes are instantly applied. for (int i = 0; i < this->ui->browser_tabs->count(); ++i) { - this->tabAt(i)->needs_rerender = true; + BrowserTab *t = this->tabAt(i); + t->refreshOptionalToolbarItems(); + t->needs_rerender = true; } // Re-render the currently-open tab if we have one. BrowserTab * tab = this->curTab(); @@ -496,29 +498,16 @@ void MainWindow::on_actionBackward_triggered() void MainWindow::on_actionRoot_triggered() { BrowserTab * tab = this->curTab(); - if(tab != nullptr && !tab->is_internal_location) { - QUrl url = tab->current_location; - url.setPath("/"); - tab->navigateTo(url, BrowserTab::PushImmediate); + if(tab != nullptr) { + tab->navigateToRoot(); } } void MainWindow::on_actionParent_triggered() { BrowserTab * tab = this->curTab(); - if(tab != nullptr && !tab->is_internal_location) { - QUrl url = tab->current_location; - - // Make sure we have a trailing slash, or else - // QUrl::resolved will not work - if (!url.path().endsWith("/")) - { - url.setPath(url.path() + "/"); - } - - // Go up one directory - url = url.resolved(QUrl{".."}); - tab->navigateTo(url, BrowserTab::PushImmediate); + if(tab != nullptr) { + tab->navigateToParent(); } } |
