mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #313 Remove any occurence of function or virtual keycode from CKeyboardKey(list)
Justification for native virtual key is, because its not cross platform.
This commit is contained in:
@@ -235,7 +235,6 @@ namespace BlackInput
|
||||
else
|
||||
{
|
||||
m_pressedKey.setKey(CKeyMappingLinux::convertToKey(virtualKeyCode));
|
||||
m_pressedKey.setNativeVirtualKey(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -245,7 +244,6 @@ namespace BlackInput
|
||||
else
|
||||
{
|
||||
m_pressedKey.setKey(Qt::Key_unknown);
|
||||
m_pressedKey.setNativeVirtualKey(0);
|
||||
}
|
||||
|
||||
isFinished = true;
|
||||
|
||||
@@ -69,7 +69,6 @@ namespace BlackInput
|
||||
else
|
||||
{
|
||||
m_pressedKey.setKey(CKeyMappingWindows::convertToKey(vkcode));
|
||||
m_pressedKey.setNativeVirtualKey(vkcode);
|
||||
}
|
||||
}
|
||||
else if ((event == WM_KEYUP) || (event == WM_SYSKEYUP) )
|
||||
@@ -79,7 +78,6 @@ namespace BlackInput
|
||||
else
|
||||
{
|
||||
m_pressedKey.setKey(Qt::Key_unknown);
|
||||
m_pressedKey.setNativeVirtualKey(0);
|
||||
}
|
||||
|
||||
isFinished = true;
|
||||
|
||||
@@ -12,16 +12,11 @@ namespace BlackMisc
|
||||
namespace Hardware
|
||||
{
|
||||
CKeyboardKey::CKeyboardKey() :
|
||||
m_qtKey(Qt::Key_unknown), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(HotkeyNone)
|
||||
m_qtKey(Qt::Key_unknown), m_modifier1(ModifierNone), m_modifier2(ModifierNone)
|
||||
{}
|
||||
|
||||
CKeyboardKey::CKeyboardKey(HotkeyFunction function) :
|
||||
m_qtKey(Qt::Key_unknown), m_nativeVirtualKey(0), m_modifier1(ModifierNone), m_modifier2(ModifierNone), m_function(function)
|
||||
{}
|
||||
|
||||
|
||||
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)
|
||||
CKeyboardKey::CKeyboardKey(Qt::Key keyCode, Modifier modifier1, Modifier modifier2) :
|
||||
m_qtKey(keyCode), m_modifier1(modifier1), m_modifier2(modifier2)
|
||||
{}
|
||||
|
||||
void CKeyboardKey::registerMetadata()
|
||||
@@ -314,47 +309,19 @@ namespace BlackMisc
|
||||
return false;
|
||||
}
|
||||
|
||||
QString CKeyboardKey::getFunctionAsString() const
|
||||
{
|
||||
switch (this->m_function)
|
||||
{
|
||||
case HotkeyNone: return "";
|
||||
case HotkeyPtt: return QCoreApplication::translate("Hotkey", "PTT");
|
||||
case HotkeyOpacity50: return QCoreApplication::translate("Hotkey", "Opacity 50%");
|
||||
case HotkeyOpacity100: return QCoreApplication::translate("Hotkey", "Opacity 100%");
|
||||
case HotkeyToggleCom1: return QCoreApplication::translate("Hotkey", "Toggle COM1");
|
||||
case HotkeyToggleCom2: return QCoreApplication::translate("Hotkey", "Toggle COM2");
|
||||
case HotkeyToogleWindowsStayOnTop: return QCoreApplication::translate("Hotkey", "Toogle Window on top");
|
||||
default:
|
||||
qFatal("Wrong function");
|
||||
return "";
|
||||
}
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "PTT");
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "Opacity 50%");
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "Opacity 100%");
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "Toggle COM1");
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "Toggle COM2");
|
||||
(void)QT_TRANSLATE_NOOP("Hotkey", "Toogle Window on top");
|
||||
}
|
||||
|
||||
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_nativeVirtualKey = key.m_nativeVirtualKey;
|
||||
this->m_qtKey = key.m_qtKey;
|
||||
}
|
||||
|
||||
bool CKeyboardKey::equalsWithRelaxedModifiers(const CKeyboardKey &key, bool ignoreFunction) const
|
||||
bool CKeyboardKey::equalsWithRelaxedModifiers(const CKeyboardKey &key) const
|
||||
{
|
||||
if (key == (*this)) return true; // fully equal, not need to bother
|
||||
|
||||
// this can never be true
|
||||
if (key.m_qtKey != this->m_qtKey) return false;
|
||||
if (!ignoreFunction && key.m_function != this->m_function) return false;
|
||||
if (this->numberOfModifiers() != key.numberOfModifiers()) return false;
|
||||
|
||||
// special modifiers
|
||||
@@ -365,24 +332,10 @@ namespace BlackMisc
|
||||
return CKeyboardKey::equalsModifierReleaxed(this->getModifier1(), key.getModifier1());
|
||||
}
|
||||
|
||||
bool CKeyboardKey::equalsWithoutFunction(const CKeyboardKey &key) const
|
||||
{
|
||||
if (key == (*this)) return true;
|
||||
CKeyboardKey k1(*this);
|
||||
CKeyboardKey k2(*this);
|
||||
k1.setFunction(HotkeyNone);
|
||||
k2.setFunction(HotkeyNone);
|
||||
return k1 == k2;
|
||||
}
|
||||
|
||||
QVariant CKeyboardKey::propertyByIndex(int index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case IndexFunction:
|
||||
return QVariant(this->m_function);
|
||||
case IndexFunctionAsString:
|
||||
return QVariant(this->getFunctionAsString());
|
||||
case IndexModifier1:
|
||||
return QVariant(static_cast<uint>(this->m_modifier1));
|
||||
case IndexModifier2:
|
||||
@@ -418,12 +371,6 @@ namespace BlackMisc
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case IndexFunction:
|
||||
{
|
||||
uint f = variant.value<uint>();
|
||||
this->setFunction(static_cast<HotkeyFunction>(f));
|
||||
break;
|
||||
}
|
||||
case IndexKey:
|
||||
case IndexKeyAsString:
|
||||
case IndexKeyAsStringRepresentation:
|
||||
|
||||
@@ -33,23 +33,9 @@ namespace BlackMisc
|
||||
IndexModifier2,
|
||||
IndexModifier1AsString,
|
||||
IndexModifier2AsString,
|
||||
IndexFunction,
|
||||
IndexFunctionAsString,
|
||||
IndexKeyObject, // just for updates
|
||||
};
|
||||
|
||||
//! Function
|
||||
enum HotkeyFunction
|
||||
{
|
||||
HotkeyNone,
|
||||
HotkeyPtt,
|
||||
HotkeyToggleCom1,
|
||||
HotkeyToggleCom2,
|
||||
HotkeyOpacity50,
|
||||
HotkeyOpacity100,
|
||||
HotkeyToogleWindowsStayOnTop
|
||||
};
|
||||
|
||||
//! Modifier
|
||||
enum Modifier
|
||||
{
|
||||
@@ -70,11 +56,8 @@ namespace BlackMisc
|
||||
//! Default constructor
|
||||
CKeyboardKey();
|
||||
|
||||
//! Constructor by function
|
||||
CKeyboardKey(HotkeyFunction function);
|
||||
|
||||
//! Constructor
|
||||
CKeyboardKey(Qt::Key keyCode, quint32 nativeVirtualKey, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone, const HotkeyFunction &function = HotkeyNone);
|
||||
CKeyboardKey(Qt::Key keyCode, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone);
|
||||
|
||||
//! Destructor
|
||||
~CKeyboardKey() {}
|
||||
@@ -133,12 +116,6 @@ namespace BlackMisc
|
||||
//! Set key code
|
||||
void setKey(int key) { this->m_qtKey = static_cast<Qt::Key>(key); }
|
||||
|
||||
//! Native virtual key
|
||||
void setNativeVirtualKey(quint32 virtualKey) { this->m_nativeVirtualKey = virtualKey; }
|
||||
|
||||
//! Native virtual key
|
||||
quint32 getNativeVirtualKey() const { return this->m_nativeVirtualKey; }
|
||||
|
||||
/*!
|
||||
* Add modifier
|
||||
* \param modifier
|
||||
@@ -156,9 +133,6 @@ namespace BlackMisc
|
||||
//! number of modifiers
|
||||
int numberOfModifiers() const;
|
||||
|
||||
//! Function (optional)
|
||||
HotkeyFunction getFunction() const { return this->m_function; }
|
||||
|
||||
//! Modifier 1
|
||||
Modifier getModifier1() const { return this->m_modifier1; }
|
||||
|
||||
@@ -230,20 +204,11 @@ namespace BlackMisc
|
||||
//! Order Modifiers
|
||||
void cleanup();
|
||||
|
||||
//! Function (optional)
|
||||
QString getFunctionAsString() const;
|
||||
|
||||
//! Set key object
|
||||
void setKeyObject(const BlackMisc::Hardware::CKeyboardKey &key);
|
||||
|
||||
//! Set function
|
||||
void setFunction(const HotkeyFunction &function) { this->m_function = function; }
|
||||
|
||||
//! CTRL will be consider equal CTRL-left/reigt, ALT = ALT-left/right ..
|
||||
bool equalsWithRelaxedModifiers(const CKeyboardKey &key, bool ignoreFunction = false) const;
|
||||
|
||||
//! Equal, but function value ignored
|
||||
bool equalsWithoutFunction(const CKeyboardKey &key) const;
|
||||
bool equalsWithRelaxedModifiers(const CKeyboardKey &key) const;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
virtual void setPropertyByIndex(const QVariant &variant, int index);
|
||||
@@ -292,16 +257,13 @@ namespace BlackMisc
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey)
|
||||
Qt::Key m_qtKey; //!< code similar to Qt::Key
|
||||
quint32 m_nativeVirtualKey; //!< virtual key code TODO: Risk in platform independent comparisons
|
||||
Modifier m_modifier1;
|
||||
Modifier m_modifier2;
|
||||
HotkeyFunction m_function;
|
||||
|
||||
};
|
||||
} // class
|
||||
} // BlackMisc
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CKeyboardKey, (o.m_qtKey, o.m_nativeVirtualKey, o.m_modifier1, o.m_modifier2, o.m_function))
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CKeyboardKey, (o.m_qtKey, o.m_modifier1, o.m_modifier2))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Hardware::CKeyboardKey)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -22,22 +22,6 @@ namespace BlackMisc
|
||||
CSequence<CKeyboardKey>(baseClass)
|
||||
{ }
|
||||
|
||||
/*
|
||||
* Contains this hotkey function?
|
||||
*/
|
||||
bool CKeyboardKeyList::containsFunction(CKeyboardKey::HotkeyFunction function) const
|
||||
{
|
||||
return CSequence::contains(&CKeyboardKey::getFunction, function);
|
||||
}
|
||||
|
||||
/*
|
||||
* Key for function
|
||||
*/
|
||||
CKeyboardKey CKeyboardKeyList::keyForFunction(CKeyboardKey::HotkeyFunction function) const
|
||||
{
|
||||
return this->findBy(&CKeyboardKey::getFunction, function).frontOrDefault({ CKeyboardKey::HotkeyNone });
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
@@ -51,19 +35,5 @@ namespace BlackMisc
|
||||
qDBusRegisterMetaType<CKeyboardKeyList>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Hotkey list
|
||||
*/
|
||||
void CKeyboardKeyList::initAsHotkeyList(bool reset)
|
||||
{
|
||||
if (reset) this->clear();
|
||||
if (!this->containsFunction(CKeyboardKey::HotkeyPtt)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyPtt));
|
||||
if (!this->containsFunction(CKeyboardKey::HotkeyOpacity50)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity50));
|
||||
if (!this->containsFunction(CKeyboardKey::HotkeyOpacity100)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity100));
|
||||
if (!this->containsFunction(CKeyboardKey::HotkeyToggleCom1)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom1));
|
||||
if (!this->containsFunction(CKeyboardKey::HotkeyToggleCom2)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom2));
|
||||
if (!this->containsFunction(CKeyboardKey::HotkeyToogleWindowsStayOnTop)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToogleWindowsStayOnTop));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -34,20 +34,8 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
//! Contains given hotkey function?
|
||||
bool containsFunction(CKeyboardKey::HotkeyFunction function) const;
|
||||
|
||||
//! Key for given function
|
||||
CKeyboardKey keyForFunction(CKeyboardKey::HotkeyFunction function) const;
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
/*!
|
||||
* Fill the list with hotkeys
|
||||
* \param reset true, list will be be reset, otherwise values will not be overridde
|
||||
*/
|
||||
void initAsHotkeyList(bool reset = true);
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
Reference in New Issue
Block a user