Reworking of Qt Hot Keys. Intermediate commit.

This commit is contained in:
mjbudd77 2021-03-27 22:44:55 -04:00
parent 18c7c95ef3
commit 3505e81710
7 changed files with 445 additions and 143 deletions

View File

@ -97,6 +97,8 @@ consoleWin_t::consoleWin_t(QWidget *parent)
QApplication::setStyle( new fceuStyle() ); QApplication::setStyle( new fceuStyle() );
initHotKeys();
createMainMenu(); createMainMenu();
g_config->getOption( "SDL.VideoDriver", &use_SDL_video ); g_config->getOption( "SDL.VideoDriver", &use_SDL_video );
@ -549,6 +551,20 @@ void consoleWin_t::keyReleaseEvent(QKeyEvent *event)
pushKeyEvent( event, 0 ); pushKeyEvent( event, 0 );
} }
//---------------------------------------------------------------------------
void consoleWin_t::initHotKeys(void)
{
for (int i = 0; i < HK_MAX; i++)
{
Hotkeys[i].init( this );
}
// Frame Advance uses key state directly, disable shortcut events
if ( Hotkeys[HK_FRAME_ADVANCE].getShortcut() != nullptr )
{
Hotkeys[HK_FRAME_ADVANCE].getShortcut()->setEnabled(false);
}
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void consoleWin_t::createMainMenu(void) void consoleWin_t::createMainMenu(void)
{ {
@ -574,26 +590,29 @@ void consoleWin_t::createMainMenu(void)
fileMenu = menubar->addMenu(tr("&File")); fileMenu = menubar->addMenu(tr("&File"));
// File -> Open ROM // File -> Open ROM
openROM = new QAction(tr("&Open ROM\tCtrl+O"), this); openROM = new QAction(tr("&Open ROM"), this);
openROM->setShortcuts(QKeySequence::Open); //openROM->setShortcuts(QKeySequence::Open);
openROM->setStatusTip(tr("Open ROM File")); openROM->setStatusTip(tr("Open ROM File"));
//openROM->setIcon( QIcon(":icons/rom.png") ); //openROM->setIcon( QIcon(":icons/rom.png") );
//openROM->setIcon( style->standardIcon( QStyle::SP_FileIcon ) ); //openROM->setIcon( style->standardIcon( QStyle::SP_FileIcon ) );
openROM->setIcon( style->standardIcon( QStyle::SP_FileDialogStart ) ); openROM->setIcon( style->standardIcon( QStyle::SP_FileDialogStart ) );
connect(openROM, SIGNAL(triggered()), this, SLOT(openROMFile(void)) ); connect(openROM, SIGNAL(triggered()), this, SLOT(openROMFile(void)) );
//shortcut = new QShortcut( QKeySequence::Open, this ); Hotkeys[ HK_OPEN_ROM ].setAction( openROM );
//connect(shortcut, SIGNAL(activated()), this, SLOT(openROMFile(void)) ); connect( Hotkeys[ HK_OPEN_ROM ].getShortcut(), SIGNAL(activated()), this, SLOT(openROMFile(void)) );
fileMenu->addAction(openROM); fileMenu->addAction(openROM);
// File -> Close ROM // File -> Close ROM
closeROM = new QAction(tr("&Close ROM"), this); closeROM = new QAction(tr("&Close ROM"), this);
closeROM->setShortcut( QKeySequence(tr("Ctrl+C"))); //closeROM->setShortcut( QKeySequence(tr("Ctrl+C")));
closeROM->setStatusTip(tr("Close Loaded ROM")); closeROM->setStatusTip(tr("Close Loaded ROM"));
closeROM->setIcon( style->standardIcon( QStyle::SP_BrowserStop ) ); closeROM->setIcon( style->standardIcon( QStyle::SP_BrowserStop ) );
connect(closeROM, SIGNAL(triggered()), this, SLOT(closeROMCB(void)) ); connect(closeROM, SIGNAL(triggered()), this, SLOT(closeROMCB(void)) );
Hotkeys[ HK_CLOSE_ROM ].setAction( closeROM );
connect( Hotkeys[ HK_CLOSE_ROM ].getShortcut(), SIGNAL(activated()), this, SLOT(closeROMCB(void)) );
fileMenu->addAction(closeROM); fileMenu->addAction(closeROM);
// File -> Recent ROMs // File -> Recent ROMs

View File

@ -212,6 +212,7 @@ class consoleWin_t : public QMainWindow
void showErrorMsgWindow(void); void showErrorMsgWindow(void);
private: private:
void initHotKeys(void);
void createMainMenu(void); void createMainMenu(void);
void buildRecentRomMenu(void); void buildRecentRomMenu(void);
void saveRecentRomMenu(void); void saveRecentRomMenu(void);

View File

@ -121,6 +121,7 @@ void HotKeyConfDialog_t::closeWindow(void)
void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event) void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event)
{ {
bool keyIsModifier; bool keyIsModifier;
QKeySequence ks( event->modifiers() + event->key() );
SDL_Keycode k = convQtKey2SDLKeyCode((Qt::Key)event->key()); SDL_Keycode k = convQtKey2SDLKeyCode((Qt::Key)event->key());
SDL_Keymod m = convQtKey2SDLModifier(event->modifiers()); SDL_Keymod m = convQtKey2SDLModifier(event->modifiers());
@ -130,6 +131,8 @@ void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event)
(k == SDLK_LGUI) || (k == SDLK_RGUI) || (k == SDLK_LGUI) || (k == SDLK_RGUI) ||
(k == SDLK_CAPSLOCK); (k == SDLK_CAPSLOCK);
printf("Assign: '%s' %i 0x%08x\n", ks.toString().toStdString().c_str(), event->key(), event->key() );
if ((k != SDLK_UNKNOWN) && !keyIsModifier) if ((k != SDLK_UNKNOWN) && !keyIsModifier)
{ {
QList<QTreeWidgetItem *> l; QList<QTreeWidgetItem *> l;
@ -145,40 +148,40 @@ void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event)
char keyName[128]; char keyName[128];
char buf[256]; char buf[256];
keyText.assign(" mod="); keyText = ks.toString().toStdString();
j = 0; //j = 0;
if (m & (KMOD_LSHIFT | KMOD_RSHIFT)) //if (m & (KMOD_LSHIFT | KMOD_RSHIFT))
{ //{
if (j > 0) // if (j > 0)
{ // {
keyText.append("+"); // keyText.append("+");
} // }
keyText.append("Shift"); // keyText.append("Shift");
j++; // j++;
} //}
if (m & (KMOD_LALT | KMOD_RALT)) //if (m & (KMOD_LALT | KMOD_RALT))
{ //{
if (j > 0) // if (j > 0)
{ // {
keyText.append("+"); // keyText.append("+");
} // }
keyText.append("Alt"); // keyText.append("Alt");
j++; // j++;
} //}
if (m & (KMOD_LCTRL | KMOD_RCTRL)) //if (m & (KMOD_LCTRL | KMOD_RCTRL))
{ //{
if (j > 0) // if (j > 0)
{ // {
keyText.append("+"); // keyText.append("+");
} // }
keyText.append("Ctrl"); // keyText.append("Ctrl");
j++; // j++;
} //}
sprintf(buf, " key=%s", SDL_GetKeyName(k)); //sprintf(buf, " key=%s", SDL_GetKeyName(k));
keyText.append(buf); //keyText.append(buf);
item = l.at(i); item = l.at(i);

View File

@ -53,6 +53,8 @@
#endif #endif
static const char* HotkeyStrings[HK_MAX] = { static const char* HotkeyStrings[HK_MAX] = {
"OpenROM",
"CloseROM",
"CheatMenu", "CheatMenu",
"BindState", "BindState",
"LoadLua", "LoadLua",
@ -92,6 +94,157 @@ const char *getHotkeyString( int i )
return NULL; return NULL;
} }
int getHotKeyConfig( int i, const char **nameOut, const char **keySeqOut )
{
const char *name = "";
const char *keySeq = "";
switch ( i )
{
case HK_OPEN_ROM:
name = "OpenROM"; keySeq = "Ctrl+O";
break;
case HK_CLOSE_ROM:
name = "CloseROM"; keySeq = "Ctrl+C";
break;
case HK_CHEAT_MENU:
name = "CheatMenu"; keySeq = "F1";
break;
case HK_BIND_STATE:
name = "BindState"; keySeq = "F2";
break;
case HK_LOAD_LUA:
name = "LoadLua"; keySeq = "F3";
break;
case HK_TOGGLE_BG:
name = "ToggleBG"; keySeq = "F4";
break;
case HK_SAVE_STATE:
name = "SaveState"; keySeq = "F5";
break;
case HK_FDS_SELECT:
name = "FDSSelect"; keySeq = "F6";
break;
case HK_LOAD_STATE:
name = "LoadState"; keySeq = "F7";
break;
case HK_FDS_EJECT:
name = "FDSEject"; keySeq = "F7";
break;
case HK_VS_INSERT_COIN:
name = "VSInsertCoin"; keySeq = "F6";
break;
case HK_VS_TOGGLE_DIPSWITCH:
name = "VSToggleDip"; keySeq = "F8";
break;
case HK_TOGGLE_FRAME_DISPLAY:
name = "MovieToggleFrameDisplay"; keySeq = ".";
break;
case HK_TOGGLE_SUBTITLE:
name = "SubtitleDisplay"; keySeq = "F10";
break;
case HK_RESET:
name = "Reset"; keySeq = "F11";
break;
case HK_SCREENSHOT:
name = "Screenshot"; keySeq = "F12";
break;
case HK_PAUSE:
name = "Pause"; keySeq = "Pause";
break;
case HK_DECREASE_SPEED:
name = "DecreaseSpeed"; keySeq = "-";
break;
case HK_INCREASE_SPEED:
name = "IncreaseSpeed"; keySeq = "=";
break;
case HK_FRAME_ADVANCE:
name = "FrameAdvance"; keySeq = "\\";
break;
case HK_TURBO:
name = "Turbo"; keySeq = "Tab";
break;
case HK_TOGGLE_INPUT_DISPLAY:
name = "ToggleInputDisplay"; keySeq = ",";
break;
case HK_MOVIE_TOGGLE_RW:
name = "ToggleMovieRW"; keySeq = "Q";
break;
case HK_MUTE_CAPTURE:
name = "MuteCapture"; keySeq = "'";
break;
case HK_QUIT:
name = "Quit"; keySeq = "";
break;
case HK_FA_LAG_SKIP:
name = "FrameAdvanceLagSkip"; keySeq = "Delete";
break;
case HK_LAG_COUNTER_DISPLAY:
name = "LagCounterDisplay"; keySeq = "/";
break;
case HK_SELECT_STATE_0:
name = "SelectState0"; keySeq = "0";
break;
case HK_SELECT_STATE_1:
name = "SelectState1"; keySeq = "1";
break;
case HK_SELECT_STATE_2:
name = "SelectState2"; keySeq = "2";
break;
case HK_SELECT_STATE_3:
name = "SelectState3"; keySeq = "3";
break;
case HK_SELECT_STATE_4:
name = "SelectState4"; keySeq = "4";
break;
case HK_SELECT_STATE_5:
name = "SelectState5"; keySeq = "5";
break;
case HK_SELECT_STATE_6:
name = "SelectState6"; keySeq = "6";
break;
case HK_SELECT_STATE_7:
name = "SelectState7"; keySeq = "7";
break;
case HK_SELECT_STATE_8:
name = "SelectState8"; keySeq = "8";
break;
case HK_SELECT_STATE_9:
name = "SelectState9"; keySeq = "9";
break;
case HK_SELECT_STATE_NEXT:
name = "SelectStateNext"; keySeq = "PageUp";
break;
case HK_SELECT_STATE_PREV:
name = "SelectStatePrev"; keySeq = "PageDown";
break;
case HK_VOLUME_DOWN:
name = "VolumeDown"; keySeq = "";
break;
case HK_VOLUME_UP:
name = "VolumeUp"; keySeq = "";
break;
case HK_FKB_ENABLE:
name = "FKB_Enable"; keySeq = "ScrollLock";
break;
default:
case HK_MAX:
name = ""; keySeq = "";
break;
}
if ( nameOut )
{
*nameOut = name;
}
if ( keySeqOut )
{
*keySeqOut = keySeq;
}
return 0;
}
/** /**
* Read a custom pallete from a file and load it into the core. * Read a custom pallete from a file and load it into the core.
*/ */
@ -487,53 +640,68 @@ InitConfig()
// TODO: use a better data structure to store the hotkeys or something // TODO: use a better data structure to store the hotkeys or something
// improve this code overall in the future to make it // improve this code overall in the future to make it
// easier to maintain // easier to maintain
const int Hotkeys[HK_MAX] = { //const int Hotkeys[HK_MAX] = {
SDLK_F1, // cheat menu // SDLK_F1, // cheat menu
SDLK_F2, // bind state // SDLK_F2, // bind state
SDLK_F3, // load lua // SDLK_F3, // load lua
SDLK_F4, // toggleBG // SDLK_F4, // toggleBG
SDLK_F5, // save state // SDLK_F5, // save state
SDLK_F6, // fds select // SDLK_F6, // fds select
SDLK_F7, // load state // SDLK_F7, // load state
SDLK_F8, // fds eject // SDLK_F8, // fds eject
SDLK_F6, // VS insert coin // SDLK_F6, // VS insert coin
SDLK_F8, // VS toggle dipswitch // SDLK_F8, // VS toggle dipswitch
SDLK_PERIOD, // toggle frame display // SDLK_PERIOD, // toggle frame display
SDLK_F10, // toggle subtitle // SDLK_F10, // toggle subtitle
SDLK_F11, // reset // SDLK_F11, // reset
SDLK_F12, // screenshot // SDLK_F12, // screenshot
SDLK_PAUSE, // pause // SDLK_PAUSE, // pause
SDLK_MINUS, // speed++ // SDLK_MINUS, // speed++
SDLK_EQUALS, // speed-- // SDLK_EQUALS, // speed--
SDLK_BACKSLASH, //frame advnace // SDLK_BACKSLASH, //frame advnace
SDLK_TAB, // turbo // SDLK_TAB, // turbo
SDLK_COMMA, // toggle input display // SDLK_COMMA, // toggle input display
SDLK_q, // toggle movie RW // SDLK_q, // toggle movie RW
SDLK_QUOTE, // toggle mute capture // SDLK_QUOTE, // toggle mute capture
0, // quit // edit 10/11/11 - don't map to escape, it causes ugly things to happen to sdl. can be manually appended to config // 0, // quit // edit 10/11/11 - don't map to escape, it causes ugly things to happen to sdl. can be manually appended to config
SDLK_DELETE, // frame advance lag skip // SDLK_DELETE, // frame advance lag skip
SDLK_SLASH, // lag counter display // SDLK_SLASH, // lag counter display
SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, // SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5,
SDLK_6, SDLK_7, SDLK_8, SDLK_9, // SDLK_6, SDLK_7, SDLK_8, SDLK_9,
SDLK_PAGEUP, // select state next // SDLK_PAGEUP, // select state next
SDLK_PAGEDOWN, // select state prev // SDLK_PAGEDOWN, // select state prev
0, // Volume Down Internal // 0, // Volume Down Internal
0, // Volume Up Internal // 0, // Volume Up Internal
SDLK_SCROLLLOCK }; // FKB Enable Toggle // SDLK_SCROLLLOCK }; // FKB Enable Toggle
//Hotkeys[ HK_OPEN_ROM ].init( "OpenROM", QKeySequence(QKeySequence::Open) );
prefix = "SDL.Hotkeys."; prefix = "SDL.Hotkeys.";
for(int i=0; i < HK_MAX; i++) for(int i=0; i < HK_MAX; i++)
{ {
char buf[256]; char buf[256];
std::string keyText; const char *hotKeyName, *hotKeySeq;
std::string nameText, keyText;
keyText.assign(" mod="); getHotKeyConfig( i, &hotKeyName, &hotKeySeq );
sprintf( buf, " key=%s", SDL_GetKeyName( Hotkeys[i] ) ); printf("Hot Key: '%s' = '%s' \n", hotKeyName, hotKeySeq );
keyText.append( buf ); //keyText.assign(" mod=");
config->addOption(prefix + HotkeyStrings[i], keyText); //sprintf( buf, " key=%s", SDL_GetKeyName( Hotkeys[i] ) );
if ( hotKeyName[0] != 0 )
{
nameText.assign( hotKeyName );
keyText.assign( hotKeySeq );
config->addOption(prefix + nameText, keyText);
Hotkeys[i].setConfigName( hotKeyName );
}
} }
// All mouse devices // All mouse devices
config->addOption("SDL.OekaKids.0.DeviceType", "Mouse"); config->addOption("SDL.OekaKids.0.DeviceType", "Mouse");

View File

@ -9,7 +9,7 @@ int LoadCPalette(const std::string &file);
// hotkey definitions // hotkey definitions
// TODO: encapsulate this in an improved data structure // TODO: encapsulate this in an improved data structure
enum HOTKEY { HK_CHEAT_MENU=0, HK_BIND_STATE, HK_LOAD_LUA, HK_TOGGLE_BG, enum HOTKEY { HK_OPEN_ROM=0, HK_CLOSE_ROM, HK_CHEAT_MENU, HK_BIND_STATE, HK_LOAD_LUA, HK_TOGGLE_BG,
HK_SAVE_STATE, HK_FDS_SELECT, HK_LOAD_STATE, HK_FDS_EJECT , HK_SAVE_STATE, HK_FDS_SELECT, HK_LOAD_STATE, HK_FDS_EJECT ,
HK_VS_INSERT_COIN, HK_VS_TOGGLE_DIPSWITCH, HK_VS_INSERT_COIN, HK_VS_TOGGLE_DIPSWITCH,
HK_TOGGLE_FRAME_DISPLAY, HK_TOGGLE_SUBTITLE, HK_RESET, HK_SCREENSHOT, HK_TOGGLE_FRAME_DISPLAY, HK_TOGGLE_SUBTITLE, HK_RESET, HK_SCREENSHOT,

View File

@ -204,32 +204,112 @@ struct hotkey_t Hotkeys[HK_MAX];
hotkey_t::hotkey_t(void) hotkey_t::hotkey_t(void)
{ {
value = 0; modifier = 0; prevState = 0; sdl.value = 0; sdl.modifier = 0; prevState = 0;
shortcut = nullptr;
act = nullptr;
configName = "";
} }
int hotkey_t::init( QWidget *parent )
{
std::string keyText;
std::string prefix = "SDL.Hotkeys.";
g_config->getOption (prefix + configName, &keyText);
printf("Initializing: '%s' = '%s'\n", configName, keyText.c_str() );
shortcut = new QShortcut( QKeySequence( QString::fromStdString(keyText) ), parent );
printf("ShortCut: '%s' = '%s'\n", configName, shortcut->key().toString().toStdString().c_str() );
conv2SDL();
return 0;
}
int hotkey_t::readConfig(void)
{
std::string keyText;
std::string prefix = "SDL.Hotkeys.";
g_config->getOption (prefix + configName, &keyText);
printf("Config: '%s' = '%s'\n", configName, keyText.c_str() );
if ( shortcut )
{
shortcut->setKey( QString::fromStdString( keyText ) );
printf("ShortCut: '%s' = '%s'\n", configName, shortcut->key().toString().toStdString().c_str() );
}
conv2SDL();
return 0;
}
void hotkey_t::conv2SDL(void)
{
if ( shortcut == nullptr ) return;
SDL_Keycode k = convQtKey2SDLKeyCode((Qt::Key)(shortcut->key()[0] & 0x01FFFFFF) );
SDL_Keymod m = convQtKey2SDLModifier( (Qt::KeyboardModifier)(shortcut->key()[0] & 0xFE000000) );
printf("Key: '%s' 0x%08x\n", shortcut->key().toString().toStdString().c_str(), shortcut->key()[0] );
sdl.value = k;
sdl.modifier = m;
printf("Key: SDL: '%s' \n", SDL_GetKeyName(sdl.value) );
}
void hotkey_t::setConfigName(const char *cName)
{
configName = cName;
}
void hotkey_t::setAction( QAction *actIn)
{
act = actIn;
actText = act->text();
act->setText( actText + "\t" + shortcut->key().toString() );
}
QShortcut *hotkey_t::getShortcut(void)
{
return shortcut;
}
const char *hotkey_t::getConfigName(void)
{
return configName;
}
int hotkey_t::getString( char *s ) int hotkey_t::getString( char *s )
{ {
s[0] = 0; s[0] = 0;
if ( modifier != 0 ) if ( sdl.modifier != 0 )
{ {
if ( modifier & (KMOD_LSHIFT | KMOD_RSHIFT) ) if ( sdl.modifier & (KMOD_LSHIFT | KMOD_RSHIFT) )
{ {
strcat( s, "Shift+" ); strcat( s, "Shift+" );
} }
if ( modifier & (KMOD_LALT | KMOD_RALT) ) if ( sdl.modifier & (KMOD_LALT | KMOD_RALT) )
{ {
strcat( s, "Alt+" ); strcat( s, "Alt+" );
} }
if ( modifier & (KMOD_LCTRL | KMOD_RCTRL) ) if ( sdl.modifier & (KMOD_LCTRL | KMOD_RCTRL) )
{ {
strcat( s, "Ctrl+" ); strcat( s, "Ctrl+" );
} }
} }
strcat( s, SDL_GetKeyName(value) ); strcat( s, SDL_GetKeyName(sdl.value) );
return 0; return 0;
} }
@ -238,9 +318,9 @@ int hotkey_t::getState(void)
{ {
int k; int k;
if ( modifier != 0 ) if ( sdl.modifier != 0 )
{ {
if ( modifier & (KMOD_LSHIFT | KMOD_RSHIFT) ) if ( sdl.modifier & (KMOD_LSHIFT | KMOD_RSHIFT) )
{ {
if ( !g_keyState[SDL_SCANCODE_LSHIFT] && !g_keyState[SDL_SCANCODE_RSHIFT] ) if ( !g_keyState[SDL_SCANCODE_LSHIFT] && !g_keyState[SDL_SCANCODE_RSHIFT] )
{ {
@ -248,7 +328,7 @@ int hotkey_t::getState(void)
} }
} }
if ( modifier & (KMOD_LALT | KMOD_RALT) ) if ( sdl.modifier & (KMOD_LALT | KMOD_RALT) )
{ {
if ( !g_keyState[SDL_SCANCODE_LALT] && !g_keyState[SDL_SCANCODE_RALT] ) if ( !g_keyState[SDL_SCANCODE_LALT] && !g_keyState[SDL_SCANCODE_RALT] )
{ {
@ -256,7 +336,7 @@ int hotkey_t::getState(void)
} }
} }
if ( modifier & (KMOD_LCTRL | KMOD_RCTRL) ) if ( sdl.modifier & (KMOD_LCTRL | KMOD_RCTRL) )
{ {
if ( !g_keyState[SDL_SCANCODE_LCTRL] && !g_keyState[SDL_SCANCODE_RCTRL] ) if ( !g_keyState[SDL_SCANCODE_LCTRL] && !g_keyState[SDL_SCANCODE_RCTRL] )
{ {
@ -272,7 +352,7 @@ int hotkey_t::getState(void)
} }
} }
k = SDL_GetScancodeFromKey(value); k = SDL_GetScancodeFromKey(sdl.value);
if ( (k >= 0) && (k < SDL_NUM_SCANCODES) ) if ( (k >= 0) && (k < SDL_NUM_SCANCODES) )
{ {
return g_keyState[k]; return g_keyState[k];
@ -282,7 +362,7 @@ int hotkey_t::getState(void)
int hotkey_t::getRisingEdge(void) int hotkey_t::getRisingEdge(void)
{ {
if ( value < 0 ) if ( sdl.value < 0 )
{ {
return 0; return 0;
} }
@ -308,7 +388,7 @@ void hotkey_t::setModifierFromString( const char *s )
char id[128]; char id[128];
i=0; j=0; i=0; j=0;
modifier = 0; sdl.modifier = 0;
while ( s[i] != 0 ) while ( s[i] != 0 )
{ {
@ -323,15 +403,15 @@ void hotkey_t::setModifierFromString( const char *s )
if ( strcmp( id, "ctrl" ) == 0 ) if ( strcmp( id, "ctrl" ) == 0 )
{ {
modifier |= (KMOD_LCTRL | KMOD_RCTRL); sdl.modifier |= (KMOD_LCTRL | KMOD_RCTRL);
} }
else if ( strcmp( id, "alt" ) == 0 ) else if ( strcmp( id, "alt" ) == 0 )
{ {
modifier |= (KMOD_LALT | KMOD_RALT); sdl.modifier |= (KMOD_LALT | KMOD_RALT);
} }
else if ( strcmp( id, "shift" ) == 0 ) else if ( strcmp( id, "shift" ) == 0 )
{ {
modifier |= (KMOD_LSHIFT | KMOD_RSHIFT); sdl.modifier |= (KMOD_LSHIFT | KMOD_RSHIFT);
} }
if ( (s[i] == '+') || (s[i] == '|') ) if ( (s[i] == '+') || (s[i] == '|') )
@ -353,59 +433,59 @@ setHotKeys (void)
std::string keyText; std::string keyText;
std::string prefix = "SDL.Hotkeys."; std::string prefix = "SDL.Hotkeys.";
char id[64], val[128]; char id[64], val[128];
const char *hotKeyName, *hotKeySeq;
//SDL_Keycode SDL_GetKeyFromName(const char* name) //SDL_Keycode SDL_GetKeyFromName(const char* name)
for (int i = 0; i < HK_MAX; i++) for (int i = 0; i < HK_MAX; i++)
{ {
g_config->getOption (prefix + getHotkeyString(i), &keyText); Hotkeys[i].readConfig();
//g_config->getOption (prefix + Hotkeys[i].getConfigName(), &keyText);
//printf("Key: '%s'\n", keyText.c_str() ); //j=0;
j=0; //while ( keyText[j] != 0 )
//{
// while ( isspace(keyText[j]) ) j++;
while ( keyText[j] != 0 ) // if ( isalpha( keyText[j] ) || (keyText[j] == '_') )
{ // {
while ( isspace(keyText[j]) ) j++; // k=0;
// while ( isalnum( keyText[j] ) || (keyText[j] == '_') )
// {
// id[k] = keyText[j]; j++; k++;
// }
// id[k] = 0;
if ( isalpha( keyText[j] ) || (keyText[j] == '_') ) // if ( keyText[j] != '=' )
{ // {
k=0; // printf("Error: Invalid Hot Key Config for %s = %s \n", getHotkeyString(i), keyText.c_str() );
while ( isalnum( keyText[j] ) || (keyText[j] == '_') ) // break;
{ // }
id[k] = keyText[j]; j++; k++; // j++;
}
id[k] = 0;
if ( keyText[j] != '=' ) // k=0;
{ // while ( !isspace(keyText[j]) && (keyText[j] != 0) )
printf("Error: Invalid Hot Key Config for %s = %s \n", getHotkeyString(i), keyText.c_str() ); // {
break; // val[k] = keyText[j]; j++; k++;
} // }
j++; // val[k] = 0;
k=0; // //printf("ID:%s Val:%s \n", id, val );
while ( !isspace(keyText[j]) && (keyText[j] != 0) )
{
val[k] = keyText[j]; j++; k++;
}
val[k] = 0;
//printf("ID:%s Val:%s \n", id, val ); // if ( strcmp( id, "key" ) == 0 )
// {
if ( strcmp( id, "key" ) == 0 ) // Hotkeys[i].sdl.value = SDL_GetKeyFromName( val );
{ // }
Hotkeys[i].value = SDL_GetKeyFromName( val ); // else if ( strcmp( id, "mod" ) == 0 )
} // {
else if ( strcmp( id, "mod" ) == 0 ) // Hotkeys[i].setModifierFromString( val );
{ // }
Hotkeys[i].setModifierFromString( val ); // }
} // else
} // {
else // break;
{ // }
break; //}
}
}
} }
return; return;

View File

@ -4,6 +4,11 @@
#include <stdint.h> #include <stdint.h>
#include <list> #include <list>
#include <QWidget>
#include <QKeySequence>
#include <QShortcut>
#include <QAction>
#include "common/configSys.h" #include "common/configSys.h"
//#define MAXBUTTCONFIG 4 //#define MAXBUTTCONFIG 4
@ -34,23 +39,49 @@ void ButtonConfigEnd();
void ConfigButton(char *text, ButtConfig *bc); void ConfigButton(char *text, ButtConfig *bc);
int DWaitButton(const uint8_t *text, ButtConfig *bc, int *buttonConfigStatus = NULL); int DWaitButton(const uint8_t *text, ButtConfig *bc, int *buttonConfigStatus = NULL);
struct hotkey_t class hotkey_t
{ {
int value; public:
int modifier; // Methods
char prevState; hotkey_t(void);
hotkey_t(void); int init( QWidget *parent );
int getState(void); int readConfig(void);
int getRisingEdge(void); int getState(void);
int getString( char *s ); int getRisingEdge(void);
void setModifierFromString( const char *s ); int getString( char *s );
void setModifierFromString( const char *s );
void setConfigName(const char *cName);
void setAction( QAction *act );
const char *getConfigName(void);
QShortcut *getShortcut(void);
// Member variables
struct
{
int value;
int modifier;
} sdl;
char prevState;
private:
void conv2SDL(void);
const char *configName;
QKeySequence keySeq;
QShortcut *shortcut;
QAction *act;
QString actText;
}; };
extern struct hotkey_t Hotkeys[]; extern class hotkey_t Hotkeys[];
struct gamepad_function_key_t struct gamepad_function_key_t
{ {