-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setkeydialog.cpp
61 lines (53 loc) · 1.77 KB
/
setkeydialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "setkeydialog.hpp"
#include <QtDebug>
#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>
#include <QSizePolicy>
#include <QKeyEvent>
#include <QMetaEnum>
SetKeyDialog::SetKeyDialog(QWidget* parent) : QDialog(parent)
{
this->setModal(true);
this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
this->setWindowTitle("Set key");
QVBoxLayout* mHLayout = new QVBoxLayout(this);
QLabel* mLabel = new QLabel(this);
QSizePolicy mPolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
mLabel->setSizePolicy(mPolicy);
mLabel->show();
mLabel->setText("Press key to set or cancel by [X]");
mHLayout->addWidget(mLabel);
this->setLayout(mHLayout);
}
quint32 SetKeyDialog::keyToNative(const Qt::Key& iKey)
{
return _qtKeysToNativeMap.value(QString::number(iKey)).toUInt();
}
QMap<QString, QVariant>& SetKeyDialog::accessMap()
{
return _qtKeysToNativeMap;
}
void SetKeyDialog::onSetClicked()
{
_btnObjName = sender()->objectName();
this->show();
}
void SetKeyDialog::keyReleaseEvent(QKeyEvent* iKeyEvent)
{
const QString mKey(QMetaEnum::fromType<Qt::Key>().valueToKey(iKeyEvent->key()));
QStringList mStringList;
mStringList << _btnObjName << mKey;
qDebug() << mStringList;
qDebug() << iKeyEvent->key();
#if defined(Q_OS_LINUX)
qDebug() << "nativeScanCode: " << iKeyEvent->nativeScanCode();
const quint32 mNativeKey = iKeyEvent->nativeScanCode();
#else // Q_OS_LINUX and Q_OS_MAC
qDebug() << "nativeVirtual: " << iKeyEvent->nativeVirtualKey();
const quint32 mNativeKey = iKeyEvent->nativeVirtualKey();
#endif
_qtKeysToNativeMap.insert(QString::number(Qt::Key(iKeyEvent->key())), mNativeKey);
emit setKey(mStringList);
this->hide();
}