From 68907258a56ba3c86cd032375c87d99825ea0c2e Mon Sep 17 00:00:00 2001 From: Roland Rossgotterer Date: Thu, 14 Feb 2019 16:10:43 +0100 Subject: [PATCH] Add method to get joystick button name including a device prefix --- src/blackmisc/input/hotkeycombination.cpp | 15 +++++++++++++++ src/blackmisc/input/hotkeycombination.h | 3 +++ src/blackmisc/input/joystickbutton.cpp | 5 +++++ src/blackmisc/input/joystickbutton.h | 3 +++ 4 files changed, 26 insertions(+) diff --git a/src/blackmisc/input/hotkeycombination.cpp b/src/blackmisc/input/hotkeycombination.cpp index 39cebddf5..183eccd55 100644 --- a/src/blackmisc/input/hotkeycombination.cpp +++ b/src/blackmisc/input/hotkeycombination.cpp @@ -89,5 +89,20 @@ namespace BlackMisc } return sl.join('+'); } + + QString CHotkeyCombination::asStringWithDeviceNames() const + { + QStringList sl; + sl.reserve(m_keyboardKeys.size() + m_joystickButtons.size()); + for (const auto &key : m_keyboardKeys) + { + sl << key.toQString(); + } + for (const auto &button : m_joystickButtons) + { + sl << button.getButtonAsStringWithDeviceName(); + } + return sl.join('+'); + } } // ns } // ns diff --git a/src/blackmisc/input/hotkeycombination.h b/src/blackmisc/input/hotkeycombination.h index 68735475b..a063d9d3a 100644 --- a/src/blackmisc/input/hotkeycombination.h +++ b/src/blackmisc/input/hotkeycombination.h @@ -86,6 +86,9 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; + //! Returns the button name with the device name prefix + QString asStringWithDeviceNames() const; + private: CKeyboardKeyList m_keyboardKeys; CJoystickButtonList m_joystickButtons; diff --git a/src/blackmisc/input/joystickbutton.cpp b/src/blackmisc/input/joystickbutton.cpp index cf356b307..9b3a51ab8 100644 --- a/src/blackmisc/input/joystickbutton.cpp +++ b/src/blackmisc/input/joystickbutton.cpp @@ -19,6 +19,11 @@ namespace BlackMisc m_deviceName(deviceName), m_buttonIndex(index) {} + QString CJoystickButton::getButtonAsStringWithDeviceName() const + { + return QString("%1 Button%2").arg(m_deviceName).arg(m_buttonIndex); + } + void CJoystickButton::setButtonIndex(int buttonIndex) { m_buttonIndex = buttonIndex; diff --git a/src/blackmisc/input/joystickbutton.h b/src/blackmisc/input/joystickbutton.h index 381aa345d..16c61dba9 100644 --- a/src/blackmisc/input/joystickbutton.h +++ b/src/blackmisc/input/joystickbutton.h @@ -54,6 +54,9 @@ namespace BlackMisc //! Get button as String QString getButtonAsString() const { return buttonIndexToString(m_buttonIndex); } + //! Get button as String including its device name + QString getButtonAsStringWithDeviceName() const; + //! Set owning device name void setDeviceName(const QString &deviceName) { m_deviceName = deviceName; }