From a90e046063d56b936b70b851933673cbfb1495ff Mon Sep 17 00:00:00 2001 From: Gergely Mincsovics Date: Sun, 27 Dec 2020 13:12:35 +0100 Subject: [PATCH] add 'add new config' option to the menu --- src/layout.cpp | 38 +++++++++++++++++++++++++------------- src/layout.h | 3 +++ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/layout.cpp b/src/layout.cpp index 00a8ccb..25d01e9 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -15,6 +15,7 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt layoutGroup(new QActionGroup(this)), updateDevicesAction(new QAction(QIcon::fromTheme("view-refresh"),tr("Update &Joystick Devices"),this)), updateLayoutsAction(new QAction(QIcon::fromTheme("view-refresh"),tr("Update &Layout List"),this)), + addNewConfiguration(new QAction(QIcon::fromTheme("list-add"),tr("Add new configuration"),this)), quitAction(new QAction(QIcon::fromTheme("application-exit"),tr("&Quit"),this)), le(0) { @@ -51,6 +52,7 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt connect(updateLayoutsAction, SIGNAL(triggered()), this, SLOT(fillPopup())); connect(updateDevicesAction, SIGNAL(triggered()), this, SLOT(updateJoyDevs())); + connect(addNewConfiguration, SIGNAL(triggered()), this, SLOT(addNewConfig())); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); //no layout loaded at start. @@ -520,20 +522,9 @@ void LayoutManager::iconClick() { errorBox(tr("No joystick devices available"), tr("No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu."), le); - return; + } else { + addNewConfig(); } - if (le) { - if (le->isActiveWindow()) { - le->close(); - } - else { - le->activateWindow(); - } - return; - } - //otherwise, make a new LayoutEdit dialog and show it. - le = new LayoutEdit(this); - le->setLayout(currentLayout); } void LayoutManager::trayClick(QSystemTrayIcon::ActivationReason reason) { @@ -585,6 +576,9 @@ void LayoutManager::fillPopup() { } trayMenu.addSeparator(); + trayMenu.addAction(addNewConfiguration); + trayMenu.addSeparator(); + //and, at the end, quit! trayMenu.addAction(quitAction); } @@ -680,6 +674,24 @@ void LayoutManager::updateJoyDevs() { debug_mesg("done updating joydevs\n"); } +void LayoutManager::addNewConfig() { + if (!le) { + // make a new LayoutEdit dialog and show it. + le = new LayoutEdit(this); + le->setLayout(currentLayout); + } + if (le) { + if (le->isActiveWindow()) { + le->hide(); + } + else { + le->show(); + le->activateWindow(); + le->raise(); + } + } +} + void LayoutManager::addJoyPad(int index) { addJoyPad(index, QString("%1/js%2").arg(devdir, index)); } diff --git a/src/layout.h b/src/layout.h index af1f869..e17fa6a 100644 --- a/src/layout.h +++ b/src/layout.h @@ -75,6 +75,8 @@ class LayoutManager : public QObject { void fillPopup(); //update the list of available joystick devices void updateJoyDevs(); + // open dialog to be able to add new configurations + void addNewConfig(); private slots: //when the user selects an item on the tray's popup menu void layoutTriggered(); @@ -97,6 +99,7 @@ class LayoutManager : public QObject { QActionGroup *layoutGroup; QAction *updateDevicesAction; QAction *updateLayoutsAction; + QAction *addNewConfiguration; QAction *quitAction; //if there is a LayoutEdit open, this points to it. Otherwise, NULL.