diff --git a/src/layout.cpp b/src/layout.cpp index 3160b28..5c9bd35 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -36,7 +36,7 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); //no layout loaded at start. - setLayoutName(NL); + setLayoutName(QString::null); } LayoutManager::~LayoutManager() { @@ -52,7 +52,7 @@ QString LayoutManager::getFileName(const QString& layoutname ) { bool LayoutManager::load(const QString& name) { //it's VERY easy to load NL :) - if (name == NL) { + if (name.isNull()) { clear(); return true; } @@ -174,11 +174,11 @@ void LayoutManager::clear() { joypad->toDefault(); } //and call our layout NL - setLayoutName(NL); + setLayoutName(QString::null); } void LayoutManager::save() { - if (currentLayout == NL) { + if (currentLayout.isNull()) { saveAs(); return; } @@ -237,8 +237,10 @@ void LayoutManager::saveDefault() { } void LayoutManager::remove() { - if (currentLayout == NL) return; - if (QMessageBox::warning( 0, QJOYPAD_NAME" - Delete layout?","Remove layout permanently from your hard drive?", "Yes", "No", 0, 0, 1 ) == 1) return; + if (currentLayout.isNull()) return; + if (QMessageBox::warning(0, QJOYPAD_NAME" - Delete layout?", + QString("Remove layout %1 permanently from your hard drive?").arg(currentLayout), "Delete", "Cancel", 0, 0, 1 ) == 1) + return; QString filename = getFileName( currentLayout ); if (!QFile(filename).remove()) { errorBox("Remove error", "Could not remove file " + filename); @@ -259,25 +261,20 @@ QStringList LayoutManager::getLayoutNames() const { QString& name = result[i]; name.truncate(name.length() - 4); } - //and, of course, there's always NL. - result.prepend(NL); return result; } void LayoutManager::setLayoutName(const QString& name) { QList actions = layoutGroup->actions(); - bool found = false; for (int i = 0; i < actions.size(); ++ i) { QAction* action = actions[i]; if (action->data().toString() == name) { action->setChecked(true); - found = true; break; } } - - currentLayout = found ? name : NL; + currentLayout = name; if (le) { le->setLayout(name); @@ -338,12 +335,21 @@ void LayoutManager::fillPopup() { trayMenu.addAction(updateDevicesAction); trayMenu.addSeparator(); + //add null layout + QAction *action = trayMenu.addAction("[NO LAYOUT]"); + action->setCheckable(true); + action->setActionGroup(layoutGroup); + //put a check by the current one ;) + if (currentLayout.isNull()) { + action->setChecked(true); + } + connect(action, SIGNAL(triggered()), this, SLOT(layoutTriggered())); + //then add all the layout names - QStringList names = getLayoutNames(); - foreach (const QString &name, names) { + foreach (const QString &name, getLayoutNames()) { QString title = name; title.replace('&',"&&"); - QAction *action = trayMenu.addAction(title); + action = trayMenu.addAction(title); action->setData(name); action->setCheckable(true); action->setActionGroup(layoutGroup); diff --git a/src/layout.h b/src/layout.h index 4a5f40a..adbf8db 100644 --- a/src/layout.h +++ b/src/layout.h @@ -26,9 +26,6 @@ //So we can know if there is a graphical version of the Layout Manager displayed #include "layout_edit.h" -//for recognizing when the special empty layout is in use -#define NL "[NO LAYOUT]" - //handles loading, saving, and changing of layouts class LayoutManager : public QObject { friend class LayoutEdit; diff --git a/src/layout_edit.cpp b/src/layout_edit.cpp index 8540d9e..4a9e748 100644 --- a/src/layout_edit.cpp +++ b/src/layout_edit.cpp @@ -18,20 +18,20 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) { g->setMargin(5); g->setSpacing(5); cmbLayouts = new QComboBox(frame); - connect( cmbLayouts, SIGNAL(activated( const QString& )), lm, SLOT(load(const QString&))); + connect(cmbLayouts, SIGNAL(activated(int)), this, SLOT(load(int))); g->addWidget(cmbLayouts,0,0,1,4); //most of these buttons can link directly into slots in the LayoutManager - btnAdd = new QPushButton("Add", frame); + btnAdd = new QPushButton("&Add", frame); connect(btnAdd, SIGNAL(clicked()), lm, SLOT(saveAs())); g->addWidget(btnAdd,1,0); - btnRem = new QPushButton("Remove", frame); + btnRem = new QPushButton("&Remove", frame); connect(btnRem, SIGNAL(clicked()), lm, SLOT(remove())); g->addWidget(btnRem,1,1); - btnUpd = new QPushButton("Update", frame); + btnUpd = new QPushButton("&Save", frame); connect(btnUpd, SIGNAL(clicked()), lm, SLOT(save())); g->addWidget(btnUpd,1,2); - btnRev = new QPushButton("Revert", frame); + btnRev = new QPushButton("Re&vert", frame); connect(btnRev, SIGNAL(clicked()), lm, SLOT(reload())); g->addWidget(btnRev,1,3); mainLayout->addWidget( frame ); @@ -73,10 +73,10 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) { QHBoxLayout* h = new QHBoxLayout(0); h->setMargin(0); h->setSpacing(5); - QPushButton* close = new QPushButton( "-- Close Dialog --", this ); + QPushButton* close = new QPushButton( "-- &Close Dialog --", this ); connect(close, SIGNAL(clicked()), this, SLOT(close())); h->addWidget(close); - QPushButton* quit = new QPushButton( "-- Quit --", this ); + QPushButton* quit = new QPushButton( "-- &Quit --", this ); connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit())); h->addWidget(quit); mainLayout->addLayout(h); @@ -86,8 +86,14 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) { } void LayoutEdit::setLayout(const QString &layout) { - //change the text, - cmbLayouts->setCurrentIndex(lm->getLayoutNames().indexOf(layout)); + //change the selection + for (int i = 0; i < cmbLayouts->count(); ++ i) { + if (cmbLayouts->itemData(i).toString() == layout) { + cmbLayouts->setCurrentIndex(i); + break; + } + } + //update all the JoyPadWidgets. for (int i = 0, n = lm->available.count(); i < n; i++) { ((JoyPadWidget*)padStack->widget(i))->update(); @@ -97,9 +103,16 @@ void LayoutEdit::setLayout(const QString &layout) { void LayoutEdit::updateLayoutList() { //blank the list, then load in new names from the LayoutManager. cmbLayouts->clear(); - QStringList layouts = lm->getLayoutNames(); - cmbLayouts->insertItems(-1, layouts); - cmbLayouts->setCurrentIndex(layouts.indexOf(lm->currentLayout)); + cmbLayouts->addItem("[NO LAYOUT]", QVariant(QString::null)); + if (lm->currentLayout.isNull()) { + cmbLayouts->setCurrentIndex(0); + } + foreach (const QString& layout, lm->getLayoutNames()) { + cmbLayouts->addItem(layout, layout); + if (layout == lm->currentLayout) { + cmbLayouts->setCurrentIndex(cmbLayouts->count() - 1); + } + } } void LayoutEdit::updateJoypadWidgets() { @@ -143,3 +156,7 @@ void LayoutEdit::appFocusChanged(QWidget *old, QWidget *now) { debug_mesg("done releasing!\n"); } } + +void LayoutEdit::load(int index) { + lm->load(cmbLayouts->itemData(index).toString()); +} diff --git a/src/layout_edit.h b/src/layout_edit.h index fc68e8c..5a34f74 100644 --- a/src/layout_edit.h +++ b/src/layout_edit.h @@ -26,6 +26,8 @@ class LayoutEdit : public QWidget { void focusStateChanged(bool); public slots: void appFocusChanged(QWidget *old, QWidget *now); + private slots: + void load(int index); protected: //the layout manager this represents LayoutManager* lm;