diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 6bdd9285..7d1dca0b 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -881,8 +881,8 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp ) hbox->addWidget( cancelButton ); hbox->addWidget( okButton ); - connect( okButton, SIGNAL(clicked(void)), &dialog, SLOT(accept(void)) ); - connect( cancelButton, SIGNAL(clicked(void)), &dialog, SLOT(reject(void)) ); + connect( okButton, SIGNAL(clicked(void)), &dialog, SLOT(accept(void)) ); + connect( cancelButton, SIGNAL(clicked(void)), &dialog, SLOT(reject(void)) ); okButton->setDefault(true); diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index f31de796..3137bcfb 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -63,6 +63,7 @@ struct GamePadConfigLocalData_t static GamePadConfigLocalData_t lcl[GAMEPAD_NUM_DEVICES]; static GamePadConfDialog_t *gamePadConfWin = NULL; +static bool updateRemapTree = false; //---------------------------------------------------- int openGamePadConfWindow(QWidget *parent) @@ -459,7 +460,11 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent) loadMapList(); - refreshKeyBindTree(); + if ( updateRemapTree ) + { + refreshKeyBindTree(); + updateRemapTree = false; + } } //---------------------------------------------------- @@ -564,29 +569,69 @@ void GamePadConfDialog_t::loadMapList(void) } } //---------------------------------------------------- -void GamePadConfDialog_t::refreshKeyBindTree(void) +void GamePadConfDialog_t::refreshKeyBindTree( bool reset ) { + int i; QTreeWidgetItem *item; std::list ::iterator it; gamepad_function_key_t *binding; - const char *btnName; + const char *btnName[2]; + char btnSeq[128]; + + if ( reset ) + { + keyBindTree->clear(); + } + + i=0; for (it=gpKeySeqList.begin(); it!=gpKeySeqList.end(); it++) { binding = *it; - item = new QTreeWidgetItem(); + if ( keyBindTree->topLevelItemCount() > i ) + { + item = keyBindTree->topLevelItem(i); + } + else + { + item = NULL; + } - btnName = ButtonName( &binding->bc ); + if ( item == NULL ) + { + item = new QTreeWidgetItem(); - item->setText(0, QString::fromStdString(btnName)); + keyBindTree->addTopLevelItem(item); + } + + btnName[0] = ButtonName( &binding->bmap[0] ); + + btnSeq[0] = 0; + + if ( btnName[0][0] != 0 ) + { + strcat( btnSeq, btnName[0] ); + strcat( btnSeq, " + "); + } + + btnName[1] = ButtonName( &binding->bmap[1] ); + + if ( btnName[1][0] != 0 ) + { + strcat( btnSeq, btnName[1] ); + } + + item->setText(0, tr(btnSeq)); //item->setText(1, QString::fromStdString(keyName)); item->setTextAlignment(0, Qt::AlignLeft); item->setTextAlignment(1, Qt::AlignLeft); - keyBindTree->addTopLevelItem(item); + i++; } + + keyBindTree->viewport()->update(); } //---------------------------------------------------- void GamePadConfDialog_t::updateCntrlrDpy(void) @@ -704,7 +749,7 @@ void GamePadConfDialog_t::changeButton(int padNo, int x) if (buttonConfigStatus != 0) { keyNameStr = ButtonName(&GamePad[padNo].bmap[x]); - keyName[x]->setText(keyNameStr); + keyName[x]->setText( tr(keyNameStr) ); lcl[padNo].btn[x].needsSave = 1; } @@ -717,7 +762,8 @@ void GamePadConfDialog_t::clearButton(int padNo, int x) { GamePad[padNo].bmap[x].ButtonNum = -1; - keyName[x]->setText(""); + //keyName[x]->setText( tr("") ); + keyName[x]->clear(); lcl[padNo].btn[x].needsSave = 1; } @@ -1068,12 +1114,14 @@ void GamePadConfDialog_t::promptToSave(void) msgBox.setIcon(QMessageBox::Warning); msgBox.setText(tr(msg.c_str())); - msgBox.show(); msgBox.exec(); } //---------------------------------------------------- void GamePadConfDialog_t::newKeyBindingCallback(void) { + GamePadFuncConfigDialog *dialog = new GamePadFuncConfigDialog( NULL, this ); + + dialog->show(); // TODO } //---------------------------------------------------- @@ -1124,6 +1172,8 @@ void GamePadConfDialog_t::updatePeriodic(void) gpView->setPort(portNum); gpView->update(); + + refreshKeyBindTree(); } //---------------------------------------------------- @@ -1469,3 +1519,208 @@ void GamePadView_t::paintEvent(QPaintEvent *event) painter.drawRect(tBox); } //---------------------------------------------------- +// Game Pad Function Config +//---------------------------------------------------- +GamePadFuncConfigDialog::GamePadFuncConfigDialog( gamepad_function_key_t *fk, QWidget *parent ) + : QDialog(parent) +{ + QHBoxLayout *hbox; + QVBoxLayout *mainLayout, *vbox; + QGridLayout *grid; + QLabel *lbl; + QPushButton *okButton, *cancelButton; + QPushButton *clearButton[3]; + + if ( fk == NULL ) + { + editMode = false; + k = new gamepad_function_key_t(); + } + else + { + editMode = true; + k = fk; + } + + if ( editMode ) + { + setWindowTitle( tr("Edit Function") ); + } + else + { + setWindowTitle( tr("Add Function") ); + } + + btnLbl[0] = new QLineEdit(); + btnLbl[1] = new QLineEdit(); + keySeqLbl = new QLineEdit(); + + btnLbl[0]->setReadOnly(true); + btnLbl[1]->setReadOnly(true); + keySeqLbl->setReadOnly(true); + + b[0] = new GamePadConfigButton_t(0); + b[1] = new GamePadConfigButton_t(1); + hk = new GamePadConfigHotKey_t(); + + clearButton[0] = new QPushButton( tr("Clear") ); + clearButton[1] = new QPushButton( tr("Clear") ); + clearButton[2] = new QPushButton( tr("Clear") ); + + mainLayout = new QVBoxLayout(); + + setLayout(mainLayout); + + grid = new QGridLayout(); + mainLayout->addLayout( grid ); + + //grid->setColumnMinimumWidth( 1, 20 ); + + grid->addWidget( new QLabel( tr("Modifier Button:") ), 0, 0 ); + grid->addWidget( btnLbl[0], 0, 1 ); + grid->addWidget( b[0], 0, 2 ); + grid->addWidget( clearButton[0], 0, 3 ); + + grid->addWidget( new QLabel( tr("Primary Button:") ), 1, 0 ); + grid->addWidget( btnLbl[1], 1, 1 ); + grid->addWidget( b[1], 1, 2 ); + grid->addWidget( clearButton[1], 1, 3 ); + + grid->addWidget( new QLabel( tr("Key Sequence:") ), 2, 0 ); + grid->addWidget( keySeqLbl, 2, 1 ); + grid->addWidget( hk, 2, 2 ); + grid->addWidget( clearButton[2], 2, 3 ); + + hbox = new QHBoxLayout(); + okButton = new QPushButton( tr("OK") ); + cancelButton = new QPushButton( tr("Cancel") ); + + mainLayout->addLayout( hbox ); + hbox->addWidget( cancelButton ); + hbox->addWidget( okButton ); + + connect( okButton, SIGNAL(clicked(void)), this, SLOT(acceptCB(void)) ); + connect( cancelButton, SIGNAL(clicked(void)), this, SLOT(rejectCB(void)) ); + + okButton->setDefault(true); + + //ret = dialog.exec(); + buttonConfigStatus = 0; + + connect( b[0], SIGNAL(clicked(void)), this, SLOT(changeButton0(void)) ); + connect( b[1], SIGNAL(clicked(void)), this, SLOT(changeButton1(void)) ); + //connect( hk, SIGNAL(clicked(void)), this, SLOT(changeButton1(void)) ); +} +//---------------------------------------------------- +GamePadFuncConfigDialog::~GamePadFuncConfigDialog(void) +{ + int ret; + + buttonConfigStatus = 0; + + ret = result(); + + if ( ret == QDialog::Accepted ) + { + if ( !editMode ) + { + gpKeySeqList.push_back( k ); + } + } + else + { + if ( !editMode ) + { + delete k; + } + } + + updateRemapTree = true; +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::closeEvent(QCloseEvent *event) +{ + done( result() ); + deleteLater(); + event->accept(); +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::acceptCB(void) +{ + done( QDialog::Accepted ); + deleteLater(); +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::rejectCB(void) +{ + done( QDialog::Rejected ); + deleteLater(); +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::closeWindow(void) +{ + done( result() ); + deleteLater(); +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::changeButton(int x) +{ + //char buf[256]; + //std::string prefix; + const char *keyNameStr; + + if (buttonConfigStatus == 2) + { + buttonConfigStatus = 0; + return; + } + buttonConfigStatus = 2; + + ButtonConfigBegin(); + + b[x]->setText("Waiting"); + b[x]->setStyleSheet("background-color: green; color: white;"); + + DWaitButton(NULL, &k->bmap[x], &buttonConfigStatus); + + b[x]->setText("Change"); + b[x]->setStyleSheet(NULL); + + if (buttonConfigStatus != 0) + { + keyNameStr = ButtonName(&k->bmap[x]); + btnLbl[x]->setText( tr(keyNameStr) ); + } + + ButtonConfigEnd(); + + buttonConfigStatus = 1; +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::changeButton0(void) +{ + changeButton(0); +} +//---------------------------------------------------- +void GamePadFuncConfigDialog::changeButton1(void) +{ + changeButton(1); +} +//---------------------------------------------------- +GamePadConfigHotKey_t::GamePadConfigHotKey_t(void) +{ + setText("Change"); +} +//---------------------------------------------------- +void GamePadConfigHotKey_t::keyPressEvent(QKeyEvent *event) +{ + //printf("GamePad Button Key Press: 0x%x \n", event->key() ); + //pushKeyEvent(event, 1); +} + +void GamePadConfigHotKey_t::keyReleaseEvent(QKeyEvent *event) +{ + //printf("GamePad Button Key Release: 0x%x \n", event->key() ); + //pushKeyEvent(event, 0); +} +//---------------------------------------------------- diff --git a/src/drivers/Qt/GamePadConf.h b/src/drivers/Qt/GamePadConf.h index 25ab3eec..0cb99216 100644 --- a/src/drivers/Qt/GamePadConf.h +++ b/src/drivers/Qt/GamePadConf.h @@ -19,6 +19,7 @@ #include #include "Qt/main.h" +#include "Qt/input.h" class GamePadConfigButton_t : public QPushButton { @@ -32,6 +33,48 @@ protected: int idx; }; +class GamePadConfigHotKey_t : public QPushButton +{ +public: + GamePadConfigHotKey_t(void); + +protected: + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *event); +}; + +class GamePadFuncConfigDialog : public QDialog +{ + Q_OBJECT + +public: + GamePadFuncConfigDialog( gamepad_function_key_t *fk, QWidget *parent = 0); + ~GamePadFuncConfigDialog(void); + +protected: + void closeEvent(QCloseEvent *bar); + + void changeButton(int x); + + QLineEdit *btnLbl[2]; + QLineEdit *keySeqLbl; + + GamePadConfigButton_t *b[2]; + GamePadConfigHotKey_t *hk; + gamepad_function_key_t *k; + + int buttonConfigStatus; + bool editMode; + +public slots: + void closeWindow(void); +private slots: + void acceptCB(void); + void rejectCB(void); + void changeButton0(void); + void changeButton1(void); +}; + class GamePadView_t : public QWidget { Q_OBJECT @@ -106,7 +149,7 @@ protected: void keyReleaseEvent(QKeyEvent *event); void closeEvent(QCloseEvent *bar); - void refreshKeyBindTree(void); + void refreshKeyBindTree( bool reset = false ); private: void updateCntrlrDpy(void); @@ -114,6 +157,7 @@ private: void loadMapList(void); void saveConfig(void); void promptToSave(void); + void openFuncEditWindow( int mode, gamepad_function_key_t *k ); public slots: void closeWindow(void); diff --git a/src/drivers/Qt/input.h b/src/drivers/Qt/input.h index f6dae796..3564cd16 100644 --- a/src/drivers/Qt/input.h +++ b/src/drivers/Qt/input.h @@ -57,7 +57,7 @@ struct gamepad_function_key_t int qKey; unsigned int qModifier; - struct ButtConfig bc; + struct ButtConfig bmap[2]; gamepad_function_key_t(void); ~gamepad_function_key_t(void);