From 84137d9c3bf21e0a32f8a50a9bf9a93584754b75 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 23 Jun 2018 10:25:28 +0200 Subject: Add Configuration::setValue and Configuration::setShortcut Change MainWindow to use setShortcut --- src/mainwindow/mainwindow.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/mainwindow') 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 &config, QWidget *parent) }); // search box - auto *searchShortcut = new QShortcut(QKeySequence(config->value("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 &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("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(qApp); if(browser) browser->createWindow(); - }, - QKeySequence(m_config->value("mainwindow.shortcuts.newWindow").value().c_str())); + }); + m_config->setShortcut(windowAction, "mainwindow.shortcuts.newWindow"); smolboteMenu->addSeparator(); - smolboteMenu->addAction(tr("About"), qobject_cast(qApp), &Browser::about, QKeySequence(m_config->value("mainwindow.shortcuts.about").value().c_str())); + auto *aboutAction = smolboteMenu->addAction(tr("About"), qobject_cast(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("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("mainwindow.shortcuts.tileWindows").value().c_str())); - windowMenu->addAction(tr("Cascade windows"), mdiArea, &QMdiArea::cascadeSubWindows, QKeySequence(m_config->value("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")); } -- cgit v1.2.1