Reworking of Qt Hot Keys. Intermediate commit.
This commit is contained in:
parent
18c7c95ef3
commit
3505e81710
|
@ -97,6 +97,8 @@ consoleWin_t::consoleWin_t(QWidget *parent)
|
|||
|
||||
QApplication::setStyle( new fceuStyle() );
|
||||
|
||||
initHotKeys();
|
||||
|
||||
createMainMenu();
|
||||
|
||||
g_config->getOption( "SDL.VideoDriver", &use_SDL_video );
|
||||
|
@ -549,6 +551,20 @@ void consoleWin_t::keyReleaseEvent(QKeyEvent *event)
|
|||
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)
|
||||
{
|
||||
|
@ -574,26 +590,29 @@ void consoleWin_t::createMainMenu(void)
|
|||
fileMenu = menubar->addMenu(tr("&File"));
|
||||
|
||||
// File -> Open ROM
|
||||
openROM = new QAction(tr("&Open ROM\tCtrl+O"), this);
|
||||
openROM->setShortcuts(QKeySequence::Open);
|
||||
openROM = new QAction(tr("&Open ROM"), this);
|
||||
//openROM->setShortcuts(QKeySequence::Open);
|
||||
openROM->setStatusTip(tr("Open ROM File"));
|
||||
//openROM->setIcon( QIcon(":icons/rom.png") );
|
||||
//openROM->setIcon( style->standardIcon( QStyle::SP_FileIcon ) );
|
||||
openROM->setIcon( style->standardIcon( QStyle::SP_FileDialogStart ) );
|
||||
connect(openROM, SIGNAL(triggered()), this, SLOT(openROMFile(void)) );
|
||||
|
||||
//shortcut = new QShortcut( QKeySequence::Open, this );
|
||||
//connect(shortcut, SIGNAL(activated()), this, SLOT(openROMFile(void)) );
|
||||
Hotkeys[ HK_OPEN_ROM ].setAction( openROM );
|
||||
connect( Hotkeys[ HK_OPEN_ROM ].getShortcut(), SIGNAL(activated()), this, SLOT(openROMFile(void)) );
|
||||
|
||||
fileMenu->addAction(openROM);
|
||||
|
||||
// File -> Close ROM
|
||||
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->setIcon( style->standardIcon( QStyle::SP_BrowserStop ) );
|
||||
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);
|
||||
|
||||
// File -> Recent ROMs
|
||||
|
|
|
@ -212,6 +212,7 @@ class consoleWin_t : public QMainWindow
|
|||
void showErrorMsgWindow(void);
|
||||
|
||||
private:
|
||||
void initHotKeys(void);
|
||||
void createMainMenu(void);
|
||||
void buildRecentRomMenu(void);
|
||||
void saveRecentRomMenu(void);
|
||||
|
|
|
@ -121,6 +121,7 @@ void HotKeyConfDialog_t::closeWindow(void)
|
|||
void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event)
|
||||
{
|
||||
bool keyIsModifier;
|
||||
QKeySequence ks( event->modifiers() + event->key() );
|
||||
SDL_Keycode k = convQtKey2SDLKeyCode((Qt::Key)event->key());
|
||||
SDL_Keymod m = convQtKey2SDLModifier(event->modifiers());
|
||||
|
||||
|
@ -130,6 +131,8 @@ void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event)
|
|||
(k == SDLK_LGUI) || (k == SDLK_RGUI) ||
|
||||
(k == SDLK_CAPSLOCK);
|
||||
|
||||
printf("Assign: '%s' %i 0x%08x\n", ks.toString().toStdString().c_str(), event->key(), event->key() );
|
||||
|
||||
if ((k != SDLK_UNKNOWN) && !keyIsModifier)
|
||||
{
|
||||
QList<QTreeWidgetItem *> l;
|
||||
|
@ -145,40 +148,40 @@ void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event)
|
|||
char keyName[128];
|
||||
char buf[256];
|
||||
|
||||
keyText.assign(" mod=");
|
||||
keyText = ks.toString().toStdString();
|
||||
|
||||
j = 0;
|
||||
if (m & (KMOD_LSHIFT | KMOD_RSHIFT))
|
||||
{
|
||||
if (j > 0)
|
||||
{
|
||||
keyText.append("+");
|
||||
}
|
||||
keyText.append("Shift");
|
||||
j++;
|
||||
}
|
||||
if (m & (KMOD_LALT | KMOD_RALT))
|
||||
{
|
||||
if (j > 0)
|
||||
{
|
||||
keyText.append("+");
|
||||
}
|
||||
keyText.append("Alt");
|
||||
j++;
|
||||
}
|
||||
if (m & (KMOD_LCTRL | KMOD_RCTRL))
|
||||
{
|
||||
if (j > 0)
|
||||
{
|
||||
keyText.append("+");
|
||||
}
|
||||
keyText.append("Ctrl");
|
||||
j++;
|
||||
}
|
||||
//j = 0;
|
||||
//if (m & (KMOD_LSHIFT | KMOD_RSHIFT))
|
||||
//{
|
||||
// if (j > 0)
|
||||
// {
|
||||
// keyText.append("+");
|
||||
// }
|
||||
// keyText.append("Shift");
|
||||
// j++;
|
||||
//}
|
||||
//if (m & (KMOD_LALT | KMOD_RALT))
|
||||
//{
|
||||
// if (j > 0)
|
||||
// {
|
||||
// keyText.append("+");
|
||||
// }
|
||||
// keyText.append("Alt");
|
||||
// j++;
|
||||
//}
|
||||
//if (m & (KMOD_LCTRL | KMOD_RCTRL))
|
||||
//{
|
||||
// if (j > 0)
|
||||
// {
|
||||
// keyText.append("+");
|
||||
// }
|
||||
// keyText.append("Ctrl");
|
||||
// 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);
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@
|
|||
#endif
|
||||
|
||||
static const char* HotkeyStrings[HK_MAX] = {
|
||||
"OpenROM",
|
||||
"CloseROM",
|
||||
"CheatMenu",
|
||||
"BindState",
|
||||
"LoadLua",
|
||||
|
@ -92,6 +94,157 @@ const char *getHotkeyString( int i )
|
|||
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.
|
||||
*/
|
||||
|
@ -487,53 +640,68 @@ InitConfig()
|
|||
// TODO: use a better data structure to store the hotkeys or something
|
||||
// improve this code overall in the future to make it
|
||||
// easier to maintain
|
||||
const int Hotkeys[HK_MAX] = {
|
||||
SDLK_F1, // cheat menu
|
||||
SDLK_F2, // bind state
|
||||
SDLK_F3, // load lua
|
||||
SDLK_F4, // toggleBG
|
||||
SDLK_F5, // save state
|
||||
SDLK_F6, // fds select
|
||||
SDLK_F7, // load state
|
||||
SDLK_F8, // fds eject
|
||||
SDLK_F6, // VS insert coin
|
||||
SDLK_F8, // VS toggle dipswitch
|
||||
SDLK_PERIOD, // toggle frame display
|
||||
SDLK_F10, // toggle subtitle
|
||||
SDLK_F11, // reset
|
||||
SDLK_F12, // screenshot
|
||||
SDLK_PAUSE, // pause
|
||||
SDLK_MINUS, // speed++
|
||||
SDLK_EQUALS, // speed--
|
||||
SDLK_BACKSLASH, //frame advnace
|
||||
SDLK_TAB, // turbo
|
||||
SDLK_COMMA, // toggle input display
|
||||
SDLK_q, // toggle movie RW
|
||||
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
|
||||
SDLK_DELETE, // frame advance lag skip
|
||||
SDLK_SLASH, // lag counter display
|
||||
SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5,
|
||||
SDLK_6, SDLK_7, SDLK_8, SDLK_9,
|
||||
SDLK_PAGEUP, // select state next
|
||||
SDLK_PAGEDOWN, // select state prev
|
||||
0, // Volume Down Internal
|
||||
0, // Volume Up Internal
|
||||
SDLK_SCROLLLOCK }; // FKB Enable Toggle
|
||||
//const int Hotkeys[HK_MAX] = {
|
||||
// SDLK_F1, // cheat menu
|
||||
// SDLK_F2, // bind state
|
||||
// SDLK_F3, // load lua
|
||||
// SDLK_F4, // toggleBG
|
||||
// SDLK_F5, // save state
|
||||
// SDLK_F6, // fds select
|
||||
// SDLK_F7, // load state
|
||||
// SDLK_F8, // fds eject
|
||||
// SDLK_F6, // VS insert coin
|
||||
// SDLK_F8, // VS toggle dipswitch
|
||||
// SDLK_PERIOD, // toggle frame display
|
||||
// SDLK_F10, // toggle subtitle
|
||||
// SDLK_F11, // reset
|
||||
// SDLK_F12, // screenshot
|
||||
// SDLK_PAUSE, // pause
|
||||
// SDLK_MINUS, // speed++
|
||||
// SDLK_EQUALS, // speed--
|
||||
// SDLK_BACKSLASH, //frame advnace
|
||||
// SDLK_TAB, // turbo
|
||||
// SDLK_COMMA, // toggle input display
|
||||
// SDLK_q, // toggle movie RW
|
||||
// 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
|
||||
// SDLK_DELETE, // frame advance lag skip
|
||||
// SDLK_SLASH, // lag counter display
|
||||
// SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5,
|
||||
// SDLK_6, SDLK_7, SDLK_8, SDLK_9,
|
||||
// SDLK_PAGEUP, // select state next
|
||||
// SDLK_PAGEDOWN, // select state prev
|
||||
// 0, // Volume Down Internal
|
||||
// 0, // Volume Up Internal
|
||||
// SDLK_SCROLLLOCK }; // FKB Enable Toggle
|
||||
|
||||
|
||||
//Hotkeys[ HK_OPEN_ROM ].init( "OpenROM", QKeySequence(QKeySequence::Open) );
|
||||
|
||||
prefix = "SDL.Hotkeys.";
|
||||
|
||||
for(int i=0; i < HK_MAX; i++)
|
||||
{
|
||||
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
|
||||
config->addOption("SDL.OekaKids.0.DeviceType", "Mouse");
|
||||
|
|
|
@ -9,7 +9,7 @@ int LoadCPalette(const std::string &file);
|
|||
|
||||
// hotkey definitions
|
||||
// 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_VS_INSERT_COIN, HK_VS_TOGGLE_DIPSWITCH,
|
||||
HK_TOGGLE_FRAME_DISPLAY, HK_TOGGLE_SUBTITLE, HK_RESET, HK_SCREENSHOT,
|
||||
|
|
|
@ -204,32 +204,112 @@ struct hotkey_t Hotkeys[HK_MAX];
|
|||
|
||||
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 )
|
||||
{
|
||||
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+" );
|
||||
}
|
||||
|
||||
if ( modifier & (KMOD_LALT | KMOD_RALT) )
|
||||
if ( sdl.modifier & (KMOD_LALT | KMOD_RALT) )
|
||||
{
|
||||
strcat( s, "Alt+" );
|
||||
}
|
||||
|
||||
if ( modifier & (KMOD_LCTRL | KMOD_RCTRL) )
|
||||
if ( sdl.modifier & (KMOD_LCTRL | KMOD_RCTRL) )
|
||||
{
|
||||
strcat( s, "Ctrl+" );
|
||||
}
|
||||
}
|
||||
|
||||
strcat( s, SDL_GetKeyName(value) );
|
||||
strcat( s, SDL_GetKeyName(sdl.value) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -238,9 +318,9 @@ int hotkey_t::getState(void)
|
|||
{
|
||||
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] )
|
||||
{
|
||||
|
@ -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] )
|
||||
{
|
||||
|
@ -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] )
|
||||
{
|
||||
|
@ -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) )
|
||||
{
|
||||
return g_keyState[k];
|
||||
|
@ -282,7 +362,7 @@ int hotkey_t::getState(void)
|
|||
|
||||
int hotkey_t::getRisingEdge(void)
|
||||
{
|
||||
if ( value < 0 )
|
||||
if ( sdl.value < 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -308,7 +388,7 @@ void hotkey_t::setModifierFromString( const char *s )
|
|||
char id[128];
|
||||
|
||||
i=0; j=0;
|
||||
modifier = 0;
|
||||
sdl.modifier = 0;
|
||||
|
||||
while ( s[i] != 0 )
|
||||
{
|
||||
|
@ -323,15 +403,15 @@ void hotkey_t::setModifierFromString( const char *s )
|
|||
|
||||
if ( strcmp( id, "ctrl" ) == 0 )
|
||||
{
|
||||
modifier |= (KMOD_LCTRL | KMOD_RCTRL);
|
||||
sdl.modifier |= (KMOD_LCTRL | KMOD_RCTRL);
|
||||
}
|
||||
else if ( strcmp( id, "alt" ) == 0 )
|
||||
{
|
||||
modifier |= (KMOD_LALT | KMOD_RALT);
|
||||
sdl.modifier |= (KMOD_LALT | KMOD_RALT);
|
||||
}
|
||||
else if ( strcmp( id, "shift" ) == 0 )
|
||||
{
|
||||
modifier |= (KMOD_LSHIFT | KMOD_RSHIFT);
|
||||
sdl.modifier |= (KMOD_LSHIFT | KMOD_RSHIFT);
|
||||
}
|
||||
|
||||
if ( (s[i] == '+') || (s[i] == '|') )
|
||||
|
@ -353,59 +433,59 @@ setHotKeys (void)
|
|||
std::string keyText;
|
||||
std::string prefix = "SDL.Hotkeys.";
|
||||
char id[64], val[128];
|
||||
const char *hotKeyName, *hotKeySeq;
|
||||
//SDL_Keycode SDL_GetKeyFromName(const char* name)
|
||||
|
||||
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 )
|
||||
{
|
||||
while ( isspace(keyText[j]) ) j++;
|
||||
// if ( isalpha( keyText[j] ) || (keyText[j] == '_') )
|
||||
// {
|
||||
// k=0;
|
||||
// while ( isalnum( keyText[j] ) || (keyText[j] == '_') )
|
||||
// {
|
||||
// id[k] = keyText[j]; j++; k++;
|
||||
// }
|
||||
// id[k] = 0;
|
||||
|
||||
if ( isalpha( keyText[j] ) || (keyText[j] == '_') )
|
||||
{
|
||||
k=0;
|
||||
while ( isalnum( keyText[j] ) || (keyText[j] == '_') )
|
||||
{
|
||||
id[k] = keyText[j]; j++; k++;
|
||||
}
|
||||
id[k] = 0;
|
||||
// if ( keyText[j] != '=' )
|
||||
// {
|
||||
// printf("Error: Invalid Hot Key Config for %s = %s \n", getHotkeyString(i), keyText.c_str() );
|
||||
// break;
|
||||
// }
|
||||
// j++;
|
||||
|
||||
if ( keyText[j] != '=' )
|
||||
{
|
||||
printf("Error: Invalid Hot Key Config for %s = %s \n", getHotkeyString(i), keyText.c_str() );
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
// k=0;
|
||||
// while ( !isspace(keyText[j]) && (keyText[j] != 0) )
|
||||
// {
|
||||
// val[k] = keyText[j]; j++; k++;
|
||||
// }
|
||||
// val[k] = 0;
|
||||
|
||||
k=0;
|
||||
while ( !isspace(keyText[j]) && (keyText[j] != 0) )
|
||||
{
|
||||
val[k] = keyText[j]; j++; k++;
|
||||
}
|
||||
val[k] = 0;
|
||||
// //printf("ID:%s Val:%s \n", id, val );
|
||||
|
||||
//printf("ID:%s Val:%s \n", id, val );
|
||||
|
||||
if ( strcmp( id, "key" ) == 0 )
|
||||
{
|
||||
Hotkeys[i].value = SDL_GetKeyFromName( val );
|
||||
}
|
||||
else if ( strcmp( id, "mod" ) == 0 )
|
||||
{
|
||||
Hotkeys[i].setModifierFromString( val );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if ( strcmp( id, "key" ) == 0 )
|
||||
// {
|
||||
// Hotkeys[i].sdl.value = SDL_GetKeyFromName( val );
|
||||
// }
|
||||
// else if ( strcmp( id, "mod" ) == 0 )
|
||||
// {
|
||||
// Hotkeys[i].setModifierFromString( val );
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
#include <stdint.h>
|
||||
#include <list>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QKeySequence>
|
||||
#include <QShortcut>
|
||||
#include <QAction>
|
||||
|
||||
#include "common/configSys.h"
|
||||
|
||||
//#define MAXBUTTCONFIG 4
|
||||
|
@ -34,23 +39,49 @@ void ButtonConfigEnd();
|
|||
void ConfigButton(char *text, ButtConfig *bc);
|
||||
int DWaitButton(const uint8_t *text, ButtConfig *bc, int *buttonConfigStatus = NULL);
|
||||
|
||||
struct hotkey_t
|
||||
class hotkey_t
|
||||
{
|
||||
int value;
|
||||
int modifier;
|
||||
char prevState;
|
||||
public:
|
||||
// Methods
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue