diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/mainwindow/widgets/navigationbar.cpp | 37 | ||||
-rw-r--r-- | src/mainwindow/widgets/navigationbar.h | 4 | ||||
-rw-r--r-- | src/util.cpp | 23 | ||||
-rw-r--r-- | src/util.h | 3 |
5 files changed, 43 insertions, 26 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 9e6f187..1544e79 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -199,7 +199,7 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa }); } - navigationToolBar = new NavigationBar(config->section("navigation"), this); + navigationToolBar = new NavigationBar(config.get(), this); navigationToolBar->setMovable(config->value<bool>("navigation.movable").value()); addToolBar(Qt::TopToolBarArea, navigationToolBar); navigationToolBar->connectWebView(nullptr); diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp index 0e5966f..61d17fa 100644 --- a/src/mainwindow/widgets/navigationbar.cpp +++ b/src/mainwindow/widgets/navigationbar.cpp @@ -17,18 +17,14 @@ #include <QToolBar> #include <QToolButton> #include <QWebEngineHistory> +#include "util.h" -NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *parent) +NavigationBar::NavigationBar(const Configuration *config, QWidget *parent) : QToolBar(parent) { - qStyle = parent->style(); - // Back button - backAction = addAction(qStyle->standardIcon(QStyle::SP_ArrowBack), tr("Back")); - if(conf.count("navigation.shortcuts.back") > 0) { - backAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.back"))); - backAction->setToolTip(tr("Back (%1)").arg(conf.value("navigation.shortcuts.back"))); - } + backAction = addAction(Util::icon(QStyle::SP_ArrowBack), tr("Back")); + config->setShortcut(backAction, "navigation.shortcuts.back"); connect(backAction, &QAction::triggered, this, [this]() { m_view->history()->back(); }); @@ -46,7 +42,7 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren }); backAction->setMenu(backMenu); - auto *backMenuShortcut = new QShortcut(QKeySequence(conf.value("navigation.shortcuts.backMenu")), this); + auto *backMenuShortcut = new QShortcut(QKeySequence(config->value<QString>("navigation.shortcuts.backMenu").value()), this); connect(backMenuShortcut, &QShortcut::activated, backMenu, [this, backMenu]() { if(backAction->isEnabled()) { auto *widget = this->widgetForAction(backAction); @@ -55,11 +51,8 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren }); // Forward button - forwardAction = addAction(qStyle->standardIcon(QStyle::SP_ArrowForward), tr("Forward")); - if(conf.count("navigation.shortcuts.forward") > 0) { - forwardAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.forward"))); - forwardAction->setToolTip(tr("Forward (%1)").arg(conf.value("navigation.shortcuts.forward"))); - } + forwardAction = addAction(Util::icon(QStyle::SP_ArrowForward), tr("Forward")); + config->setShortcut(forwardAction, "navigation.shortcuts.forward"); connect(forwardAction, &QAction::triggered, this, [this]() { m_view->history()->forward(); }); @@ -77,7 +70,7 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren }); forwardAction->setMenu(forwardMenu); - auto *forwardMenuShortcut = new QShortcut(QKeySequence(conf.value("navigation.shortcuts.forwardMenu")), this); + auto *forwardMenuShortcut = new QShortcut(QKeySequence(config->value<QString>("navigation.shortcuts.forwardMenu").value()), this); connect(forwardMenuShortcut, &QShortcut::activated, forwardMenu, [this, forwardMenu]() { if(forwardAction->isEnabled()) { auto *widget = this->widgetForAction(forwardAction); @@ -86,8 +79,8 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren }); // Stop/Refresh button - stopReloadAction = addAction(qStyle->standardIcon(QStyle::SP_BrowserReload), tr("Refresh")); - stopReloadAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.refresh"))); + stopReloadAction = addAction(Util::icon(QStyle::SP_BrowserReload), tr("Refresh")); + config->setShortcut(stopReloadAction, "navigation.shortcuts.refresh"); connect(stopReloadAction, &QAction::triggered, this, [this]() { if(m_view->isLoaded()) m_view->reload(); @@ -95,14 +88,14 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren m_view->stop(); }); - auto *reloadShortcut = new QShortcut(QKeySequence(conf.value("navigation.shortcuts.reload")), this); + auto *reloadShortcut = new QShortcut(QKeySequence(config->value<QString>("navigation.shortcuts.reload").value()), this); connect(reloadShortcut, &QShortcut::activated, this, [this]() { m_view->triggerPageAction(QWebEnginePage::ReloadAndBypassCache); }); // Home button - homeAction = addAction(qStyle->standardIcon(QStyle::SP_DirHomeIcon), tr("Home")); - homeAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.home"))); + homeAction = addAction(Util::icon(QStyle::SP_DirHomeIcon), tr("Home")); + config->setShortcut(homeAction, "navigation.shortcuts.home"); connect(homeAction, &QAction::triggered, this, [this]() { m_view->triggerViewAction(WebView::GoHome); }); @@ -140,12 +133,12 @@ void NavigationBar::update_loadStarted() { backAction->setEnabled(m_view->history()->canGoForward()); forwardAction->setEnabled(m_view->history()->canGoForward()); - stopReloadAction->setIcon(qStyle->standardIcon(QStyle::SP_BrowserStop)); + stopReloadAction->setIcon(Util::icon(QStyle::SP_BrowserStop)); } void NavigationBar::update_loadFinished() { backAction->setEnabled(m_view->history()->canGoBack()); forwardAction->setEnabled(m_view->history()->canGoForward()); - stopReloadAction->setIcon(qStyle->standardIcon(QStyle::SP_BrowserReload)); + stopReloadAction->setIcon(Util::icon(QStyle::SP_BrowserReload)); } diff --git a/src/mainwindow/widgets/navigationbar.h b/src/mainwindow/widgets/navigationbar.h index 98d62dc..0b5a319 100644 --- a/src/mainwindow/widgets/navigationbar.h +++ b/src/mainwindow/widgets/navigationbar.h @@ -11,13 +11,14 @@ #include <QToolBar> +class Configuration; class WebView; class NavigationBar : public QToolBar { Q_OBJECT public: - explicit NavigationBar(const QHash<QString, QString> &conf, QWidget *parent = nullptr); + explicit NavigationBar(const Configuration *config, QWidget *parent = nullptr); public slots: void connectWebView(WebView *view); @@ -27,7 +28,6 @@ private slots: void update_loadFinished(); private: - QStyle *qStyle; WebView *m_view; QAction *backAction, *forwardAction; diff --git a/src/util.cpp b/src/util.cpp index a978838..adf1f85 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -9,6 +9,7 @@ #include "util.h" #include <QDir> #include <QFileInfo> +#include <QApplication> #define ListSeparator QLatin1Literal(";") @@ -43,4 +44,24 @@ const QStringList Util::files(const QString &location, const QStringList &nameFi } return filelist; -}
\ No newline at end of file +} + +// icon names: https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html +QIcon Util::icon(QStyle::StandardPixmap id) { + switch(id) { + case QStyle::SP_ArrowBack: + return QIcon::fromTheme("go-previous", qApp->style()->standardIcon(id)); + case QStyle::SP_ArrowForward: + return QIcon::fromTheme("go-next", qApp->style()->standardIcon(id)); + case QStyle::SP_BrowserStop: + return QIcon::fromTheme("process-stop", qApp->style()->standardIcon(id)); + case QStyle::SP_BrowserReload: + return QIcon::fromTheme("view-refresh", qApp->style()->standardIcon(id)); + case QStyle::SP_DirHomeIcon: + return QIcon::fromTheme("go-home", qApp->style()->standardIcon(id)); + + default: + qDebug("FIXME: unhandled StandardPixmap %i", id); + return qApp->style()->standardIcon(id); + } +} @@ -10,10 +10,13 @@ #define SMOLBOTE_UTIL_H #include <QStringList> +#include <QIcon> +#include <QStyle> namespace Util { const QStringList files(const QString &location, const QStringList &nameFilters = QStringList()); +QIcon icon(QStyle::StandardPixmap id); } |