Merge remote-tracking branch 'mjbudd77/master'

This commit is contained in:
mjbudd77 2021-06-13 22:01:52 -04:00
commit 279b7c0e58
4 changed files with 273 additions and 17 deletions

View File

@ -1266,6 +1266,9 @@ void GamePadConfDialog_t::delKeyBindingCallback(void)
//----------------------------------------------------
void GamePadConfDialog_t::updatePeriodic(void)
{
char jsFound[ MAX_JOYSTICKS ];
memset( jsFound, 0, sizeof(jsFound) );
for (int i = 0; i < devSel->count(); i++)
{
@ -1290,6 +1293,7 @@ void GamePadConfDialog_t::updatePeriodic(void)
devSel->removeItem(i);
deviceSelect( devSel->currentIndex() );
}
jsFound[ devIdx ] = 1;
}
}
@ -1301,15 +1305,7 @@ void GamePadConfDialog_t::updatePeriodic(void)
{
if (js->isConnected())
{
char jsFound = 0;
for (int j = 0; j < devSel->count(); j++)
{
if ( devSel->itemData(j).toInt() == i )
{
jsFound = 1; break;
}
}
if ( !jsFound )
if ( !jsFound[i] )
{
char stmp[256];
//printf("Adding Newly Connected JS\n");
@ -1941,14 +1937,76 @@ void GamePadFuncConfigDialog::changeButton1(void)
//----------------------------------------------------
void GamePadFuncConfigDialog::changeKeySeq0(void)
{
hk[0]->setCaptureState(true);
hk[0]->setStyleSheet("background-color: green; color: white;");
int ret;
HotKeySelectDialog_t hkd;
ret = hkd.exec();
if ( ret == QDialog::Accepted )
{
hotkey_t *hkp;
char keyName[128];
//printf("Accepted Hot Key: %i\n", hkd.getSelHotKey() );
k->hk[0] = hkd.getSelHotKey();
hkp = &Hotkeys[ k->hk[0] ];
hkp->getString(keyName);
k->keySeq[0].key = hkp->qkey.value;
k->keySeq[0].modifier = hkp->qkey.modifier;
k->keySeq[0].name.assign(hkp->getConfigName());
if ( keySeqLbl[0] )
{
keySeqLbl[0]->setText( tr(hkp->getConfigName()) );
}
}
//else
//{
// printf("Rejected Hot Key\n");
//}
//hk[0]->setCaptureState(true);
//hk[0]->setStyleSheet("background-color: green; color: white;");
}
//----------------------------------------------------
void GamePadFuncConfigDialog::changeKeySeq1(void)
{
hk[1]->setCaptureState(true);
hk[1]->setStyleSheet("background-color: green; color: white;");
int ret;
HotKeySelectDialog_t hkd;
ret = hkd.exec();
if ( ret == QDialog::Accepted )
{
hotkey_t *hkp;
char keyName[128];
//printf("Accepted Hot Key: %i\n", hkd.getSelHotKey() );
k->hk[1] = hkd.getSelHotKey();
hkp = &Hotkeys[ k->hk[1] ];
hkp->getString(keyName);
k->keySeq[1].key = hkp->qkey.value;
k->keySeq[1].modifier = hkp->qkey.modifier;
k->keySeq[1].name.assign(keyName);
if ( keySeqLbl[1] )
{
keySeqLbl[1]->setText( tr(hkp->getConfigName()) );
}
}
//else
//{
// printf("Rejected Hot Key\n");
//}
//hk[1]->setCaptureState(true);
//hk[1]->setStyleSheet("background-color: green; color: white;");
}
//----------------------------------------------------
void GamePadFuncConfigDialog::clearButton0(void)
@ -1976,6 +2034,9 @@ void GamePadFuncConfigDialog::clearButton2(void)
k->keySeq[0].key = 0;
k->keySeq[0].modifier = 0;
k->keySeq[0].name.clear();
k->hk[0] = -1;
keySeqLbl[0]->clear();
}
//----------------------------------------------------
void GamePadFuncConfigDialog::clearButton3(void)
@ -1983,6 +2044,9 @@ void GamePadFuncConfigDialog::clearButton3(void)
k->keySeq[1].key = 0;
k->keySeq[1].modifier = 0;
k->keySeq[1].name.clear();
k->hk[1] = -1;
keySeqLbl[1]->clear();
}
//----------------------------------------------------
GamePadConfigHotKey_t::GamePadConfigHotKey_t(int idxIn, gamepad_function_key_t *fk)
@ -2034,3 +2098,123 @@ void GamePadConfigHotKey_t::keyReleaseEvent(QKeyEvent *event)
//printf("GamePad Hot Key Release: 0x%x \n", event->key() );
}
//----------------------------------------------------
// Hot Key Selection Dialog
//----------------------------------------------------
HotKeySelectDialog_t::HotKeySelectDialog_t( QWidget *parent )
: QDialog(parent)
{
QVBoxLayout *mainLayout;
QHBoxLayout *hbox;
QTreeWidgetItem *item;
std::string prefix = "SDL.Hotkeys.";
hotKeyIdx = -1;
setWindowTitle("Hotkey Select");
resize(512, 512);
mainLayout = new QVBoxLayout();
tree = new QTreeWidget(this);
tree->setColumnCount(2);
tree->setSelectionMode( QAbstractItemView::SingleSelection );
item = new QTreeWidgetItem();
item->setText(0, QString::fromStdString("Command"));
item->setText(1, QString::fromStdString("Key"));
item->setTextAlignment(0, Qt::AlignLeft);
item->setTextAlignment(1, Qt::AlignCenter);
tree->setHeaderItem(item);
tree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
for (int i = 0; i < HK_MAX; i++)
{
char keyName[128];
std::string optionName = prefix + Hotkeys[i].getConfigName();
//g_config->getOption (optionName.c_str (), &keycode);
Hotkeys[i].getString(keyName);
item = new QTreeWidgetItem();
tree->addTopLevelItem(item);
//item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren );
//item->setCheckState( 0, Qt::Checked );
item->setText(0, QString::fromStdString(optionName));
item->setText(1, QString::fromStdString(keyName));
item->setTextAlignment(0, Qt::AlignLeft);
item->setTextAlignment(1, Qt::AlignCenter);
}
connect( tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
this, SLOT(hotkeyItemClicked(QTreeWidgetItem *, int)));
mainLayout->addWidget(tree);
okButton = new QPushButton( tr("Ok") );
okButton->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton));
okButton->setEnabled(false);
connect(okButton, SIGNAL(clicked(void)), this, SLOT(acceptCB(void)));
cancelButton = new QPushButton( tr("Cancel") );
cancelButton->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
connect(cancelButton, SIGNAL(clicked(void)), this, SLOT(rejectCB(void)));
hbox = new QHBoxLayout();
hbox->addWidget( cancelButton, 1 );
hbox->addStretch(5);
hbox->addWidget( okButton, 1 );
mainLayout->addLayout( hbox );
setLayout(mainLayout);
}
//----------------------------------------------------
HotKeySelectDialog_t::~HotKeySelectDialog_t(void)
{
}
//----------------------------------------------------
void HotKeySelectDialog_t::hotkeyItemClicked(QTreeWidgetItem *item, int column)
{
int row = tree->indexOfTopLevelItem(item);
if ( (row >= 0) && (row < HK_MAX) )
{
hotKeyIdx = row;
okButton->setEnabled(true);
}
}
//----------------------------------------------------
void HotKeySelectDialog_t::closeEvent(QCloseEvent *event)
{
done( result() );
deleteLater();
event->accept();
}
//----------------------------------------------------
void HotKeySelectDialog_t::acceptCB(void)
{
done( QDialog::Accepted );
deleteLater();
}
//----------------------------------------------------
void HotKeySelectDialog_t::rejectCB(void)
{
done( QDialog::Rejected );
deleteLater();
}
//----------------------------------------------------
void HotKeySelectDialog_t::closeWindow(void)
{
done( result() );
deleteLater();
}
//----------------------------------------------------

View File

@ -52,6 +52,32 @@ protected:
bool captureState;
};
class HotKeySelectDialog_t : public QDialog
{
Q_OBJECT
public:
HotKeySelectDialog_t( QWidget *parent = 0);
~HotKeySelectDialog_t(void);
int getSelHotKey(void){ return hotKeyIdx; };
protected:
void closeEvent(QCloseEvent *bar);
QTreeWidget *tree;
QPushButton *okButton;
QPushButton *cancelButton;
int hotKeyIdx;
public slots:
void closeWindow(void);
private slots:
void acceptCB(void);
void rejectCB(void);
void hotkeyItemClicked(QTreeWidgetItem *item, int column);
};
class GamePadFuncConfigDialog : public QDialog
{
Q_OBJECT

View File

@ -200,6 +200,8 @@ hotkey_t::hotkey_t(void)
{
sdl.value = 0;
sdl.modifier = 0;
qkey.value = 0;
qkey.modifier = 0;
prevState = 0;
shortcut = nullptr;
act = nullptr;
@ -253,6 +255,9 @@ void hotkey_t::conv2SDL(void)
if (shortcut == nullptr)
return;
qkey.value = (Qt::Key)(shortcut->key()[0] & 0x01FFFFFF);
qkey.modifier = (Qt::KeyboardModifier)(shortcut->key()[0] & 0xFE000000);
SDL_Keycode k = convQtKey2SDLKeyCode((Qt::Key)(shortcut->key()[0] & 0x01FFFFFF));
SDL_Keymod m = convQtKey2SDLModifier((Qt::KeyboardModifier)(shortcut->key()[0] & 0xFE000000));
@ -450,6 +455,11 @@ gamepad_function_key_t::gamepad_function_key_t(void)
{
keySeq[i].key = 0;
keySeq[i].modifier = Qt::NoModifier;
keyRelReq[i] = 0;
}
for (int i = 0; i < 2; i++)
{
hk[i] = -1;
}
for (int i = 0; i < 2; i++)
{
@ -464,16 +474,41 @@ gamepad_function_key_t::~gamepad_function_key_t(void)
void gamepad_function_key_t::sendKeyPressEvent(int idx)
{
QKeyEvent *k = new QKeyEvent(QEvent::KeyPress, keySeq[idx].key, (Qt::KeyboardModifiers)keySeq[idx].modifier);
bool hasShortcut = false;
qApp->postEvent((QObject *)consoleWindow, (QEvent *)k);
// If the hot key has a shortcut associated with it,
// activate shortcut directly instead of attempting to send key sequence events.
if ( (hk[idx] >= 0) && (hk[idx] < HK_MAX) )
{
QShortcut *s = Hotkeys[ hk[idx] ].getShortcut();
if ( s && s->isEnabled() )
{
emit s->activated();
hasShortcut = true;
}
}
if ( !hasShortcut && (keySeq[idx].key > 0) )
{
QKeyEvent *k = new QKeyEvent(QEvent::KeyPress, keySeq[idx].key, (Qt::KeyboardModifiers)keySeq[idx].modifier);
qApp->postEvent((QObject *)consoleWindow, (QEvent *)k);
keyRelReq[idx] = 1;
}
}
void gamepad_function_key_t::sendKeyReleaseEvent(int idx)
{
QKeyEvent *k = new QKeyEvent(QEvent::KeyRelease, keySeq[idx].key, (Qt::KeyboardModifiers)keySeq[idx].modifier);
if ( keyRelReq[idx] )
{
QKeyEvent *k = new QKeyEvent(QEvent::KeyRelease, keySeq[idx].key, (Qt::KeyboardModifiers)keySeq[idx].modifier);
qApp->postEvent((QObject *)consoleWindow, (QEvent *)k);
qApp->postEvent((QObject *)consoleWindow, (QEvent *)k);
keyRelReq[idx] = 0;
}
}
void gamepad_function_key_t::updateStatus(void)

View File

@ -61,6 +61,8 @@ class hotkey_t
const char *getConfigName(void);
QShortcut *getShortcut(void);
QKeySequence getKeySeq(void){ return keySeq; };
// Member variables
struct
{
@ -68,6 +70,12 @@ class hotkey_t
int modifier;
} sdl;
struct
{
int value;
int modifier;
} qkey;
char prevState;
private:
@ -90,6 +98,9 @@ struct gamepad_function_key_t
} keySeq[2];
int hk[2];
char keyRelReq[2];
struct ButtConfig bmap[2];
gamepad_function_key_t(void);