diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-06 23:07:45 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-06 23:07:45 +0200 |
| commit | 44e85dce678e7e36f436a6d0a25c212c9a2d3657 (patch) | |
| tree | 30dcc4eb5dfca0c50830443a8d68bec83dc06d7c | |
| parent | d9e105e6e0accf5def8681334341069117cab213 (diff) | |
| download | kristall-44e85dce678e7e36f436a6d0a25c212c9a2d3657.tar.gz | |
A bit of redesign of the user interface, more convenience functions.
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | browsertab.cpp | 40 | ||||
| -rw-r--r-- | browsertab.hpp | 5 | ||||
| -rw-r--r-- | browsertab.ui | 11 | ||||
| -rw-r--r-- | icons.qrc | 1 | ||||
| -rw-r--r-- | icons/settings.svg | 1 | ||||
| -rw-r--r-- | mainwindow.cpp | 116 | ||||
| -rw-r--r-- | mainwindow.hpp | 20 | ||||
| -rw-r--r-- | mainwindow.ui | 122 | ||||
| -rw-r--r-- | settingsdialog.ui | 2 |
10 files changed, 235 insertions, 85 deletions
@@ -10,7 +10,7 @@ A high-quality visual cross-platform gemini browser. - `text/markdown` - `text/*` - `image/*` -- [Outline generation](https://mq32.de/public/a50ef327f4150d870393b1989c5b41db495b56f7.png) +- [Outline generation](https://mq32.de/public/a50ef327f4150d870393b1989c5b41db495b56f7.png) ([Video](https://mq32.de/public/kristall-02.mp4)) - Favourite Sites - Tabbed interface - Survives [ConMans torture suite](gemini://gemini.conman.org/test/torture/) diff --git a/browsertab.cpp b/browsertab.cpp index e81dc39..f7e5f78 100644 --- a/browsertab.cpp +++ b/browsertab.cpp @@ -41,7 +41,6 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : this->ui->text_browser->setVisible(false); this->ui->graphics_browser->setScene(&graphics_scene); - } BrowserTab::~BrowserTab() @@ -110,40 +109,10 @@ void BrowserTab::scrollToAnchor(QString const & anchor) this->ui->text_browser->scrollToAnchor(anchor); } -void BrowserTab::on_menu_button_clicked() +void BrowserTab::reloadPage() { - QMenu menu; - connect(menu.addAction("Open Empty Tab"), &QAction::triggered, mainWindow, &MainWindow::addEmptyTab); - - QMenu * view_menu = menu.addMenu("View"); - { - QList<QDockWidget *> dockWidgets = mainWindow->findChildren<QDockWidget *>(); - - for(QDockWidget * dock : dockWidgets) - { - QAction * act = view_menu ->addAction(dock->windowTitle()); - act->setCheckable(true); - act->setChecked(dock->isVisible()); - - connect(act, QOverload<bool>::of(&QAction::triggered), dock, &QDockWidget::setVisible); - } - } - - connect(menu.addAction("Settings..."), &QAction::triggered, [this]() { - SettingsDialog dialog; - - dialog.setGeminiStyle(mainWindow->current_style); - - if(dialog.exec() == QDialog::Accepted) { - mainWindow->current_style = dialog.geminiStyle(); - - mainWindow->saveSettings(); - } - }); - - - connect(menu.addAction("Quit"), &QAction::triggered, &QApplication::quit); - menu.exec(QCursor::pos()); + if(current_location.isValid()) + this->navigateTo(this->current_location, DontPush); } void BrowserTab::on_url_bar_returnPressed() @@ -159,8 +128,7 @@ void BrowserTab::on_url_bar_returnPressed() void BrowserTab::on_refresh_button_clicked() { - if(current_location.isValid()) - this->navigateTo(this->current_location, DontPush); + reloadPage(); } void BrowserTab::on_gemini_complete(const QByteArray &data, const QString &mime) diff --git a/browsertab.hpp b/browsertab.hpp index 44e47b7..7f0ac35 100644 --- a/browsertab.hpp +++ b/browsertab.hpp @@ -41,20 +41,19 @@ public: void scrollToAnchor(QString const & anchor); + void reloadPage(); + signals: void titleChanged(QString const & title); void locationChanged(QUrl const & url); private slots: - void on_menu_button_clicked(); - void on_url_bar_returnPressed(); void on_refresh_button_clicked(); void on_gemini_complete(QByteArray const & data, QString const & mime); - void on_protocolViolation(QString const & reason); void on_inputRequired(QString const & query); diff --git a/browsertab.ui b/browsertab.ui index 6207711..265560e 100644 --- a/browsertab.ui +++ b/browsertab.ui @@ -130,17 +130,6 @@ </property> </widget> </item> - <item> - <widget class="QToolButton" name="menu_button"> - <property name="text"> - <string>...</string> - </property> - <property name="icon"> - <iconset resource="icons.qrc"> - <normaloff>:/icons/menu.svg</normaloff>:/icons/menu.svg</iconset> - </property> - </widget> - </item> </layout> </item> <item> @@ -10,5 +10,6 @@ <file>icons/format-font.svg</file> <file>icons/palette.svg</file> <file>icons/kristall.svg</file> + <file>icons/settings.svg</file> </qresource> </RCC> diff --git a/icons/settings.svg b/icons/settings.svg new file mode 100644 index 0000000..731a5a7 --- /dev/null +++ b/icons/settings.svg @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z" /></svg>
\ No newline at end of file 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 <QMessageBox> #include <memory> #include <QShortcut> #include <QKeySequence> @@ -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<QDockWidget *>()) { - 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<bool>::of(&QAction::triggered), dock, &QDockWidget::setVisible); + } + + connect(this->ui->menuView, &QMenu::aboutToShow, [this]() { + for(QAction * act : this->ui->menuView->actions()) + { + auto * dock = qvariant_cast<QDockWidget*>(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<BrowserTab*>(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<BrowserTab*>(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<BrowserTab*>(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<BrowserTab*>(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<BrowserTab*>(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<BrowserTab*>(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"); +} diff --git a/mainwindow.hpp b/mainwindow.hpp index dd901e3..41b6e2c 100644 --- a/mainwindow.hpp +++ b/mainwindow.hpp @@ -46,17 +46,25 @@ private slots: void on_tab_locationChanged(QUrl const & url); - void on_new_tab(); + void on_outline_view_clicked(const QModelIndex &index); - void on_refresh(); + void on_actionSettings_triggered(); - void on_close_tab(); + void on_actionNew_Tab_triggered(); - void on_nav_back(); + void on_actionQuit_triggered(); - void on_nav_forward(); + void on_actionAbout_triggered(); - void on_outline_view_clicked(const QModelIndex &index); + void on_actionClose_Tab_triggered(); + + void on_actionForward_triggered(); + + void on_actionBackward_triggered(); + + void on_actionRefresh_triggered(); + + void on_actionAbout_Qt_triggered(); public: QSettings settings; diff --git a/mainwindow.ui b/mainwindow.ui index 04e6940..08ba787 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -179,6 +179,128 @@ </layout> </widget> </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>20</height> + </rect> + </property> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>File</string> + </property> + <addaction name="actionNew_Tab"/> + <addaction name="actionClose_Tab"/> + <addaction name="separator"/> + <addaction name="actionSettings"/> + <addaction name="separator"/> + <addaction name="actionQuit"/> + </widget> + <widget class="QMenu" name="menuHelp"> + <property name="title"> + <string>Help</string> + </property> + <addaction name="actionAbout"/> + <addaction name="actionAbout_Qt"/> + </widget> + <widget class="QMenu" name="menuView"> + <property name="title"> + <string>View</string> + </property> + </widget> + <widget class="QMenu" name="menuNavigation"> + <property name="title"> + <string>Navigation</string> + </property> + <addaction name="actionBackward"/> + <addaction name="actionForward"/> + <addaction name="separator"/> + <addaction name="actionRefresh"/> + </widget> + <addaction name="menuFile"/> + <addaction name="menuNavigation"/> + <addaction name="menuView"/> + <addaction name="menuHelp"/> + </widget> + <action name="actionAbout"> + <property name="text"> + <string>About...</string> + </property> + </action> + <action name="actionQuit"> + <property name="text"> + <string>Quit</string> + </property> + </action> + <action name="actionNew_Tab"> + <property name="text"> + <string>New Tab</string> + </property> + <property name="shortcut"> + <string>Ctrl+T</string> + </property> + </action> + <action name="actionClose_Tab"> + <property name="text"> + <string>Close Tab</string> + </property> + <property name="shortcut"> + <string>Ctrl+W</string> + </property> + </action> + <action name="actionSettings"> + <property name="icon"> + <iconset resource="icons.qrc"> + <normaloff>:/icons/settings.svg</normaloff>:/icons/settings.svg</iconset> + </property> + <property name="text"> + <string>Settings</string> + </property> + </action> + <action name="actionBackward"> + <property name="icon"> + <iconset resource="icons.qrc"> + <normaloff>:/icons/arrow-left.svg</normaloff>:/icons/arrow-left.svg</iconset> + </property> + <property name="text"> + <string>Backward</string> + </property> + <property name="shortcut"> + <string>Alt+Left</string> + </property> + </action> + <action name="actionForward"> + <property name="icon"> + <iconset resource="icons.qrc"> + <normaloff>:/icons/arrow-right.svg</normaloff>:/icons/arrow-right.svg</iconset> + </property> + <property name="text"> + <string>Forward</string> + </property> + <property name="shortcut"> + <string>Alt+Right</string> + </property> + </action> + <action name="actionRefresh"> + <property name="icon"> + <iconset resource="icons.qrc"> + <normaloff>:/icons/refresh.svg</normaloff>:/icons/refresh.svg</iconset> + </property> + <property name="text"> + <string>Refresh</string> + </property> + <property name="shortcut"> + <string>F5</string> + </property> + </action> + <action name="actionAbout_Qt"> + <property name="text"> + <string>About Qt...</string> + </property> + </action> </widget> <resources> <include location="icons.qrc"/> diff --git a/settingsdialog.ui b/settingsdialog.ui index d30b049..aee3959 100644 --- a/settingsdialog.ui +++ b/settingsdialog.ui @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Settings</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> |
