diff --git a/src/blackinput/linux/keyboard_linux.cpp b/src/blackinput/linux/keyboard_linux.cpp index e7d229fc1..21bd79dcd 100644 --- a/src/blackinput/linux/keyboard_linux.cpp +++ b/src/blackinput/linux/keyboard_linux.cpp @@ -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; diff --git a/src/blackinput/win/keyboard_windows.cpp b/src/blackinput/win/keyboard_windows.cpp index 6324a3151..7c201f680 100644 --- a/src/blackinput/win/keyboard_windows.cpp +++ b/src/blackinput/win/keyboard_windows.cpp @@ -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; diff --git a/src/blackmisc/hwkeyboardkey.cpp b/src/blackmisc/hwkeyboardkey.cpp index d7dda95d1..0301be0c7 100644 --- a/src/blackmisc/hwkeyboardkey.cpp +++ b/src/blackmisc/hwkeyboardkey.cpp @@ -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(this->m_modifier1)); case IndexModifier2: @@ -418,12 +371,6 @@ namespace BlackMisc { switch (index) { - case IndexFunction: - { - uint f = variant.value(); - this->setFunction(static_cast(f)); - break; - } case IndexKey: case IndexKeyAsString: case IndexKeyAsStringRepresentation: diff --git a/src/blackmisc/hwkeyboardkey.h b/src/blackmisc/hwkeyboardkey.h index 55fcfdceb..8c1bd9410 100644 --- a/src/blackmisc/hwkeyboardkey.h +++ b/src/blackmisc/hwkeyboardkey.h @@ -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(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 diff --git a/src/blackmisc/hwkeyboardkeylist.cpp b/src/blackmisc/hwkeyboardkeylist.cpp index fa9d969d7..9e32a5d28 100644 --- a/src/blackmisc/hwkeyboardkeylist.cpp +++ b/src/blackmisc/hwkeyboardkeylist.cpp @@ -22,22 +22,6 @@ namespace BlackMisc CSequence(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(); } - /* - * 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 diff --git a/src/blackmisc/hwkeyboardkeylist.h b/src/blackmisc/hwkeyboardkeylist.h index e47373b93..ce937f682 100644 --- a/src/blackmisc/hwkeyboardkeylist.h +++ b/src/blackmisc/hwkeyboardkeylist.h @@ -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 diff --git a/tests/blackmisc/testhardware.cpp b/tests/blackmisc/testhardware.cpp index 9c3333d1f..c940bf988 100644 --- a/tests/blackmisc/testhardware.cpp +++ b/tests/blackmisc/testhardware.cpp @@ -23,13 +23,11 @@ namespace BlackMiscTest void CTestHardware::keyboardKey() { // Test equal operator - CKeyboardKey key = CKeyboardKey(Qt::Key_5, '5', CKeyboardKey::ModifierAltLeft, CKeyboardKey::ModifierCtrlLeft, CKeyboardKey::HotkeyPtt); + CKeyboardKey key = CKeyboardKey(Qt::Key_5, CKeyboardKey::ModifierAltLeft, CKeyboardKey::ModifierCtrlLeft); CKeyboardKey key2; key2.setKey(Qt::Key_5); key2.setModifier1(CKeyboardKey::ModifierAltLeft); key2.setModifier2(CKeyboardKey::ModifierCtrlLeft); - key2.setFunction(CKeyboardKey::HotkeyPtt); - key2.setNativeVirtualKey('5'); QVERIFY2(key == key2, "CKeyboardKey::operator== failed!"); key = CKeyboardKey(); @@ -55,19 +53,13 @@ namespace BlackMiscTest QVERIFY2(key.getModifier1() == CKeyboardKey::ModifierAltLeft, "Expected modifier to be ModifierAltLeft"); QVERIFY2(key.getModifier2() == CKeyboardKey::ModifierNone, "Expected modifier to be ModifierAltLeft"); - // relaxed checks - key = CKeyboardKey(Qt::Key_1, 0, CKeyboardKey::ModifierCtrlLeft, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyPtt); - key2 = CKeyboardKey(Qt::Key_1, 0, CKeyboardKey::ModifierCtrlLeft, CKeyboardKey::ModifierNone, CKeyboardKey::HotkeyOpacity50); - - QVERIFY2(key != key2, "Function differs, values shall be unequal"); - QVERIFY2(key.equalsWithoutFunction(key2), "Function differs, values shall be equal without function"); + key = CKeyboardKey(Qt::Key_1, CKeyboardKey::ModifierCtrlLeft, CKeyboardKey::ModifierNone); + key2 = CKeyboardKey(Qt::Key_1, CKeyboardKey::ModifierCtrlLeft, CKeyboardKey::ModifierNone); key2 = key; key2.setModifier1(CKeyboardKey::ModifierCtrlAny); QVERIFY2(key != key2, "Modifiers differs, values shall be unequal"); QVERIFY2(key.equalsWithRelaxedModifiers(key2), "Modifiers are relaxed easy, values shall be equal"); - key2.setFunction(CKeyboardKey::HotkeyToggleCom2); - QVERIFY2(key.equalsWithRelaxedModifiers(key2, true), "Modifiers are relaxed easy, function ignored, value shall be equal without function"); } } // namespace