Qt: GamePadConf change buttons sequentially. (#322)

This commit is contained in:
Oleg V. Polivets 2021-02-07 20:58:34 +03:00 committed by GitHub
parent 5edd659949
commit 23db1b35b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 5 deletions

View File

@ -83,6 +83,7 @@ int closeGamePadConfWindow(void)
//----------------------------------------------------
GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
: QDialog( parent )
, changeSeqStatus(0)
{
QWidget *mainWidget;
QVBoxLayout *mainLayout;
@ -98,6 +99,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
QPushButton *removeProfileButton;
QPushButton *clearAllButton;
QPushButton *closebutton;
QPushButton *changeSeqButton = nullptr;
QPushButton *clearButton[GAMEPAD_NUM_BUTTONS];
QScrollArea *scroll;
QStyle *style;
@ -267,11 +269,14 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
clearAllButton = new QPushButton(tr("Clear All"));
closebutton = new QPushButton(tr("Close"));
changeSeqButton = new QPushButton(tr("Change Sequentially"));
clearAllButton->setIcon( style->standardIcon( QStyle::SP_LineEditClearButton ) );
closebutton->setIcon( style->standardIcon( QStyle::SP_DialogCloseButton ) );
changeSeqButton->setIcon( style->standardIcon( QStyle::QStyle::SP_ArrowDown ) );
hbox4->addWidget( clearAllButton );
hbox4->addWidget( changeSeqButton );
hbox4->addWidget( closebutton );
connect(button[0], SIGNAL(clicked()), this, SLOT(changeButton0(void)) );
@ -303,6 +308,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
connect(clearAllButton , SIGNAL(clicked()), this, SLOT(clearAllCallback(void)) );
connect(closebutton , SIGNAL(clicked()), this, SLOT(closeWindow(void)) );
connect(changeSeqButton , SIGNAL(clicked()), this, SLOT(changeSequentallyCallback(void)) );
connect(portSel , SIGNAL(activated(int)), this, SLOT(portSelect(int)) );
connect(devSel , SIGNAL(activated(int)), this, SLOT(deviceSelect(int)) );
@ -557,14 +563,19 @@ void GamePadConfDialog_t::changeButton(int padNo, int x)
ButtonConfigBegin ();
button[x]->setText("Waiting" );
button[x]->setStyleSheet("background-color: green; color: white;");
DWaitButton (NULL, &GamePad[padNo].bmap[x], &buttonConfigStatus );
keyNameStr = ButtonName( &GamePad[padNo].bmap[x] );
keyName[x]->setText( keyNameStr );
button[x]->setText("Change");
button[x]->setStyleSheet("");
if (buttonConfigStatus != 0)
{
keyNameStr = ButtonName( &GamePad[padNo].bmap[x] );
keyName[x]->setText( keyNameStr );
lcl[padNo].btn[x].needsSave = 1;
}
ButtonConfigEnd ();
@ -582,6 +593,17 @@ void GamePadConfDialog_t::clearButton( int padNo, int x )
//----------------------------------------------------
void GamePadConfDialog_t::closeEvent(QCloseEvent *event)
{
if (changeSeqStatus != 0)
{
// change sequentially still in progress
// now try to abort its progress
changeSeqStatus = -1;
// ... out from waiting gamepad button event loop
buttonConfigStatus = 0;
// and ignore this event
event->ignore();
return;
}
promptToSave();
printf("GamePad Close Window Event\n");
@ -593,6 +615,16 @@ void GamePadConfDialog_t::closeEvent(QCloseEvent *event)
//----------------------------------------------------
void GamePadConfDialog_t::closeWindow(void)
{
if (changeSeqStatus != 0)
{
// change sequentially still in progress
// now try to abort its progress
changeSeqStatus = -1;
// ... out from waiting gamepad button event loop
buttonConfigStatus = 0;
return;
}
promptToSave();
printf("Close Window\n");
@ -947,6 +979,34 @@ void GamePadConfDialog_t::updatePeriodic(void)
efs_chkbox->setChecked( fourScore );
}
}
//----------------------------------------------------
void GamePadConfDialog_t::changeSequentallyCallback(void)
{
// get pointer to button
QPushButton* changeSeqButton = qobject_cast<QPushButton*>(sender());
if (!changeSeqButton)
return;
// disable it for user input
changeSeqButton->setEnabled(false);
// change button for every button on gamepad
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; ++i)
{
changeSeqStatus += 1;
if (this->isHidden()) break;
changeButton(portNum, i);
if (this->isHidden()) break;
// abort?
if (changeSeqStatus == -1) break;
}
// return all back
changeSeqStatus = 0;
changeSeqButton->setEnabled(true);
}
//----------------------------------------------------
GamePadConfigButton_t::GamePadConfigButton_t(int i)
{

View File

@ -52,6 +52,10 @@ class GamePadConfDialog_t : public QDialog
int portNum;
int buttonConfigStatus;
int changeSeqStatus; // status of sequentally changing buttons mechanism
// 0 - we can start new change process
// 1-10 - changing in progress
// -1 - changing is aborted
void changeButton( int port, int button );
void clearButton( int port, int button );
@ -98,6 +102,7 @@ class GamePadConfDialog_t : public QDialog
void saveProfileCallback(void);
void deleteProfileCallback(void);
void updatePeriodic(void);
void changeSequentallyCallback(void);
};