mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
refs #139 , allows to store the native scan code and the virtual key code. Adjusted list to use changed constructor.
This commit is contained in:
@@ -12,17 +12,22 @@ namespace BlackMisc
|
||||
namespace Hardware
|
||||
{
|
||||
CKeyboardKey::CKeyboardKey() :
|
||||
m_key(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(HotkeyNone), m_pressed(false)
|
||||
m_qtKey(0), m_nativeScanCode(0), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(HotkeyNone), m_pressed(false)
|
||||
{}
|
||||
|
||||
CKeyboardKey::CKeyboardKey(int keyCode, Modifier modifier1, Modifier modifier2, const HotkeyFunction &function, bool isPressed) :
|
||||
m_key(keyCode), m_modifier1(modifier1), m_modifier2(modifier2), m_function(function), m_pressed(isPressed)
|
||||
CKeyboardKey::CKeyboardKey(HotkeyFunction function) :
|
||||
m_qtKey(0), m_nativeScanCode(0), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(function), m_pressed(false)
|
||||
{}
|
||||
|
||||
|
||||
CKeyboardKey::CKeyboardKey(int keyCode, quint32 nativeScanCode, quint32 nativeVirtualKey, Modifier modifier1, Modifier modifier2, const HotkeyFunction &function, bool isPressed) :
|
||||
m_qtKey(keyCode), m_nativeScanCode(nativeScanCode), m_nativeVirtualKey(nativeVirtualKey), m_modifier1(modifier1), m_modifier2(modifier2), m_function(function), m_pressed(isPressed)
|
||||
{}
|
||||
|
||||
uint CKeyboardKey::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << qHash(this->m_key);
|
||||
hashs << qHash(this->m_qtKey);
|
||||
hashs << qHash(this->m_function);
|
||||
hashs << qHash(static_cast<uint>(this->m_modifier1));
|
||||
hashs << qHash(static_cast<uint>(this->m_modifier2));
|
||||
@@ -39,7 +44,7 @@ namespace BlackMisc
|
||||
{
|
||||
QString s = this->getModifier1AsString();
|
||||
s.append(" ").append(this->getModifier2AsString()).append(" ");
|
||||
if (this->m_key != 0) this->getKeyAsStringRepresentation();
|
||||
if (this->m_qtKey != 0) this->getKeyAsStringRepresentation();
|
||||
return s.trimmed();
|
||||
}
|
||||
|
||||
@@ -56,14 +61,16 @@ namespace BlackMisc
|
||||
int CKeyboardKey::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CKeyboardKey &>(otherBase);
|
||||
QString k1(this->m_key);
|
||||
QString k1(this->m_qtKey);
|
||||
QString k2(other.getKey());
|
||||
return k1.compare(k2);
|
||||
}
|
||||
|
||||
void CKeyboardKey::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << this->m_key;
|
||||
argument << this->m_qtKey;
|
||||
argument << this->m_nativeScanCode;
|
||||
argument << this->m_nativeVirtualKey;
|
||||
argument << static_cast<uint>(this->m_modifier1);
|
||||
argument << static_cast<uint>(this->m_modifier2);
|
||||
argument << static_cast<uint>(this->m_function);
|
||||
@@ -72,8 +79,10 @@ namespace BlackMisc
|
||||
|
||||
void CKeyboardKey::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> this->m_qtKey;
|
||||
argument >> this->m_nativeScanCode;
|
||||
argument >> this->m_nativeVirtualKey;
|
||||
uint c;
|
||||
argument >> this->m_key;
|
||||
argument >> c;
|
||||
this->m_modifier1 = static_cast<Modifier>(c);
|
||||
argument >> c;
|
||||
@@ -201,14 +210,14 @@ namespace BlackMisc
|
||||
void CKeyboardKey::setKey(const QString &key)
|
||||
{
|
||||
if (key.isEmpty())
|
||||
this->m_key = 0;
|
||||
this->m_qtKey = 0;
|
||||
else if (key.contains(QRegExp("\\((\\d+)\\)")))
|
||||
{
|
||||
QString code = key.mid(key.indexOf("(") + 1).replace(")", "");
|
||||
if (code.isEmpty())
|
||||
this->m_key = 0;
|
||||
this->m_qtKey = 0;
|
||||
else
|
||||
this->m_key = code.toInt();
|
||||
this->m_qtKey = code.toInt();
|
||||
}
|
||||
else
|
||||
this->setKey(key.at(0));
|
||||
@@ -217,9 +226,9 @@ namespace BlackMisc
|
||||
void CKeyboardKey::setKey(const QChar key)
|
||||
{
|
||||
if (key.isNull())
|
||||
this->m_key = 0;
|
||||
this->m_qtKey = 0;
|
||||
else
|
||||
this->m_key = key.digitValue();
|
||||
this->m_qtKey = key.digitValue();
|
||||
}
|
||||
|
||||
QString CKeyboardKey::getFunctionAsString() const
|
||||
@@ -245,6 +254,17 @@ namespace BlackMisc
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "Toggle COM2");
|
||||
}
|
||||
|
||||
void CKeyboardKey::setKeyObject(const CKeyboardKey &key)
|
||||
{
|
||||
this->m_function = key.m_function;
|
||||
this->m_modifier1 = key.m_modifier1;
|
||||
this->m_modifier2 = key.m_modifier2;
|
||||
this->m_nativeScanCode = key.m_nativeScanCode;
|
||||
this->m_nativeVirtualKey = key.m_nativeVirtualKey;
|
||||
this->m_qtKey = key.m_qtKey;
|
||||
this->m_pressed = key.m_pressed;
|
||||
}
|
||||
|
||||
QVariant CKeyboardKey::propertyByIndex(int index) const
|
||||
{
|
||||
switch (index)
|
||||
@@ -262,9 +282,9 @@ namespace BlackMisc
|
||||
case IndexModifier2AsString:
|
||||
return QVariant(this->getModifier2AsString());
|
||||
case IndexKey:
|
||||
return QVariant(this->m_key);
|
||||
return QVariant(this->m_qtKey);
|
||||
case IndexKeyAsString:
|
||||
return QVariant(QString(QChar(this->m_key)));
|
||||
return QVariant(QString(QChar(this->m_qtKey)));
|
||||
case IndexKeyAsStringRepresentation:
|
||||
return QVariant(this->getKeyAsStringRepresentation());
|
||||
case IndexIsPressed:
|
||||
@@ -282,7 +302,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (key == 0) return "";
|
||||
QString ks = QKeySequence(key).toString();
|
||||
ks.append('(').append(QString::number(key)).append(')');
|
||||
// ks.append('(').append(QString::number(key)).append(')');
|
||||
return ks;
|
||||
}
|
||||
|
||||
@@ -316,6 +336,9 @@ namespace BlackMisc
|
||||
case IndexModifier2AsString:
|
||||
this->setModifier2(variant.value<QString>());
|
||||
break;
|
||||
case IndexKeyObject:
|
||||
this->setKeyObject(variant.value<BlackMisc::Hardware::CKeyboardKey>());
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT_X(false, "CKeyboardKey", "index unknown (setter)");
|
||||
break;
|
||||
|
||||
@@ -37,7 +37,8 @@ namespace BlackMisc
|
||||
IndexModifier2AsString,
|
||||
IndexFunction,
|
||||
IndexFunctionAsString,
|
||||
IndexIsPressed
|
||||
IndexIsPressed,
|
||||
IndexKeyObject, // just for updates
|
||||
};
|
||||
|
||||
//! \brief Function
|
||||
@@ -71,8 +72,11 @@ namespace BlackMisc
|
||||
//! \brief Default constructor
|
||||
CKeyboardKey();
|
||||
|
||||
//! \brief Constructor by function
|
||||
CKeyboardKey(HotkeyFunction function);
|
||||
|
||||
//! \brief Constructor
|
||||
CKeyboardKey(int keyCode, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone, const HotkeyFunction &function = HotkeyNone, bool isPressed = false);
|
||||
CKeyboardKey(int keyCode, quint32 nativeScanCode, quint32 nativeVirtualKey, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone, const HotkeyFunction &function = HotkeyNone, bool isPressed = false);
|
||||
|
||||
//! \brief Destructor
|
||||
~CKeyboardKey() {}
|
||||
@@ -102,16 +106,16 @@ namespace BlackMisc
|
||||
void setPressed(bool isPressed) { this->m_pressed = isPressed; }
|
||||
|
||||
//! \brief Get key code
|
||||
QChar getKey() const { return QChar(this->m_key); }
|
||||
QChar getKey() const { return QChar(this->m_qtKey); }
|
||||
|
||||
//! \brief Get key code
|
||||
QString getKeyAsString() const { return QString(this->getKey()); }
|
||||
|
||||
//! \brief Get key code
|
||||
QString getKeyAsStringRepresentation() const { return CKeyboardKey::toStringRepresentation(this->m_key); }
|
||||
QString getKeyAsStringRepresentation() const { return CKeyboardKey::toStringRepresentation(this->m_qtKey); }
|
||||
|
||||
//! \brief As Qt::Key
|
||||
Qt::Key getKeyAsQtKey() const { return static_cast<Qt::Key>(this->m_key);}
|
||||
Qt::Key getKeyAsQtKey() const { return static_cast<Qt::Key>(this->m_qtKey);}
|
||||
|
||||
//! \brief Set key code
|
||||
void setKey(const QString &key);
|
||||
@@ -119,6 +123,24 @@ namespace BlackMisc
|
||||
//! \brief Set key code
|
||||
void setKey(const QChar key);
|
||||
|
||||
//! \brief Set key code
|
||||
void setKey(const Qt::Key key) { this->m_qtKey = static_cast<int>(key); }
|
||||
|
||||
//! \brief Set key code
|
||||
void setKey(int key) { this->m_qtKey = key; }
|
||||
|
||||
//! \brief Native scan code
|
||||
void setNativeScanCode(quint32 scanCode) { this->m_nativeScanCode = scanCode; }
|
||||
|
||||
//! \brief Native virtual key
|
||||
void setNativeVirtualKey(quint32 virtualKey) { this->m_nativeVirtualKey = virtualKey; }
|
||||
|
||||
//! \brief Native scan code
|
||||
quint32 getNativeScanCode() const { return this->m_nativeScanCode; }
|
||||
|
||||
//! \brief Native virtual key
|
||||
quint32 getNativeVirtualKey() const { return this->m_nativeVirtualKey; }
|
||||
|
||||
//! \brief number of modifiers
|
||||
int numberOfModifiers() const;
|
||||
|
||||
@@ -152,7 +174,7 @@ namespace BlackMisc
|
||||
//! \brief with key?
|
||||
bool hasKey() const
|
||||
{
|
||||
return !this->m_key == 0;
|
||||
return !this->m_qtKey == 0;
|
||||
}
|
||||
|
||||
//! \brief Key + modifier?
|
||||
@@ -167,6 +189,9 @@ namespace BlackMisc
|
||||
//! \brief Function (optional)
|
||||
QString getFunctionAsString() const;
|
||||
|
||||
//! \brief Set key object
|
||||
void setKeyObject(const BlackMisc::Hardware::CKeyboardKey &key);
|
||||
|
||||
//! \brief Set function
|
||||
void setFunction(const HotkeyFunction &function) { this->m_function = function; }
|
||||
|
||||
@@ -215,7 +240,9 @@ namespace BlackMisc
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
private:
|
||||
int m_key;
|
||||
int m_qtKey; //!< code similar to Qt::Key
|
||||
quint32 m_nativeScanCode; //!< native scan code, QKeyEvent::nativeScanCode
|
||||
quint32 m_nativeVirtualKey; //!< virtual key code
|
||||
Modifier m_modifier1;
|
||||
Modifier m_modifier2;
|
||||
HotkeyFunction m_function;
|
||||
|
||||
@@ -38,11 +38,11 @@ namespace BlackMisc
|
||||
void CKeyboardKeyList::initAsHotkeyList()
|
||||
{
|
||||
this->clear();
|
||||
this->push_back(CKeyboardKey(QChar::Null, CKeyboardKey::ModifierNone, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyPtt));
|
||||
this->push_back(CKeyboardKey(QChar::Null, CKeyboardKey::ModifierNone, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyOpacity50));
|
||||
this->push_back(CKeyboardKey(QChar::Null, CKeyboardKey::ModifierNone, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyOpacity100));
|
||||
this->push_back(CKeyboardKey(QChar::Null, CKeyboardKey::ModifierNone, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyToggleCom1));
|
||||
this->push_back(CKeyboardKey(QChar::Null, CKeyboardKey::ModifierNone, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyToggleCom2));
|
||||
this->push_back(CKeyboardKey(CKeyboardKey::HotkeyPtt));
|
||||
this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity50));
|
||||
this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity100));
|
||||
this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom1));
|
||||
this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom2));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user