add 'add new config' option to the menu

This commit is contained in:
Gergely Mincsovics
2020-12-27 13:12:35 +01:00
parent 3f19c04a8f
commit a90e046063
2 changed files with 28 additions and 13 deletions

View File

@ -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));
}

View File

@ -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.