diff --git a/fceux.pro b/fceux.pro index 80711047..f4fe1fc8 100644 --- a/fceux.pro +++ b/fceux.pro @@ -298,12 +298,14 @@ HEADERS += src/drivers/Qt/ConsoleWindow.h HEADERS += src/drivers/Qt/ConsoleViewerGL.h HEADERS += src/drivers/Qt/ConsoleViewerSDL.h HEADERS += src/drivers/Qt/GamePadConf.h +HEADERS += src/drivers/Qt/HotKeyConf.h HEADERS += src/drivers/Qt/ConsoleSoundConf.h SOURCES += src/drivers/Qt/main.cpp SOURCES += src/drivers/Qt/ConsoleWindow.cpp SOURCES += src/drivers/Qt/ConsoleViewerGL.cpp SOURCES += src/drivers/Qt/ConsoleViewerSDL.cpp SOURCES += src/drivers/Qt/GamePadConf.cpp +SOURCES += src/drivers/Qt/HotKeyConf.cpp SOURCES += src/drivers/Qt/ConsoleSoundConf.cpp SOURCES += src/drivers/Qt/fceuWrapper.cpp SOURCES += src/drivers/Qt/config.cpp diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 19a779f2..d718926a 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -7,6 +7,7 @@ #include "Qt/input.h" #include "Qt/ConsoleWindow.h" #include "Qt/GamePadConf.h" +#include "Qt/HotKeyConf.h" #include "Qt/ConsoleSoundConf.h" #include "Qt/fceuWrapper.h" #include "Qt/keyscan.h" @@ -149,6 +150,14 @@ void consoleWin_t::createMainMenu(void) optMenu->addAction(gameSoundConfig); + // Options -> HotKey Config + hotkeyConfig = new QAction(tr("Hotkey Config"), this); + //hotkeyConfig->setShortcut( QKeySequence(tr("Ctrl+C"))); + hotkeyConfig->setStatusTip(tr("Hotkey Configure")); + connect(hotkeyConfig, SIGNAL(triggered()), this, SLOT(openHotkeyConfWin(void)) ); + + optMenu->addAction(hotkeyConfig); + //----------------------------------------------------------------------- // Help helpMenu = menuBar()->addMenu(tr("Help")); @@ -259,7 +268,7 @@ void consoleWin_t::openGameSndConfWin(void) { ConsoleSndConfDialog_t *sndConfWin; - printf("Open Sound Config Window\n"); + //printf("Open Sound Config Window\n"); sndConfWin = new ConsoleSndConfDialog_t(this); @@ -268,7 +277,23 @@ void consoleWin_t::openGameSndConfWin(void) delete sndConfWin; - printf("Sound Config Window Destroyed\n"); + //printf("Sound Config Window Destroyed\n"); +} + +void consoleWin_t::openHotkeyConfWin(void) +{ + HotKeyConfDialog_t *hkConfWin; + + printf("Open Hot Key Config Window\n"); + + hkConfWin = new HotKeyConfDialog_t(this); + + hkConfWin->show(); + hkConfWin->exec(); + + delete hkConfWin; + + printf("Hotkey Config Window Destroyed\n"); } void consoleWin_t::aboutQPlot(void) diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 672d4546..87e931af 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -56,6 +56,7 @@ class consoleWin_t : public QMainWindow QAction *quitAct; QAction *gamePadConfig; QAction *gameSoundConfig; + QAction *hotkeyConfig; QAction *aboutAct; QTimer *gameTimer; @@ -78,6 +79,7 @@ class consoleWin_t : public QMainWindow void aboutQPlot(void); void openGamePadConfWin(void); void openGameSndConfWin(void); + void openHotkeyConfWin(void); void updatePeriodic(void); }; diff --git a/src/drivers/Qt/HotKeyConf.cpp b/src/drivers/Qt/HotKeyConf.cpp new file mode 100644 index 00000000..13c33f1c --- /dev/null +++ b/src/drivers/Qt/HotKeyConf.cpp @@ -0,0 +1,125 @@ +// HotKeyConf.cpp +// +#include +#include +#include +#include + +#include +#include + +#include "Qt/main.h" +#include "Qt/dface.h" +#include "Qt/input.h" +#include "Qt/config.h" +#include "Qt/keyscan.h" +#include "Qt/fceuWrapper.h" +#include "Qt/HotKeyConf.h" + +//---------------------------------------------------------------------------- +HotKeyConfDialog_t::HotKeyConfDialog_t(QWidget *parent) + : QDialog( parent ) +{ + QVBoxLayout *mainLayout; + QTreeWidgetItem *item; + std::string prefix = "SDL.Hotkeys."; + int keycode; + + setWindowTitle("Hotkey Configuration"); + + resize( 512, 512 ); + + mainLayout = new QVBoxLayout(); + + tree = new QTreeWidget(); + + tree->setColumnCount(2); + + 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; igetOption (optionName.c_str (), &keycode); + + item = new QTreeWidgetItem(); + + item->setText( 0, QString::fromStdString( optionName ) ); + item->setText( 1, QString::fromStdString( SDL_GetKeyName (keycode) ) ); + + item->setTextAlignment( 0, Qt::AlignLeft); + item->setTextAlignment( 1, Qt::AlignCenter); + + tree->addTopLevelItem( item ); + } + mainLayout->addWidget( tree ); + + setLayout( mainLayout ); +} +//---------------------------------------------------------------------------- +HotKeyConfDialog_t::~HotKeyConfDialog_t(void) +{ + +} +//---------------------------------------------------------------------------- +void HotKeyConfDialog_t::closeWindow(void) +{ + //printf("Close Window\n"); + done(0); +} +//---------------------------------------------------------------------------- +void HotKeyConfDialog_t::assignHotkey(QKeyEvent *event) +{ + SDL_Keycode k = convQtKey2SDLKeyCode( (Qt::Key)event->key() ); + + if ( k != SDLK_UNKNOWN ) + { + QList l; + + l = tree->selectedItems(); + + for (size_t i=0; i < l.size(); i++) + { + //int idx; + QString qs; + QTreeWidgetItem *item; + + item = l.at(i); + + //idx = tree->indexOfTopLevelItem( item ); + + qs = item->text(0); + + g_config->setOption ( qs.toStdString(), k ); + + setHotKeys(); + + item->setText( 1, QString::fromStdString( SDL_GetKeyName (k) ) ); + + //printf("Hotkey Window Key Press: 0x%x item:%p\n '%s' : %i\n", + // k, item, qs.toStdString().c_str(), idx ); + } + } +} +//---------------------------------------------------------------------------- +void HotKeyConfDialog_t::keyPressEvent(QKeyEvent *event) +{ + //printf("Hotkey Window Key Press: 0x%x \n", event->key() ); + assignHotkey( event ); +} +//---------------------------------------------------------------------------- +void HotKeyConfDialog_t::keyReleaseEvent(QKeyEvent *event) +{ + //printf("Hotkey Window Key Release: 0x%x \n", event->key() ); + assignHotkey( event ); +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/HotKeyConf.h b/src/drivers/Qt/HotKeyConf.h new file mode 100644 index 00000000..cba35cee --- /dev/null +++ b/src/drivers/Qt/HotKeyConf.h @@ -0,0 +1,42 @@ +// GamePadConf.h +// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Qt/main.h" + +class HotKeyConfDialog_t : public QDialog +{ + Q_OBJECT + + public: + HotKeyConfDialog_t(QWidget *parent = 0); + ~HotKeyConfDialog_t(void); + + protected: + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *event); + void assignHotkey(QKeyEvent *event); + + QTreeWidget *tree; + + private: + + public slots: + void closeWindow(void); + private slots: + +}; diff --git a/src/drivers/Qt/input.h b/src/drivers/Qt/input.h index af5f0c47..d9a70118 100644 --- a/src/drivers/Qt/input.h +++ b/src/drivers/Qt/input.h @@ -27,7 +27,7 @@ extern CFGSTRUCT InputConfig[]; extern ARGPSTRUCT InputArgs[]; extern int Hotkeys[]; void ParseGIInput(FCEUGI *GI); -void setHotKeys(); +void setHotKeys(void); int getKeyState( int k ); int ButtonConfigBegin(); void ButtonConfigEnd();