From 44e85dce678e7e36f436a6d0a25c212c9a2d3657 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Sat, 6 Jun 2020 23:07:45 +0200 Subject: A bit of redesign of the user interface, more convenience functions. --- mainwindow.cpp | 116 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 27 deletions(-) (limited to 'mainwindow.cpp') diff --git a/mainwindow.cpp b/mainwindow.cpp index 4b8d692..19dd922 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,7 +1,9 @@ #include "mainwindow.hpp" #include "ui_mainwindow.h" #include "browsertab.hpp" +#include "settingsdialog.hpp" +#include #include #include #include @@ -25,22 +27,39 @@ MainWindow::MainWindow(QWidget *parent) : this->ui->clientcert_window->setVisible(false); this->ui->bookmarks_window->setVisible(true); - - auto add_shortcut = [this](QString const & sequence, void (MainWindow::*fun)()) + for(QDockWidget * dock : findChildren()) { - auto * shortcut = new QShortcut(QKeySequence(sequence), this); - connect(shortcut, &QShortcut::activated, this, fun); - }; + QAction * act = this->ui->menuView ->addAction(dock->windowTitle()); + act->setCheckable(true); + act->setChecked(dock->isVisible()); + act->setData(QVariant::fromValue(dock)); + connect(act, QOverload::of(&QAction::triggered), dock, &QDockWidget::setVisible); + } + + connect(this->ui->menuView, &QMenu::aboutToShow, [this]() { + for(QAction * act : this->ui->menuView->actions()) + { + auto * dock = qvariant_cast(act->data()); + act->setChecked(dock->isVisible()); + } + }); - add_shortcut("Ctrl+T", &MainWindow::on_new_tab); - add_shortcut("Ctrl+W", &MainWindow::on_close_tab); - add_shortcut("F5", &MainWindow::on_refresh); - add_shortcut("Alt+Left", &MainWindow::on_nav_back); - add_shortcut("Alt+Right", &MainWindow::on_nav_forward); + + { + settings.beginGroup("Window State"); + if(settings.contains("geometry")) { + restoreGeometry(settings.value("geometry").toByteArray()); + } + if(settings.contains("state")) { + restoreState(settings.value("state").toByteArray()); + } + settings.endGroup(); + } } MainWindow::~MainWindow() { + this->saveSettings(); delete ui; } @@ -85,6 +104,15 @@ void MainWindow::saveSettings() { this->favourites.save(settings); this->current_style.save(settings); + + { + settings.beginGroup("Window State"); + + settings.setValue("geometry", saveGeometry()); + settings.setValue("state", saveState()); + + settings.endGroup(); + } } void MainWindow::on_browser_tabs_currentChanged(int index) @@ -147,20 +175,53 @@ void MainWindow::on_tab_locationChanged(const QUrl &url) } } -void MainWindow::on_new_tab() +void MainWindow::on_outline_view_clicked(const QModelIndex &index) { - this->addEmptyTab(true); + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + + auto anchor = tab->outline.getAnchor(index); + if(not anchor.isEmpty()) { + tab->scrollToAnchor(anchor); + } + } } -void MainWindow::on_refresh() +void MainWindow::on_actionSettings_triggered() { - BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); - if(tab != nullptr) { - // tab->reloadPage(); + SettingsDialog dialog; + + dialog.setGeminiStyle(this->current_style); + + if(dialog.exec() == QDialog::Accepted) { + this->current_style = dialog.geminiStyle(); + this->saveSettings(); } } -void MainWindow::on_close_tab() +void MainWindow::on_actionNew_Tab_triggered() +{ + this->addEmptyTab(true); +} + +void MainWindow::on_actionQuit_triggered() +{ + QApplication::quit(); +} + +void MainWindow::on_actionAbout_triggered() +{ + QMessageBox::about(this, + "Kristall", +R"about(Kristall, an OpenSource Gemini browser. +Made by Felix "xq" Queißner + +This is free software. You can get the source code at +https://github.com/MasterQ32/Kristall)about" + ); +} + +void MainWindow::on_actionClose_Tab_triggered() { BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); if(tab != nullptr) { @@ -168,30 +229,31 @@ void MainWindow::on_close_tab() } } -void MainWindow::on_nav_back() +void MainWindow::on_actionForward_triggered() { BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); if(tab != nullptr) { - tab->navOneBackback(); + tab->navOneForward(); } } -void MainWindow::on_nav_forward() +void MainWindow::on_actionBackward_triggered() { BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); if(tab != nullptr) { - tab->navOneForward(); + tab->navOneBackback(); } } -void MainWindow::on_outline_view_clicked(const QModelIndex &index) +void MainWindow::on_actionRefresh_triggered() { BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); if(tab != nullptr) { - - auto anchor = tab->outline.getAnchor(index); - if(not anchor.isEmpty()) { - tab->scrollToAnchor(anchor); - } + tab->reloadPage(); } } + +void MainWindow::on_actionAbout_Qt_triggered() +{ + QMessageBox::aboutQt(this, "Kristall"); +} -- cgit v1.2.3