mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
Remove native scan code from CKeyboardKey
Remove isPressed status from CKeyboardKey Switched key value to Qt::Key There is no way on OSX to get the native scan code of a key. Therefore it is removed from this class, because we might create dependent code which will not run on OSX. CKeyboardKey is a abstraction of platform keys. It was representing also the status when CKeyboardKey was sent in signals. So this can be removed. Pressed status is sent as argument to the registered method. refs #83
This commit is contained in:
@@ -12,16 +12,16 @@ namespace BlackMisc
|
||||
namespace Hardware
|
||||
{
|
||||
CKeyboardKey::CKeyboardKey() :
|
||||
m_qtKey(0), m_nativeScanCode(0), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(HotkeyNone), m_pressed(false)
|
||||
m_qtKey(Qt::Key_unknown), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(HotkeyNone)
|
||||
{}
|
||||
|
||||
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)
|
||||
m_qtKey(Qt::Key_unknown), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(function)
|
||||
{}
|
||||
|
||||
|
||||
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)
|
||||
CKeyboardKey::CKeyboardKey(Qt::Key keyCode, quint32 nativeVirtualKey, Modifier modifier1, Modifier modifier2, const HotkeyFunction &function) :
|
||||
m_qtKey(keyCode), m_nativeVirtualKey(nativeVirtualKey), m_modifier1(modifier1), m_modifier2(modifier2), m_function(function)
|
||||
{}
|
||||
|
||||
void CKeyboardKey::registerMetadata()
|
||||
@@ -34,7 +34,7 @@ namespace BlackMisc
|
||||
{
|
||||
QString s = this->getModifier1AsString();
|
||||
s.append(" ").append(this->getModifier2AsString()).append(" ");
|
||||
if (this->m_qtKey != 0) this->getKeyAsStringRepresentation();
|
||||
if (this->m_qtKey != 0) s.append(" ").append(this->getKeyAsStringRepresentation());
|
||||
return s.trimmed();
|
||||
}
|
||||
|
||||
@@ -207,25 +207,22 @@ namespace BlackMisc
|
||||
void CKeyboardKey::setKey(const QString &key)
|
||||
{
|
||||
if (key.isEmpty())
|
||||
this->m_qtKey = 0;
|
||||
else if (key.contains(QRegExp("\\((\\d+)\\)")))
|
||||
{
|
||||
QString code = key.mid(key.indexOf("(") + 1).replace(")", "");
|
||||
if (code.isEmpty())
|
||||
this->m_qtKey = 0;
|
||||
else
|
||||
this->m_qtKey = code.toInt();
|
||||
}
|
||||
else
|
||||
this->setKey(key.at(0));
|
||||
this->m_qtKey = Qt::Key_unknown;
|
||||
|
||||
QKeySequence sequence(key);
|
||||
m_qtKey = static_cast<Qt::Key>(sequence[0]);
|
||||
}
|
||||
|
||||
void CKeyboardKey::setKey(const QChar key)
|
||||
void CKeyboardKey::setKey(const QChar &key)
|
||||
{
|
||||
if (key.isNull())
|
||||
this->m_qtKey = 0;
|
||||
this->m_qtKey = Qt::Key_unknown;
|
||||
else
|
||||
this->m_qtKey = key.digitValue();
|
||||
{
|
||||
QKeySequence sequence(key);
|
||||
m_qtKey = static_cast<Qt::Key>(sequence[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString CKeyboardKey::getFunctionAsString() const
|
||||
@@ -256,10 +253,8 @@ namespace BlackMisc
|
||||
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
|
||||
@@ -284,8 +279,6 @@ namespace BlackMisc
|
||||
return QVariant(QString(QChar(this->m_qtKey)));
|
||||
case IndexKeyAsStringRepresentation:
|
||||
return QVariant(this->getKeyAsStringRepresentation());
|
||||
case IndexIsPressed:
|
||||
return QVariant(this->m_pressed);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -324,9 +317,6 @@ namespace BlackMisc
|
||||
this->setKey(variant.value<QString>());
|
||||
break;
|
||||
}
|
||||
case IndexIsPressed:
|
||||
this->setPressed(variant.value<bool>());
|
||||
break;
|
||||
case IndexModifier1AsString:
|
||||
this->setModifier1(variant.value<QString>());
|
||||
break;
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace BlackMisc
|
||||
IndexModifier2AsString,
|
||||
IndexFunction,
|
||||
IndexFunctionAsString,
|
||||
IndexIsPressed,
|
||||
IndexKeyObject, // just for updates
|
||||
};
|
||||
|
||||
@@ -76,7 +75,7 @@ namespace BlackMisc
|
||||
CKeyboardKey(HotkeyFunction function);
|
||||
|
||||
//! \brief Constructor
|
||||
CKeyboardKey(int keyCode, quint32 nativeScanCode, quint32 nativeVirtualKey, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone, const HotkeyFunction &function = HotkeyNone, bool isPressed = false);
|
||||
CKeyboardKey(Qt::Key keyCode, quint32 nativeVirtualKey, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone, const HotkeyFunction &function = HotkeyNone);
|
||||
|
||||
//! \brief Destructor
|
||||
~CKeyboardKey() {}
|
||||
@@ -102,14 +101,8 @@ namespace BlackMisc
|
||||
//! \brief <
|
||||
bool operator<(CKeyboardKey const &other) const;
|
||||
|
||||
//! \brief key pressed?
|
||||
bool isPressed() const { return this->m_pressed; }
|
||||
|
||||
//! \brief Set key pressed
|
||||
void setPressed(bool isPressed) { this->m_pressed = isPressed; }
|
||||
|
||||
//! \brief Get key code
|
||||
QChar getKey() const { return QChar(this->m_qtKey); }
|
||||
Qt::Key getKey() const { return this->m_qtKey; }
|
||||
|
||||
//! \brief Get key code
|
||||
QString getKeyAsString() const { return QString(this->getKey()); }
|
||||
@@ -124,23 +117,17 @@ namespace BlackMisc
|
||||
void setKey(const QString &key);
|
||||
|
||||
//! \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); }
|
||||
void setKey(const Qt::Key key) { this->m_qtKey = 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; }
|
||||
void setKey(int key) { this->m_qtKey = static_cast<Qt::Key>(key); }
|
||||
|
||||
//! \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; }
|
||||
|
||||
@@ -177,7 +164,7 @@ namespace BlackMisc
|
||||
//! \brief with key?
|
||||
bool hasKey() const
|
||||
{
|
||||
return !this->m_qtKey == 0;
|
||||
return !(this->m_qtKey == Qt::Key_unknown);
|
||||
}
|
||||
|
||||
//! \brief Key + modifier?
|
||||
@@ -244,19 +231,17 @@ namespace BlackMisc
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey)
|
||||
int m_qtKey; //!< code similar to Qt::Key
|
||||
quint32 m_nativeScanCode; //!< native scan code, QKeyEvent::nativeScanCode
|
||||
Qt::Key m_qtKey; //!< code similar to Qt::Key
|
||||
quint32 m_nativeVirtualKey; //!< virtual key code
|
||||
Modifier m_modifier1;
|
||||
Modifier m_modifier2;
|
||||
HotkeyFunction m_function;
|
||||
bool m_pressed;
|
||||
|
||||
};
|
||||
} // class
|
||||
} // BlackMisc
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CKeyboardKey, (o.m_qtKey, o.m_nativeScanCode, o.m_nativeVirtualKey, o.m_modifier1, o.m_modifier2, o.m_function, o.m_pressed))
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CKeyboardKey, (o.m_qtKey, o.m_nativeVirtualKey, o.m_modifier1, o.m_modifier2, o.m_function, o.m_pressed))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Hardware::CKeyboardKey)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user