mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +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:
@@ -135,8 +135,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
const Qt::Key k = static_cast<Qt::Key>(event->key());
|
const Qt::Key k = static_cast<Qt::Key>(event->key());
|
||||||
if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return;
|
if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return;
|
||||||
this->m_key.setKey(event->key());
|
this->m_key.setKey(k);
|
||||||
this->m_key.setNativeScanCode(event->nativeScanCode());
|
|
||||||
this->m_key.setNativeVirtualKey(event->nativeVirtualKey());
|
this->m_key.setNativeVirtualKey(event->nativeVirtualKey());
|
||||||
this->setText(CKeyboardKey::toStringRepresentation(event->key()));
|
this->setText(CKeyboardKey::toStringRepresentation(event->key()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ namespace BlackMisc
|
|||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
CKeyboardKey::CKeyboardKey() :
|
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) :
|
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) :
|
CKeyboardKey::CKeyboardKey(Qt::Key keyCode, quint32 nativeVirtualKey, Modifier modifier1, Modifier modifier2, const HotkeyFunction &function) :
|
||||||
m_qtKey(keyCode), m_nativeScanCode(nativeScanCode), m_nativeVirtualKey(nativeVirtualKey), m_modifier1(modifier1), m_modifier2(modifier2), m_function(function), m_pressed(isPressed)
|
m_qtKey(keyCode), m_nativeVirtualKey(nativeVirtualKey), m_modifier1(modifier1), m_modifier2(modifier2), m_function(function)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void CKeyboardKey::registerMetadata()
|
void CKeyboardKey::registerMetadata()
|
||||||
@@ -34,7 +34,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_qtKey != 0) this->getKeyAsStringRepresentation();
|
if (this->m_qtKey != 0) s.append(" ").append(this->getKeyAsStringRepresentation());
|
||||||
return s.trimmed();
|
return s.trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,25 +207,22 @@ namespace BlackMisc
|
|||||||
void CKeyboardKey::setKey(const QString &key)
|
void CKeyboardKey::setKey(const QString &key)
|
||||||
{
|
{
|
||||||
if (key.isEmpty())
|
if (key.isEmpty())
|
||||||
this->m_qtKey = 0;
|
this->m_qtKey = Qt::Key_unknown;
|
||||||
else if (key.contains(QRegExp("\\((\\d+)\\)")))
|
|
||||||
{
|
QKeySequence sequence(key);
|
||||||
QString code = key.mid(key.indexOf("(") + 1).replace(")", "");
|
m_qtKey = static_cast<Qt::Key>(sequence[0]);
|
||||||
if (code.isEmpty())
|
|
||||||
this->m_qtKey = 0;
|
|
||||||
else
|
|
||||||
this->m_qtKey = code.toInt();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this->setKey(key.at(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeyboardKey::setKey(const QChar key)
|
void CKeyboardKey::setKey(const QChar &key)
|
||||||
{
|
{
|
||||||
if (key.isNull())
|
if (key.isNull())
|
||||||
this->m_qtKey = 0;
|
this->m_qtKey = Qt::Key_unknown;
|
||||||
else
|
else
|
||||||
this->m_qtKey = key.digitValue();
|
{
|
||||||
|
QKeySequence sequence(key);
|
||||||
|
m_qtKey = static_cast<Qt::Key>(sequence[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CKeyboardKey::getFunctionAsString() const
|
QString CKeyboardKey::getFunctionAsString() const
|
||||||
@@ -256,10 +253,8 @@ namespace BlackMisc
|
|||||||
this->m_function = key.m_function;
|
this->m_function = key.m_function;
|
||||||
this->m_modifier1 = key.m_modifier1;
|
this->m_modifier1 = key.m_modifier1;
|
||||||
this->m_modifier2 = key.m_modifier2;
|
this->m_modifier2 = key.m_modifier2;
|
||||||
this->m_nativeScanCode = key.m_nativeScanCode;
|
|
||||||
this->m_nativeVirtualKey = key.m_nativeVirtualKey;
|
this->m_nativeVirtualKey = key.m_nativeVirtualKey;
|
||||||
this->m_qtKey = key.m_qtKey;
|
this->m_qtKey = key.m_qtKey;
|
||||||
this->m_pressed = key.m_pressed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CKeyboardKey::propertyByIndex(int index) const
|
QVariant CKeyboardKey::propertyByIndex(int index) const
|
||||||
@@ -284,8 +279,6 @@ namespace BlackMisc
|
|||||||
return QVariant(QString(QChar(this->m_qtKey)));
|
return QVariant(QString(QChar(this->m_qtKey)));
|
||||||
case IndexKeyAsStringRepresentation:
|
case IndexKeyAsStringRepresentation:
|
||||||
return QVariant(this->getKeyAsStringRepresentation());
|
return QVariant(this->getKeyAsStringRepresentation());
|
||||||
case IndexIsPressed:
|
|
||||||
return QVariant(this->m_pressed);
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -324,9 +317,6 @@ namespace BlackMisc
|
|||||||
this->setKey(variant.value<QString>());
|
this->setKey(variant.value<QString>());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IndexIsPressed:
|
|
||||||
this->setPressed(variant.value<bool>());
|
|
||||||
break;
|
|
||||||
case IndexModifier1AsString:
|
case IndexModifier1AsString:
|
||||||
this->setModifier1(variant.value<QString>());
|
this->setModifier1(variant.value<QString>());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ namespace BlackMisc
|
|||||||
IndexModifier2AsString,
|
IndexModifier2AsString,
|
||||||
IndexFunction,
|
IndexFunction,
|
||||||
IndexFunctionAsString,
|
IndexFunctionAsString,
|
||||||
IndexIsPressed,
|
|
||||||
IndexKeyObject, // just for updates
|
IndexKeyObject, // just for updates
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,7 +75,7 @@ namespace BlackMisc
|
|||||||
CKeyboardKey(HotkeyFunction function);
|
CKeyboardKey(HotkeyFunction function);
|
||||||
|
|
||||||
//! \brief Constructor
|
//! \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
|
//! \brief Destructor
|
||||||
~CKeyboardKey() {}
|
~CKeyboardKey() {}
|
||||||
@@ -102,14 +101,8 @@ namespace BlackMisc
|
|||||||
//! \brief <
|
//! \brief <
|
||||||
bool operator<(CKeyboardKey const &other) const;
|
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
|
//! \brief Get key code
|
||||||
QChar getKey() const { return QChar(this->m_qtKey); }
|
Qt::Key getKey() const { return 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()); }
|
||||||
@@ -124,23 +117,17 @@ namespace BlackMisc
|
|||||||
void setKey(const QString &key);
|
void setKey(const QString &key);
|
||||||
|
|
||||||
//! \brief Set key code
|
//! \brief Set key code
|
||||||
void setKey(const QChar key);
|
void setKey(const QChar &key);
|
||||||
|
|
||||||
//! \brief Set key code
|
//! \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
|
//! \brief Set key code
|
||||||
void setKey(int key) { this->m_qtKey = key; }
|
void setKey(int key) { this->m_qtKey = static_cast<Qt::Key>(key); }
|
||||||
|
|
||||||
//! \brief Native scan code
|
|
||||||
void setNativeScanCode(quint32 scanCode) { this->m_nativeScanCode = scanCode; }
|
|
||||||
|
|
||||||
//! \brief Native virtual key
|
//! \brief Native virtual key
|
||||||
void setNativeVirtualKey(quint32 virtualKey) { this->m_nativeVirtualKey = virtualKey; }
|
void setNativeVirtualKey(quint32 virtualKey) { this->m_nativeVirtualKey = virtualKey; }
|
||||||
|
|
||||||
//! \brief Native scan code
|
|
||||||
quint32 getNativeScanCode() const { return this->m_nativeScanCode; }
|
|
||||||
|
|
||||||
//! \brief Native virtual key
|
//! \brief Native virtual key
|
||||||
quint32 getNativeVirtualKey() const { return this->m_nativeVirtualKey; }
|
quint32 getNativeVirtualKey() const { return this->m_nativeVirtualKey; }
|
||||||
|
|
||||||
@@ -177,7 +164,7 @@ namespace BlackMisc
|
|||||||
//! \brief with key?
|
//! \brief with key?
|
||||||
bool hasKey() const
|
bool hasKey() const
|
||||||
{
|
{
|
||||||
return !this->m_qtKey == 0;
|
return !(this->m_qtKey == Qt::Key_unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Key + modifier?
|
//! \brief Key + modifier?
|
||||||
@@ -244,19 +231,17 @@ namespace BlackMisc
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey)
|
BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey)
|
||||||
int m_qtKey; //!< code similar to Qt::Key
|
Qt::Key m_qtKey; //!< code similar to Qt::Key
|
||||||
quint32 m_nativeScanCode; //!< native scan code, QKeyEvent::nativeScanCode
|
|
||||||
quint32 m_nativeVirtualKey; //!< virtual key code
|
quint32 m_nativeVirtualKey; //!< virtual key code
|
||||||
Modifier m_modifier1;
|
Modifier m_modifier1;
|
||||||
Modifier m_modifier2;
|
Modifier m_modifier2;
|
||||||
HotkeyFunction m_function;
|
HotkeyFunction m_function;
|
||||||
bool m_pressed;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // class
|
} // class
|
||||||
} // BlackMisc
|
} // 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)
|
Q_DECLARE_METATYPE(BlackMisc::Hardware::CKeyboardKey)
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user