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