diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-23 10:25:28 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-23 10:25:28 +0200 |
commit | 84137d9c3bf21e0a32f8a50a9bf9a93584754b75 (patch) | |
tree | cb539940bc33375dd477db545bb1fac9ab17ade6 /src | |
parent | clang-format pass (diff) | |
download | smolbote-84137d9c3bf21e0a32f8a50a9bf9a93584754b75.tar.xz |
Add Configuration::setValue and Configuration::setShortcut
Change MainWindow to use setShortcut
Diffstat (limited to 'src')
-rw-r--r-- | src/browser.cpp | 4 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 38 |
3 files changed, 33 insertions, 15 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index e26dbc8..56eed96 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -167,7 +167,7 @@ MainWindow *Browser::createWindow() connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search); auto *bookmarksAction = new QAction(tr("Bookmarks"), window); - bookmarksAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("bookmarks.shortcut").value()))); + m_config->setShortcut(bookmarksAction, "bookmarks.shortcut"); connect(bookmarksAction, &QAction::triggered, window, [this, window]() { bool wasVisible = m_bookmarks->isVisible(); for(MainWindow *w : qAsConst(m_windows)) { @@ -180,7 +180,7 @@ MainWindow *Browser::createWindow() window->addAction(MainWindow::ToolsMenu, bookmarksAction); auto *downloadsAction = new QAction(tr("Downloads"), window); - downloadsAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("downloads.shortcut").value()))); + m_config->setShortcut(downloadsAction, "downloads.shortcut"); connect(downloadsAction, &QAction::triggered, window, [this, window]() { bool wasVisible = m_downloads->isVisible(); for(MainWindow *w : qAsConst(m_windows)) { diff --git a/src/main.cpp b/src/main.cpp index c1060aa..ee22753 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,12 @@ int main(int argc, char **argv) { // create and load configuration std::shared_ptr<Configuration> config = std::make_shared<Configuration>(); +#ifdef QT_DEBUG + QObject::connect(config.get(), &Configuration::settingChanged, [](const std::string &path, const QString &value) { + qDebug("!!! setting changed %s=[%s]", path.c_str(), qUtf8Printable(value)); + }); +#endif + if(!config->parse(argc, argv)) { qWarning("Error parsing command line, check --help for usage."); return -1; diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index e885513..27279c1 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -113,8 +113,9 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) }); // search box - auto *searchShortcut = new QShortcut(QKeySequence(config->value<std::string>("mainwindow.shortcuts.search").value().c_str()), this); - connect(searchShortcut, &QShortcut::activated, this, [=]() { + auto *searchAction = new QAction(this); + m_config->setShortcut(searchAction, "mainwindow.shortcuts.search"); + connect(searchAction, &QAction::triggered, this, [=]() { /* QTBUG-18665 * When focusing out of the search box and hiding it, the first * (or earlier?) subwindow gets activated for some reason. @@ -127,6 +128,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) searchBox->show(); } }); + QMainWindow::addAction(searchAction); } MainWindow::~MainWindow() @@ -142,34 +144,44 @@ void MainWindow::createMenuBar() { Q_CHECK_PTR(mdiArea); + // smolbote menu auto *smolboteMenu = menuBar()->addMenu(qApp->applicationDisplayName()); - smolboteMenu->addAction(tr("New subwindow"), this, [this]() { + + auto *subwindowAction = smolboteMenu->addAction(tr("New subwindow"), this, [this]() { createSubWindow(); - }, - QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.newGroup").value().c_str())); + }); + m_config->setShortcut(subwindowAction, "mainwindow.shortcuts.newGroup"); - smolboteMenu->addAction(tr("New window"), this, []() { + auto *windowAction = smolboteMenu->addAction(tr("New window"), this, []() { auto *browser = qobject_cast<Browser *>(qApp); if(browser) browser->createWindow(); - }, - QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.newWindow").value().c_str())); + }); + m_config->setShortcut(windowAction, "mainwindow.shortcuts.newWindow"); smolboteMenu->addSeparator(); - smolboteMenu->addAction(tr("About"), qobject_cast<Browser *>(qApp), &Browser::about, QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.about").value().c_str())); + auto *aboutAction = smolboteMenu->addAction(tr("About"), qobject_cast<Browser *>(qApp), &Browser::about); + m_config->setShortcut(aboutAction, "mainwindow.shortcuts.about"); smolboteMenu->addAction(tr("About Qt"), qApp, &QApplication::aboutQt); smolboteMenu->addSeparator(); - smolboteMenu->addAction(tr("Quit"), qApp, &QApplication::quit, - QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.quit").value().c_str())); + auto *quitAction = smolboteMenu->addAction(tr("Quit"), qApp, &QApplication::quit); + m_config->setShortcut(quitAction, "mainwindow.shortcuts.quit"); + // window menu auto *windowMenu = menuBar()->addMenu(tr("Window")); - windowMenu->addAction(tr("Tile windows"), mdiArea, &QMdiArea::tileSubWindows, QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.tileWindows").value().c_str())); - windowMenu->addAction(tr("Cascade windows"), mdiArea, &QMdiArea::cascadeSubWindows, QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.cascadeWindows").value().c_str())); + + auto *tileAction = windowMenu->addAction(tr("Tile windows"), mdiArea, &QMdiArea::tileSubWindows); + m_config->setShortcut(tileAction, "mainwindow.shortcuts.tileWindows"); + + auto *cascadeAction = windowMenu->addAction(tr("Cascade windows"), mdiArea, &QMdiArea::cascadeSubWindows); + m_config->setShortcut(cascadeAction, "mainwindow.shortcuts.cascadeWindows"); + subWindowAction = windowMenu->addAction(tr("Current window")); + // tools menu toolsMenu = menuBar()->addMenu(tr("Tools")); } |