Changed Qt GUI hot key set logic to be more like Win32 version. Each key now spawns a set/clear key state dialog window.
This commit is contained in:
parent
cf7d23694c
commit
1d7dd522ba
|
@ -79,8 +79,8 @@ HotKeyConfDialog_t::HotKeyConfDialog_t(QWidget *parent)
|
||||||
|
|
||||||
tree->addTopLevelItem(item);
|
tree->addTopLevelItem(item);
|
||||||
|
|
||||||
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren );
|
//item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren );
|
||||||
item->setCheckState( 0, Qt::Checked );
|
//item->setCheckState( 0, Qt::Checked );
|
||||||
|
|
||||||
item->setText(0, QString::fromStdString(optionName));
|
item->setText(0, QString::fromStdString(optionName));
|
||||||
item->setText(1, QString::fromStdString(keyName));
|
item->setText(1, QString::fromStdString(keyName));
|
||||||
|
@ -89,6 +89,10 @@ HotKeyConfDialog_t::HotKeyConfDialog_t(QWidget *parent)
|
||||||
item->setTextAlignment(1, Qt::AlignCenter);
|
item->setTextAlignment(1, Qt::AlignCenter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect( tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(hotKeyDoubleClicked(QTreeWidgetItem*,int) ) );
|
||||||
|
connect( tree, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(hotKeyActivated(QTreeWidgetItem*,int) ) );
|
||||||
|
|
||||||
mainLayout->addWidget(tree);
|
mainLayout->addWidget(tree);
|
||||||
|
|
||||||
closeButton = new QPushButton( tr("Close") );
|
closeButton = new QPushButton( tr("Close") );
|
||||||
|
@ -123,105 +127,36 @@ void HotKeyConfDialog_t::closeWindow(void)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
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());
|
|
||||||
|
|
||||||
keyIsModifier = (k == SDLK_LCTRL) || (k == SDLK_RCTRL) ||
|
|
||||||
(k == SDLK_LSHIFT) || (k == SDLK_RSHIFT) ||
|
|
||||||
(k == SDLK_LALT) || (k == SDLK_RALT) ||
|
|
||||||
(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;
|
|
||||||
|
|
||||||
l = tree->selectedItems();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < l.size(); i++)
|
|
||||||
{
|
|
||||||
int j, idx;
|
|
||||||
QString qs;
|
|
||||||
QTreeWidgetItem *item;
|
|
||||||
std::string keyText;
|
|
||||||
char keyName[128];
|
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
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++;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//sprintf(buf, " key=%s", SDL_GetKeyName(k));
|
|
||||||
|
|
||||||
//keyText.append(buf);
|
|
||||||
|
|
||||||
item = l.at(i);
|
|
||||||
|
|
||||||
idx = tree->indexOfTopLevelItem(item);
|
|
||||||
|
|
||||||
qs = item->text(0);
|
|
||||||
|
|
||||||
g_config->setOption(qs.toStdString(), keyText);
|
|
||||||
|
|
||||||
setHotKeys();
|
|
||||||
|
|
||||||
Hotkeys[idx].getString(keyName);
|
|
||||||
|
|
||||||
item->setText(1, QString::fromStdString(keyName));
|
|
||||||
|
|
||||||
//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)
|
void HotKeyConfDialog_t::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
//printf("Hotkey Window Key Press: 0x%x \n", event->key() );
|
//printf("Hotkey Window Key Press: 0x%x \n", event->key() );
|
||||||
assignHotkey(event);
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void HotKeyConfDialog_t::keyReleaseEvent(QKeyEvent *event)
|
void HotKeyConfDialog_t::keyReleaseEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
//printf("Hotkey Window Key Release: 0x%x \n", event->key() );
|
//printf("Hotkey Window Key Release: 0x%x \n", event->key() );
|
||||||
assignHotkey(event);
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfDialog_t::hotKeyActivated(QTreeWidgetItem *item, int column)
|
||||||
|
{
|
||||||
|
int row = tree->indexOfTopLevelItem( item );
|
||||||
|
|
||||||
|
HotKeyConfSetDialog_t *win = new HotKeyConfSetDialog_t( row, 1, item, this );
|
||||||
|
|
||||||
|
win->exec();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfDialog_t::hotKeyDoubleClicked(QTreeWidgetItem *item, int column)
|
||||||
|
{
|
||||||
|
int row = tree->indexOfTopLevelItem( item );
|
||||||
|
|
||||||
|
HotKeyConfSetDialog_t *win = new HotKeyConfSetDialog_t( row, 0, item, this );
|
||||||
|
|
||||||
|
win->exec();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
HotKeyConfTree_t::HotKeyConfTree_t(QWidget *parent)
|
HotKeyConfTree_t::HotKeyConfTree_t(QWidget *parent)
|
||||||
: QTreeWidget(parent)
|
: QTreeWidget(parent)
|
||||||
{
|
{
|
||||||
|
@ -235,19 +170,191 @@ HotKeyConfTree_t::~HotKeyConfTree_t(void)
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void HotKeyConfTree_t::keyPressEvent(QKeyEvent *event)
|
void HotKeyConfTree_t::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
if ( parent() )
|
//if ( parent() )
|
||||||
{
|
//{
|
||||||
static_cast<HotKeyConfDialog_t*>(parent())->assignHotkey(event);
|
// static_cast<HotKeyConfDialog_t*>(parent())->assignHotkey(event);
|
||||||
}
|
//}
|
||||||
event->accept();
|
//if ( event->key() == Qt::Key_Enter )
|
||||||
|
//{
|
||||||
|
// QTreeWidgetItem *item;
|
||||||
|
|
||||||
|
// item = currentItem();
|
||||||
|
|
||||||
|
// event->accept();
|
||||||
|
// if ( item )
|
||||||
|
// {
|
||||||
|
// HotKeyConfSetDialog_t *win = new HotKeyConfSetDialog_t( indexOfTopLevelItem( item ), item, this );
|
||||||
|
|
||||||
|
// win->exec();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
QTreeWidget::keyPressEvent(event);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void HotKeyConfTree_t::keyReleaseEvent(QKeyEvent *event)
|
void HotKeyConfTree_t::keyReleaseEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
if ( parent() )
|
//if ( parent() )
|
||||||
|
//{
|
||||||
|
// static_cast<HotKeyConfDialog_t*>(parent())->assignHotkey(event);
|
||||||
|
//}
|
||||||
|
QTreeWidget::keyReleaseEvent(event);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
HotKeyConfSetDialog_t::HotKeyConfSetDialog_t( int hkIndex, int discardNum, QTreeWidgetItem *itemIn, QWidget *parent )
|
||||||
|
: QDialog(parent)
|
||||||
|
{
|
||||||
|
QVBoxLayout *mainLayout;
|
||||||
|
QHBoxLayout *hbox;
|
||||||
|
QPushButton *clearButton, *okButton;
|
||||||
|
|
||||||
|
idx = hkIndex;
|
||||||
|
item = itemIn;
|
||||||
|
discardCount = discardNum;
|
||||||
|
|
||||||
|
setWindowTitle("Set Hot Key");
|
||||||
|
|
||||||
|
mainLayout = new QVBoxLayout();
|
||||||
|
hbox = new QHBoxLayout();
|
||||||
|
|
||||||
|
keySeqText = new QLineEdit();
|
||||||
|
keySeqText->setReadOnly(true);
|
||||||
|
keySeqText->setText( tr("Press a Key") );
|
||||||
|
|
||||||
|
mainLayout->addWidget(keySeqText);
|
||||||
|
|
||||||
|
mainLayout->addLayout( hbox );
|
||||||
|
|
||||||
|
clearButton = new QPushButton( tr("Clear") );
|
||||||
|
okButton = new QPushButton( tr("Ok") );
|
||||||
|
|
||||||
|
clearButton->setIcon(style()->standardIcon(QStyle::SP_DialogResetButton));
|
||||||
|
okButton->setIcon(style()->standardIcon(QStyle::SP_DialogApplyButton));
|
||||||
|
|
||||||
|
hbox->addWidget( clearButton );
|
||||||
|
hbox->addWidget( okButton );
|
||||||
|
|
||||||
|
setLayout( mainLayout );
|
||||||
|
|
||||||
|
connect( clearButton, SIGNAL(clicked(void)), this, SLOT(cleanButtonCB(void)) );
|
||||||
|
connect( okButton, SIGNAL(clicked(void)), this, SLOT( okButtonCB(void)) );
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
HotKeyConfSetDialog_t::~HotKeyConfSetDialog_t(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_t::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
//printf("Hot Key Close Window Event\n");
|
||||||
|
done(0);
|
||||||
|
deleteLater();
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_t::closeWindow(void)
|
||||||
|
{
|
||||||
|
//printf("Close Window\n");
|
||||||
|
done(0);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_t::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
//printf("Hotkey Window Key Press: 0x%x \n", event->key() );
|
||||||
|
if ( discardCount == 0 )
|
||||||
{
|
{
|
||||||
static_cast<HotKeyConfDialog_t*>(parent())->assignHotkey(event);
|
assignHotkey(event);
|
||||||
|
}
|
||||||
|
else if ( discardCount > 0 )
|
||||||
|
{
|
||||||
|
discardCount--;
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_t::keyReleaseEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
if ( discardCount == 0 )
|
||||||
|
{
|
||||||
|
assignHotkey(event);
|
||||||
|
}
|
||||||
|
else if ( discardCount > 0 )
|
||||||
|
{
|
||||||
|
discardCount--;
|
||||||
|
}
|
||||||
|
//printf("Hotkey Window Key Release: 0x%x \n", event->key() );
|
||||||
|
//assignHotkey(event);
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_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());
|
||||||
|
|
||||||
|
keyIsModifier = (k == SDLK_LCTRL) || (k == SDLK_RCTRL) ||
|
||||||
|
(k == SDLK_LSHIFT) || (k == SDLK_RSHIFT) ||
|
||||||
|
(k == SDLK_LALT) || (k == SDLK_RALT) ||
|
||||||
|
(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)
|
||||||
|
{
|
||||||
|
std::string keyText;
|
||||||
|
std::string prefix = "SDL.Hotkeys.";
|
||||||
|
std::string confName;
|
||||||
|
|
||||||
|
confName = prefix + Hotkeys[idx].getConfigName();
|
||||||
|
|
||||||
|
keyText = ks.toString().toStdString();
|
||||||
|
|
||||||
|
g_config->setOption( confName, keyText);
|
||||||
|
|
||||||
|
setHotKeys();
|
||||||
|
|
||||||
|
if ( item )
|
||||||
|
{
|
||||||
|
item->setText(1, QString::fromStdString(keyText));
|
||||||
|
}
|
||||||
|
|
||||||
|
done(0);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_t::cleanButtonCB(void)
|
||||||
|
{
|
||||||
|
std::string prefix = "SDL.Hotkeys.";
|
||||||
|
std::string confName;
|
||||||
|
|
||||||
|
confName = prefix + Hotkeys[idx].getConfigName();
|
||||||
|
|
||||||
|
g_config->setOption( confName, "");
|
||||||
|
|
||||||
|
setHotKeys();
|
||||||
|
|
||||||
|
if ( item )
|
||||||
|
{
|
||||||
|
item->setText(1, tr(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
done(0);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void HotKeyConfSetDialog_t::okButtonCB(void)
|
||||||
|
{
|
||||||
|
done(0);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QLineEdit>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
@ -18,6 +19,32 @@
|
||||||
|
|
||||||
#include "Qt/main.h"
|
#include "Qt/main.h"
|
||||||
|
|
||||||
|
class HotKeyConfSetDialog_t : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
HotKeyConfSetDialog_t( int hkIndex, int discardNum, QTreeWidgetItem *itemIn = 0, QWidget *parent = 0);
|
||||||
|
~HotKeyConfSetDialog_t(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *event);
|
||||||
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
void keyReleaseEvent(QKeyEvent *event);
|
||||||
|
void assignHotkey(QKeyEvent *event);
|
||||||
|
|
||||||
|
QLineEdit *keySeqText;
|
||||||
|
QTreeWidgetItem *item;
|
||||||
|
|
||||||
|
int idx;
|
||||||
|
int discardCount;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void closeWindow(void);
|
||||||
|
void cleanButtonCB(void);
|
||||||
|
void okButtonCB(void);
|
||||||
|
};
|
||||||
|
|
||||||
class HotKeyConfTree_t : public QTreeWidget
|
class HotKeyConfTree_t : public QTreeWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -39,7 +66,6 @@ public:
|
||||||
HotKeyConfDialog_t(QWidget *parent = 0);
|
HotKeyConfDialog_t(QWidget *parent = 0);
|
||||||
~HotKeyConfDialog_t(void);
|
~HotKeyConfDialog_t(void);
|
||||||
|
|
||||||
void assignHotkey(QKeyEvent *event);
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
@ -51,4 +77,6 @@ private:
|
||||||
public slots:
|
public slots:
|
||||||
void closeWindow(void);
|
void closeWindow(void);
|
||||||
private slots:
|
private slots:
|
||||||
|
void hotKeyActivated(QTreeWidgetItem *item, int column);
|
||||||
|
void hotKeyDoubleClicked(QTreeWidgetItem *item, int column);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue