Added initial window layout for advanced gamepad key binding feature.

This commit is contained in:
mjbudd77 2021-03-21 21:11:16 -04:00
parent 3836e03f53
commit 13d93f1b84
4 changed files with 133 additions and 0 deletions

View File

@ -25,6 +25,10 @@
#include <QScrollArea>
#include <QScrollBar>
#include <QPainter>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QHeaderView>
#include "Qt/GamePadConf.h"
#include "Qt/main.h"
@ -108,6 +112,11 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
std::string prefix;
char stmp[256];
bool useScroll = false;
int useNativeMenuBar;
QMenuBar *menuBar;
QMenu *fileMenu;
QAction *act;
QTreeWidgetItem *item;
style = this->style();
@ -131,6 +140,31 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
setWindowTitle(tr("GamePad Config"));
menuBar = new QMenuBar(this);
// This is needed for menu bar to show up on MacOS
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
menuBar->setNativeMenuBar( useNativeMenuBar ? true : false );
//-----------------------------------------------------------------------
// Menu Start
//-----------------------------------------------------------------------
// File
fileMenu = menuBar->addMenu(tr("&File"));
// File -> Close
act = new QAction(tr("&Close"), this);
act->setShortcut(QKeySequence::Close);
act->setStatusTip(tr("Close Window"));
connect(act, SIGNAL(triggered()), this, SLOT(closeWindow(void)) );
fileMenu->addAction(act);
//-----------------------------------------------------------------------
// Menu End
//-----------------------------------------------------------------------
grid1 = new QGridLayout();
grid1->setColumnStretch(0, 1);
@ -341,15 +375,54 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
gpView = new GamePadView_t(this);
advOptLayout = new QGroupBox( tr("Advanced Key Bindings") );
mainLayoutV->addLayout(vbox1);
mainLayoutV->addWidget(gpView);
mainLayoutH->addLayout(mainLayoutV);
mainLayoutH->addLayout(vbox2);
mainLayoutH->addWidget(advOptLayout);
mainLayoutH->setMenuBar( menuBar );
mainWidget->setLayout(mainLayoutH);
mainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
hbox1 = new QHBoxLayout();
vbox = new QVBoxLayout();
advOptLayout->setLayout(hbox1);
hbox1->addLayout(vbox);
newKeyBindBtn = new QPushButton( tr("New") );
editKeyBindBtn = new QPushButton( tr("Edit") );
delKeyBindBtn = new QPushButton( tr("Delete") );
vbox->addWidget( newKeyBindBtn , 1 );
vbox->addWidget( editKeyBindBtn, 1 );
vbox->addWidget( delKeyBindBtn , 1 );
vbox->addStretch(5);
keyBindTree = new QTreeWidget();
keyBindTree->setColumnCount(2);
item = new QTreeWidgetItem();
item->setText(0, QString::fromStdString("JS Button"));
item->setText(1, QString::fromStdString("Key Binding"));
item->setTextAlignment(0, Qt::AlignLeft);
item->setTextAlignment(1, Qt::AlignLeft);
keyBindTree->setHeaderItem(item);
keyBindTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
hbox1->addWidget(keyBindTree);
connect( newKeyBindBtn, SIGNAL(clicked()), this, SLOT(newKeyBindingCallback(void)));
connect(editKeyBindBtn, SIGNAL(clicked()), this, SLOT(editKeyBindingCallback(void)));
connect( delKeyBindBtn, SIGNAL(clicked()), this, SLOT(delKeyBindingCallback(void)));
if (useScroll)
{
scroll->setWidget(mainWidget);
@ -385,6 +458,8 @@ GamePadConfDialog_t::GamePadConfDialog_t(QWidget *parent)
}
loadMapList();
refreshKeyBindTree();
}
//----------------------------------------------------
@ -489,6 +564,31 @@ void GamePadConfDialog_t::loadMapList(void)
}
}
//----------------------------------------------------
void GamePadConfDialog_t::refreshKeyBindTree(void)
{
QTreeWidgetItem *item;
std::list <gamepad_function_key_t*>::iterator it;
gamepad_function_key_t *binding;
const char *btnName;
for (it=gpKeySeqList.begin(); it!=gpKeySeqList.end(); it++)
{
binding = *it;
item = new QTreeWidgetItem();
btnName = ButtonName( &binding->bc );
item->setText(0, QString::fromStdString(btnName));
//item->setText(1, QString::fromStdString(keyName));
item->setTextAlignment(0, Qt::AlignLeft);
item->setTextAlignment(1, Qt::AlignLeft);
keyBindTree->addTopLevelItem(item);
}
}
//----------------------------------------------------
void GamePadConfDialog_t::updateCntrlrDpy(void)
{
char keyNameStr[128];
@ -972,6 +1072,21 @@ void GamePadConfDialog_t::promptToSave(void)
msgBox.exec();
}
//----------------------------------------------------
void GamePadConfDialog_t::newKeyBindingCallback(void)
{
// TODO
}
//----------------------------------------------------
void GamePadConfDialog_t::editKeyBindingCallback(void)
{
// TODO
}
//----------------------------------------------------
void GamePadConfDialog_t::delKeyBindingCallback(void)
{
// TODO
}
//----------------------------------------------------
void GamePadConfDialog_t::updatePeriodic(void)
{
for (int i = 0; i < GAMEPAD_NUM_BUTTONS; i++)

View File

@ -15,6 +15,8 @@
#include <QTimer>
#include <QGroupBox>
#include <QPainter>
#include <QTreeView>
#include <QTreeWidget>
#include "Qt/main.h"
@ -78,6 +80,7 @@ protected:
QComboBox *mapSel;
QComboBox *profSel;
QCheckBox *efs_chkbox;
QGroupBox *advOptLayout;
QLabel *guidLbl;
QLabel *mapMsg;
QLabel *keyName[GAMEPAD_NUM_BUTTONS];
@ -85,6 +88,11 @@ protected:
GamePadConfigButton_t *button[GAMEPAD_NUM_BUTTONS];
GamePadView_t *gpView;
QPushButton *newKeyBindBtn;
QPushButton *editKeyBindBtn;
QPushButton *delKeyBindBtn;
QTreeWidget *keyBindTree;
int portNum;
int buttonConfigStatus;
int changeSeqStatus; // status of sequentally changing buttons mechanism
@ -98,6 +106,8 @@ protected:
void keyReleaseEvent(QKeyEvent *event);
void closeEvent(QCloseEvent *bar);
void refreshKeyBindTree(void);
private:
void updateCntrlrDpy(void);
void createNewProfile(const char *name);
@ -139,6 +149,9 @@ private slots:
void deleteProfileCallback(void);
void updatePeriodic(void);
void changeSequentallyCallback(void);
void newKeyBindingCallback(void);
void editKeyBindingCallback(void);
void delKeyBindingCallback(void);
};
int openGamePadConfWindow(QWidget *parent);

View File

@ -65,6 +65,8 @@ static int buttonConfigInProgress = 0;
extern int gametype;
std::list <gamepad_function_key_t*> gpKeySeqList;
/**
* Necessary for proper GUI functioning (configuring when a game isn't loaded).
*/

View File

@ -2,6 +2,7 @@
#define _aosdfjk02fmasf
#include <stdint.h>
#include <list>
#include "common/configSys.h"
@ -65,6 +66,8 @@ struct gamepad_function_key_t
void sendKeyReleaseEvent(void);
};
extern std::list <gamepad_function_key_t*> gpKeySeqList;
#define FCFGD_GAMEPAD 1
#define FCFGD_POWERPAD 2
#define FCFGD_HYPERSHOT 3