diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-05-26 18:36:50 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-05-26 18:36:50 +0200 |
commit | 36989a4698aa455bb7512a9b47a0768281d4c47c (patch) | |
tree | a88bec8e6cbd9c2323bfde111da33a407e55d259 /src | |
parent | QTBUG-68224 workaround (diff) | |
download | smolbote-36989a4698aa455bb7512a9b47a0768281d4c47c.tar.xz |
Back/Forward menu shortcuts
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow/widgets/navigationbar.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp index 98fe0fa..177c4ad 100644 --- a/src/mainwindow/widgets/navigationbar.cpp +++ b/src/mainwindow/widgets/navigationbar.cpp @@ -25,7 +25,10 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren // Back button backAction = addAction(qStyle->standardIcon(QStyle::SP_ArrowBack), tr("Back")); - backAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.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"))); + } connect(backAction, &QAction::triggered, this, [this]() { m_view->history()->back(); }); @@ -42,9 +45,20 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren }); backAction->setMenu(backMenu); + auto *backMenuShortcut = new QShortcut(QKeySequence(conf.value("navigation.shortcuts.backMenu")), this); + connect(backMenuShortcut, &QShortcut::activated, backMenu, [this, backMenu]() { + if(backAction->isEnabled()) { + auto *widget = this->widgetForAction(backAction); + backMenu->exec(this->mapToGlobal(widget->pos() + QPoint(0, widget->height()))); + } + }); + // Forward button forwardAction = addAction(qStyle->standardIcon(QStyle::SP_ArrowForward), tr("Forward")); - forwardAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.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"))); + } connect(forwardAction, &QAction::triggered, this, [this]() { m_view->history()->forward(); }); @@ -61,8 +75,16 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren }); forwardAction->setMenu(forwardMenu); + auto *forwardMenuShortcut = new QShortcut(QKeySequence(conf.value("navigation.shortcuts.forwardMenu")), this); + connect(forwardMenuShortcut, &QShortcut::activated, forwardMenu, [this, forwardMenu]() { + if(forwardAction->isEnabled()) { + auto *widget = this->widgetForAction(forwardAction); + forwardMenu->exec(this->mapToGlobal(widget->pos() + QPoint(0, widget->height()))); + } + }); + // Stop/Refresh button - stopReloadAction = addAction(qStyle->standardIcon(QStyle::SP_BrowserReload), tr("Reload")); + stopReloadAction = addAction(qStyle->standardIcon(QStyle::SP_BrowserReload), tr("Refresh")); stopReloadAction->setShortcut(QKeySequence(conf.value("navigation.shortcuts.refresh"))); connect(stopReloadAction, &QAction::triggered, this, [this]() { if(m_view->isLoaded()) @@ -71,6 +93,11 @@ NavigationBar::NavigationBar(const QHash<QString, QString> &conf, QWidget *paren m_view->stop(); }); + auto *reloadShortcut = new QShortcut(QKeySequence(conf.value("navigation.shortcuts.reload")), 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"))); |