Removed scroll bars from Qt game pad window as its new layout makes it unnecessary.

This commit is contained in:
mjbudd77 2021-02-13 20:10:20 -05:00
parent 5abdc4a50e
commit bff4dd4d93
2 changed files with 182 additions and 157 deletions

View File

@ -23,6 +23,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QScrollArea> #include <QScrollArea>
#include <QScrollBar>
#include <QPainter> #include <QPainter>
#include "Qt/GamePadConf.h" #include "Qt/GamePadConf.h"
@ -86,12 +87,12 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
: QDialog( parent ) : QDialog( parent )
, changeSeqStatus(0) , changeSeqStatus(0)
{ {
QWidget *mainWidget; //QWidget *mainWidget;
QVBoxLayout *mainLayoutV; QVBoxLayout *mainLayoutV;
QHBoxLayout *mainLayoutH; QHBoxLayout *mainLayoutH;
QHBoxLayout *hbox, *hbox1, *hbox2, *hbox3, *hbox4, *hbox5; QHBoxLayout *hbox, *hbox1, *hbox2;
QVBoxLayout *vbox, *vbox1, *vbox2; QVBoxLayout *vbox, *vbox1, *vbox2;
QGridLayout *grid; QGridLayout *grid, *grid1;
QCheckBox *udlr_chkbox; QCheckBox *udlr_chkbox;
QGroupBox *frame1, *frame2; QGroupBox *frame1, *frame2;
QLabel *label; QLabel *label;
@ -103,10 +104,11 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
QPushButton *closebutton; QPushButton *closebutton;
QPushButton *changeSeqButton = nullptr; QPushButton *changeSeqButton = nullptr;
QPushButton *clearButton[GAMEPAD_NUM_BUTTONS]; QPushButton *clearButton[GAMEPAD_NUM_BUTTONS];
QScrollArea *scroll; QScrollArea *scroll = NULL;
QStyle *style; QStyle *style;
std::string prefix; std::string prefix;
char stmp[256]; char stmp[256];
bool useScroll = false;
style = this->style(); style = this->style();
@ -115,7 +117,10 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
// Ensure that joysticks are enabled, no harm calling init again. // Ensure that joysticks are enabled, no harm calling init again.
InitJoysticks(); InitJoysticks();
if ( useScroll )
{
scroll = new QScrollArea(this); scroll = new QScrollArea(this);
}
mainWidget = new QWidget(); mainWidget = new QWidget();
portNum = 0; portNum = 0;
@ -127,16 +132,17 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
setWindowTitle( tr("GamePad Config") ); setWindowTitle( tr("GamePad Config") );
grid1 = new QGridLayout();
grid1->setColumnStretch( 0, 1 );
grid1->setColumnStretch( 1, 10 );
hbox1 = new QHBoxLayout(); hbox1 = new QHBoxLayout();
hbox2 = new QHBoxLayout(); hbox2 = new QHBoxLayout();
hbox3 = new QHBoxLayout();
hbox4 = new QHBoxLayout();
hbox5 = new QHBoxLayout();
label = new QLabel(tr("Console Port:")); label = new QLabel(tr("Console Port:"));
portSel = new QComboBox(); portSel = new QComboBox();
hbox1->addWidget( label ); grid1->addWidget( label , 0, 0 );
hbox1->addWidget( portSel ); grid1->addWidget( portSel, 0, 1 );
portSel->addItem( tr("1"), 0 ); portSel->addItem( tr("1"), 0 );
portSel->addItem( tr("2"), 1 ); portSel->addItem( tr("2"), 1 );
@ -145,8 +151,8 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
label = new QLabel(tr("Device:")); label = new QLabel(tr("Device:"));
devSel = new QComboBox(); devSel = new QComboBox();
hbox2->addWidget( label ); grid1->addWidget( label , 1, 0 );
hbox2->addWidget( devSel ); grid1->addWidget( devSel, 1, 1 );
devSel->addItem( tr("Keyboard"), -1 ); devSel->addItem( tr("Keyboard"), -1 );
@ -174,8 +180,8 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
label = new QLabel(tr("GUID:")); label = new QLabel(tr("GUID:"));
guidLbl = new QLabel(); guidLbl = new QLabel();
hbox3->addWidget( label ); grid1->addWidget( label , 2, 0 );
hbox3->addWidget( guidLbl ); grid1->addWidget( guidLbl, 2, 1 );
guidLbl->setText( GamePad[portNum].getGUID() ); guidLbl->setText( GamePad[portNum].getGUID() );
@ -238,7 +244,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
frame2 = new QGroupBox(tr("Current Active Button Mappings:")); frame2 = new QGroupBox(tr("Current Active Button Mappings:"));
grid = new QGridLayout(); grid = new QGridLayout();
grid-> setHorizontalSpacing(50); //grid-> setHorizontalSpacing(10);
frame2->setLayout( grid ); frame2->setLayout( grid );
@ -255,17 +261,17 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
buttonName = new QLabel(tr(text)); buttonName = new QLabel(tr(text));
keyName[i] = new QLabel(); keyName[i] = new QLabel();
keyState[i] = new QLabel( tr("F") ); //keyState[i] = new QLabel( tr("F") );
label = new QLabel( tr("State:") ); //label = new QLabel( tr("State:") );
button[i] = new GamePadConfigButton_t(i); button[i] = new GamePadConfigButton_t(i);
clearButton[i] = new QPushButton( tr("Clear") ); clearButton[i] = new QPushButton( tr("Clear") );
grid->addWidget( buttonName , i, 0, Qt::AlignCenter ); grid->addWidget( buttonName , i, 0, Qt::AlignCenter );
grid->addWidget( keyName[i] , i, 1, Qt::AlignCenter ); grid->addWidget( keyName[i] , i, 1, Qt::AlignCenter );
grid->addWidget( label , i, 2, Qt::AlignCenter ); //grid->addWidget( label , i, 2, Qt::AlignCenter );
grid->addWidget( keyState[i] , i, 3, Qt::AlignCenter ); //grid->addWidget( keyState[i] , i, 3, Qt::AlignCenter );
grid->addWidget( button[i] , i, 4, Qt::AlignCenter ); grid->addWidget( button[i] , i, 2, Qt::AlignCenter );
grid->addWidget( clearButton[i], i, 5, Qt::AlignCenter ); grid->addWidget( clearButton[i], i, 3, Qt::AlignCenter );
} }
updateCntrlrDpy(); updateCntrlrDpy();
@ -277,9 +283,9 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
closebutton->setIcon( style->standardIcon( QStyle::SP_DialogCloseButton ) ); closebutton->setIcon( style->standardIcon( QStyle::SP_DialogCloseButton ) );
changeSeqButton->setIcon( style->standardIcon( QStyle::QStyle::SP_ArrowDown ) ); changeSeqButton->setIcon( style->standardIcon( QStyle::QStyle::SP_ArrowDown ) );
hbox4->addWidget( clearAllButton ); hbox1->addWidget( clearAllButton );
hbox4->addWidget( changeSeqButton ); hbox1->addWidget( changeSeqButton );
hbox4->addWidget( closebutton ); hbox1->addWidget( closebutton );
connect(button[0], SIGNAL(clicked()), this, SLOT(changeButton0(void)) ); connect(button[0], SIGNAL(clicked()), this, SLOT(changeButton0(void)) );
connect(button[1], SIGNAL(clicked()), this, SLOT(changeButton1(void)) ); connect(button[1], SIGNAL(clicked()), this, SLOT(changeButton1(void)) );
@ -322,17 +328,17 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
vbox1 = new QVBoxLayout(); vbox1 = new QVBoxLayout();
vbox2 = new QVBoxLayout(); vbox2 = new QVBoxLayout();
hbox5->addWidget( efs_chkbox ); hbox2->addWidget( efs_chkbox );
hbox5->addWidget( udlr_chkbox ); hbox2->addWidget( udlr_chkbox );
vbox1->addLayout( hbox1 ); vbox1->addLayout( grid1 );
vbox1->addLayout( hbox2 ); //vbox1->addLayout( hbox2 );
vbox1->addLayout( hbox3 ); //vbox1->addLayout( hbox3 );
vbox1->addWidget( frame1); vbox1->addWidget( frame1);
vbox1->addLayout( hbox5 ); vbox1->addLayout( hbox2 );
vbox2->addWidget( frame2 ); vbox2->addWidget( frame2 );
vbox2->addLayout( hbox4 ); vbox2->addLayout( hbox1 );
gpView = new GamePadView_t(this); gpView = new GamePadView_t(this);
@ -345,15 +351,25 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
mainWidget->setLayout( mainLayoutH ); mainWidget->setLayout( mainLayoutH );
mainWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); mainWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
if ( useScroll )
{
scroll->setWidget( mainWidget ); scroll->setWidget( mainWidget );
scroll->setWidgetResizable(true); scroll->setWidgetResizable(true);
scroll->setSizeAdjustPolicy( QAbstractScrollArea::AdjustToContents ); scroll->setSizeAdjustPolicy( QAbstractScrollArea::AdjustToContents );
scroll->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); scroll->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
scroll->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); scroll->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
}
QHBoxLayout *dialogLayout = new QHBoxLayout(); QHBoxLayout *dialogLayout = new QHBoxLayout();
if ( useScroll )
{
dialogLayout->addWidget( scroll ); dialogLayout->addWidget( scroll );
}
else
{
dialogLayout->addWidget( mainWidget );
}
setLayout( dialogLayout ); setLayout( dialogLayout );
@ -370,6 +386,7 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
} }
loadMapList(); loadMapList();
} }
//---------------------------------------------------- //----------------------------------------------------
@ -381,6 +398,12 @@ GamePadConfDialog_t::~GamePadConfDialog_t(void)
printf("GamePad Window Deleted\n"); printf("GamePad Window Deleted\n");
} }
void GamePadConfDialog_t::resizeEvent(QResizeEvent *event)
{
//printf("%ix%i\n", event->size().width(), event->size().height() );
}
void GamePadConfDialog_t::keyPressEvent(QKeyEvent *event) void GamePadConfDialog_t::keyPressEvent(QKeyEvent *event)
{ {
//printf("GamePad Window Key Press: 0x%x \n", event->key() ); //printf("GamePad Window Key Press: 0x%x \n", event->key() );
@ -948,7 +971,6 @@ void GamePadConfDialog_t::promptToSave(void)
msgBox.setText( tr(msg.c_str()) ); msgBox.setText( tr(msg.c_str()) );
msgBox.show(); msgBox.show();
//msgBox.resize( 512, 128 );
msgBox.exec(); msgBox.exec();
} }
//---------------------------------------------------- //----------------------------------------------------
@ -956,19 +978,19 @@ void GamePadConfDialog_t::updatePeriodic(void)
{ {
for (int i=0; i<GAMEPAD_NUM_BUTTONS; i++) for (int i=0; i<GAMEPAD_NUM_BUTTONS; i++)
{ {
const char *txt, *style; //const char *txt, *style;
if ( GamePad[portNum].bmap[i].state ) //if ( GamePad[portNum].bmap[i].state )
{ //{
txt = " T "; // txt = " T ";
style = "background-color: green; color: white;"; // style = "background-color: green; color: white;";
} //}
else //else
{ //{
txt = " F "; // txt = " F ";
style = "background-color: red; color: white;"; // style = "background-color: red; color: white;";
} //}
keyState[i]->setText( tr(txt) ); //keyState[i]->setText( tr(txt) );
keyState[i]->setStyleSheet( style ); //keyState[i]->setStyleSheet( style );
if ( lcl[portNum].btn[i].needsSave ) if ( lcl[portNum].btn[i].needsSave )
{ {

View File

@ -68,6 +68,9 @@ class GamePadConfDialog_t : public QDialog
~GamePadConfDialog_t(void); ~GamePadConfDialog_t(void);
protected: protected:
void resizeEvent(QResizeEvent *event);
QWidget *mainWidget;
QTimer *inputTimer; QTimer *inputTimer;
QComboBox *portSel; QComboBox *portSel;
QComboBox *devSel; QComboBox *devSel;