aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/configuration/configuration.cpp23
-rw-r--r--lib/configuration/configuration.h3
-rw-r--r--src/addressbar/urllineedit.cpp46
-rw-r--r--src/addressbar/urllineedit.h13
-rw-r--r--src/mainwindow/mainwindow.cpp14
5 files changed, 66 insertions, 33 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index 75d0a5b..fa01951 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -9,6 +9,7 @@
#include "configuration.h"
#include <QStandardPaths>
#include <fstream>
+#include <boost/algorithm/string/predicate.hpp>
namespace po = boost::program_options;
@@ -48,6 +49,11 @@ Configuration::Configuration()
("browser.shortcuts.reload", po::value<std::string>()->default_value("Ctrl+F5"))
("browser.shortcuts.home", po::value<std::string>()->default_value("Ctrl+Home"))
+ // address bar
+ ("addressbar.shortcuts.focus", po::value<std::string>()->default_value("F4"))
+ ("addressbar.shortcuts.pageMenu", po::value<std::string>()->default_value("F2"))
+ ("addressbar.shortcuts.toolsMenu", po::value<std::string>()->default_value("F10"))
+
// tabs
("browser.shortcuts.tabClose", po::value<std::string>()->default_value("Ctrl+X"))
("browser.shortcuts.tabLeft", po::value<std::string>()->default_value("Ctrl+O"))
@@ -55,7 +61,6 @@ Configuration::Configuration()
// page
("browser.shortcuts.toggleSearchBox", po::value<std::string>()->default_value("F3"))
- ("browser.shortcuts.focusAddress", po::value<std::string>()->default_value("F4"))
("browser.shortcuts.fullscreen", po::value<std::string>()->default_value("F11"))
// Filter settings
@@ -106,7 +111,9 @@ QString Configuration::defaultUserConfigLocation()
bool Configuration::read(const QString &path)
{
std::ifstream f(path.toStdString(), std::ifstream::in);
- po::store(po::parse_config_file(f, desc, false), vm);
+
+ // parse_config_file(file, options_description, allow_unregistered)
+ po::store(po::parse_config_file(f, desc, true), vm);
return true;
}
@@ -120,3 +127,15 @@ bool Configuration::parse(int argc, const char **argv)
return true;
}
+
+QHash<QString, QString> Configuration::section(const std::string &prefix) const
+{
+ QHash<QString, QString> v;
+ for(auto s : desc.options()) {
+ if(boost::starts_with(s->long_name(), prefix)) {
+ v[s->long_name().c_str()] = QString::fromStdString(value<std::string>(s->long_name().c_str()).value());
+ }
+ }
+
+ return v;
+}
diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h
index c8fcdff..1c919b0 100644
--- a/lib/configuration/configuration.h
+++ b/lib/configuration/configuration.h
@@ -15,6 +15,7 @@
#include <QString>
#include <boost/program_options.hpp>
#include <QStringList>
+#include <QVariant>
class Configuration
{
@@ -68,6 +69,8 @@ public:
return desc.options();
}
+ QHash<QString, QString> section(const std::string &prefix) const;
+
private:
boost::program_options::options_description desc;
boost::program_options::variables_map vm;
diff --git a/src/addressbar/urllineedit.cpp b/src/addressbar/urllineedit.cpp
index cfc2ab0..a36e1fc 100644
--- a/src/addressbar/urllineedit.cpp
+++ b/src/addressbar/urllineedit.cpp
@@ -9,29 +9,41 @@
#include "urllineedit.h"
#include <QLabel>
#include <QMenu>
+#include <QShortcut>
#include <QTimer>
#include <QWidgetAction>
#include <bookmarks/bookmarksview.h>
-UrlLineEdit::UrlLineEdit(QWidget *parent)
+UrlLineEdit::UrlLineEdit(const QHash<QString, QString> &config, QWidget *parent)
: QLineEdit(parent)
, m_listView(new Completer(this))
{
+ auto *focusShortcut = new QShortcut(QKeySequence(config.value("addressbar.shortcuts.focus")), parent);
+ connect(focusShortcut, &QShortcut::activated, this, [this]() {
+ setFocus();
+ selectAll();
+ });
+
setPlaceholderText(tr("Enter address"));
m_listView->setVisible(false);
connect(this, &UrlLineEdit::textEdited, this, &UrlLineEdit::updateCompleter);
- // leading position action
- //addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
+ m_pageMenuAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
+ m_pageMenuAction->setShortcut(QKeySequence(config.value("addressbar.shortcuts.pageMenu")));
+ m_pageMenuAction->setToolTip(tr("Page Actions (%1)").arg(m_pageMenuAction->shortcut().toString()));
+ connect(m_pageMenuAction, &QAction::triggered, m_pageMenuAction, [&]() {
+ if(m_pageMenuAction->menu()) {
+ m_pageMenuAction->menu()->exec(this->mapToGlobal(QPoint(0, height())));
+ }
+ });
- m_pageAction = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
- m_pageAction->setShortcut(QKeySequence("F10"));
- m_pageAction->setToolTip(tr("Page Actions"));
- connect(m_pageAction, &QAction::triggered, m_pageAction, [&]() {
- //this->deselect();
- if(m_pageAction->menu() != nullptr) {
- m_pageAction->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
+ m_toolsMenuAction = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
+ m_toolsMenuAction->setShortcut(QKeySequence(config.value("addressbar.shortcuts.toolsMenu")));
+ m_toolsMenuAction->setToolTip(tr("Tools (%1)").arg(m_toolsMenuAction->shortcut().toString()));
+ connect(m_toolsMenuAction, &QAction::triggered, m_toolsMenuAction, [&]() {
+ if(m_toolsMenuAction->menu()) {
+ m_toolsMenuAction->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
}
});
@@ -63,7 +75,7 @@ void UrlLineEdit::connectWebView(WebView *view)
disconnect(urlChangedConnection);
setUrl(view->url());
- m_pageAction->setMenu(view->pageMenu());
+ m_pageMenuAction->setMenu(view->pageMenu());
urlChangedConnection = connect(view, &WebView::urlChanged, this, &UrlLineEdit::setUrl);
}
@@ -88,7 +100,7 @@ void UrlLineEdit::updateCompleter(const QString &text)
return;
}
- const QList<QTreeWidgetItem*> res = m_bookmarksModel->findItems(text, Qt::MatchContains | Qt::MatchRecursive, 1);
+ const QList<QTreeWidgetItem *> res = m_bookmarksModel->findItems(text, Qt::MatchContains | Qt::MatchRecursive, 1);
if(!m_listView->updateItems(res)) {
m_listView->hide();
@@ -115,7 +127,9 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
void UrlLineEdit::focusOutEvent(QFocusEvent *event)
{
- setUrl(QUrl::fromUserInput(text()));
+ if(!text().startsWith('#'))
+ setUrl(QUrl::fromUserInput(text()));
+
QLineEdit::focusOutEvent(event);
}
@@ -131,9 +145,15 @@ void UrlLineEdit::keyPressEvent(QKeyEvent *event)
setText(currentIndex.data().toString());
}
m_listView->hide();
+ event->accept();
return;
}
+ } else if(event->key() == Qt::Key::Key_Escape) {
+ clearFocus();
+ event->accept();
+ return;
}
+
QLineEdit::keyPressEvent(event);
}
diff --git a/src/addressbar/urllineedit.h b/src/addressbar/urllineedit.h
index b726973..17465bc 100644
--- a/src/addressbar/urllineedit.h
+++ b/src/addressbar/urllineedit.h
@@ -6,8 +6,8 @@
* SPDX-License-Identifier: GPL-3.0
*/
-#ifndef URLLINEEDIT_H
-#define URLLINEEDIT_H
+#ifndef SMOLBOTE_URLLINEEDIT_H
+#define SMOLBOTE_URLLINEEDIT_H
#include <QAction>
#include <QLineEdit>
@@ -22,7 +22,7 @@ class UrlLineEdit : public QLineEdit
{
Q_OBJECT
public:
- explicit UrlLineEdit(QWidget *parent = nullptr);
+ explicit UrlLineEdit(const QHash<QString, QString> &config, QWidget *parent = nullptr);
void setCompleterModel(BookmarksView *model);
@@ -47,7 +47,10 @@ private:
QTextLayout::FormatRange m_hostFormat;
- QAction *m_pageAction = nullptr;
+ // pageMenu action: zoom, print
+ QAction *m_pageMenuAction = nullptr;
+ // devMenu action: scripts, etc
+ QAction *m_toolsMenuAction = nullptr;
// completer
BookmarksView *m_bookmarksModel = nullptr;
@@ -56,4 +59,4 @@ private:
QMetaObject::Connection urlChangedConnection;
};
-#endif // URLLINEEDIT_H
+#endif // SMOLBOTE_URLLINEEDIT_H
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index e280fee..6dc7635 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -17,14 +17,13 @@
#include <downloads/downloadswidget.h>
#include "addressbar/urllineedit.h"
#include <bookmarks/bookmarksview.h>
-//#include <settings/settingsdialog.h>
MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, tabBar(new MainWindowTabBar(config, this))
, menuBar(new MainWindowMenuBar(config, this))
- , m_addressBar(new UrlLineEdit(this))
+ , m_addressBar(new UrlLineEdit(config->section("addressbar"), this))
, m_progressBar(new LoadingBar(this))
{
Q_ASSERT(config);
@@ -84,17 +83,6 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent)
ui->statusBar->addWidget(m_searchBox);
m_searchBox->setVisible(false);
- // shortcuts
- QAction *focusAddressAction = new QAction(this);
- focusAddressAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("browser.shortcuts.focusAddress").value())));
- //focusAddressAction->setShortcut(QKeySequence::fromString(browser->settings()->value("window.shortcuts.focusAddress").toString()));
- //connect(focusAddressAction, SIGNAL(triggered(bool)), this, SLOT(focusAddress()));
- connect(focusAddressAction, &QAction::triggered, this, [this]() {
- m_addressBar->setFocus();
- m_addressBar->selectAll();
- });
- addAction(focusAddressAction);
-
resize(m_config->value<int>("browser.window.width").value(), m_config->value<int>("browser.window.height").value());
if(m_config->value<bool>("browser.window.maximized").value()) {
showMaximized();