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