Add method to get joystick button name including a device prefix

This commit is contained in:
Roland Rossgotterer
2019-02-14 16:10:43 +01:00
committed by Mat Sutcliffe
parent e5c435f281
commit 68907258a5
4 changed files with 26 additions and 0 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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; }