mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
[Hotkey] Style
This commit is contained in:
committed by
Mat Sutcliffe
parent
9dbb441e44
commit
ef4640e66f
@@ -69,13 +69,13 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIdentifier: return CVariant::from(m_identifier);
|
||||
case IndexIdentifierAsString: return CVariant::from(m_identifier.getMachineName());
|
||||
case IndexAction: return CVariant::from(m_action);
|
||||
case IndexActionAsString: return CVariant::from(m_action);
|
||||
case IndexCombination: return CVariant::from(m_combination);
|
||||
case IndexIdentifier: return CVariant::from(m_identifier);
|
||||
case IndexIdentifierAsString: return CVariant::from(m_identifier.getMachineName());
|
||||
case IndexAction: return CVariant::from(m_action);
|
||||
case IndexActionAsString: return CVariant::from(m_action);
|
||||
case IndexCombination: return CVariant::from(m_combination);
|
||||
case IndexCombinationAsString: return CVariant::from(QString(m_combination.toQString()));
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,9 +100,9 @@ namespace BlackMisc
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
CIdentifier m_identifier; //!< Identifier to which machine this hotkey belongs to
|
||||
CIdentifier m_identifier; //!< Identifier to which machine this hotkey belongs to
|
||||
CHotkeyCombination m_combination; //!< hotkey combination
|
||||
QString m_action; //!< hotkey action
|
||||
QString m_action; //!< hotkey action
|
||||
|
||||
BLACK_METACLASS(
|
||||
CActionHotkey,
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace BlackMisc
|
||||
|
||||
QString CHotkeyCombination::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
Q_UNUSED(i18n)
|
||||
QStringList sl;
|
||||
sl.reserve(m_keyboardKeys.size() + m_joystickButtons.size());
|
||||
for (const auto &key : m_keyboardKeys)
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace BlackMisc
|
||||
QString asStringWithDeviceNames() const;
|
||||
|
||||
private:
|
||||
CKeyboardKeyList m_keyboardKeys;
|
||||
CKeyboardKeyList m_keyboardKeys;
|
||||
CJoystickButtonList m_joystickButtons;
|
||||
|
||||
BLACK_METACLASS(
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/input/joystickbutton.h"
|
||||
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -20,7 +19,7 @@ namespace BlackMisc
|
||||
|
||||
QString CJoystickButton::getButtonAsStringWithDeviceName() const
|
||||
{
|
||||
return QString("%1 Button%2").arg(m_deviceName).arg(m_buttonIndex);
|
||||
return QStringLiteral("%1%2 - %3").arg(buttonIndentifier()).arg(m_buttonIndex).arg(m_deviceName);
|
||||
}
|
||||
|
||||
void CJoystickButton::setButtonIndex(int buttonIndex)
|
||||
@@ -30,20 +29,19 @@ namespace BlackMisc
|
||||
|
||||
bool CJoystickButton::isValid() const
|
||||
{
|
||||
if (!m_deviceName.isEmpty() && m_buttonIndex >= 0) { return true; }
|
||||
else { return false; }
|
||||
return (!m_deviceName.isEmpty() && m_buttonIndex >= 0);
|
||||
}
|
||||
|
||||
void CJoystickButton::setButtonObject(CJoystickButton button)
|
||||
{
|
||||
m_deviceName = button.m_deviceName;
|
||||
m_deviceName = button.m_deviceName;
|
||||
m_buttonIndex = button.m_buttonIndex;
|
||||
}
|
||||
|
||||
void CJoystickButton::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CJoystickButton>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDeviceName:
|
||||
@@ -65,13 +63,13 @@ namespace BlackMisc
|
||||
CVariant CJoystickButton::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDeviceName: return CVariant::from(this->getDeviceName());
|
||||
case IndexButton: return CVariant::from(this->getButtonIndex());
|
||||
case IndexDeviceName: return CVariant::from(this->getDeviceName());
|
||||
case IndexButton: return CVariant::from(this->getButtonIndex());
|
||||
case IndexButtonAsString: return CVariant::from(this->getButtonAsString());
|
||||
case IndexButtonObject: return CVariant::from(*this);
|
||||
case IndexButtonObject: return CVariant::from(*this);
|
||||
}
|
||||
|
||||
Q_ASSERT_X(false, "CJoystickButton", "index unknown");
|
||||
@@ -81,25 +79,22 @@ namespace BlackMisc
|
||||
|
||||
QString CJoystickButton::buttonIndexToString(qint32 buttonIndex)
|
||||
{
|
||||
QString buttonString("Button");
|
||||
return buttonString.append(QStringLiteral("%1").arg(buttonIndex));
|
||||
return buttonIndentifier() + QString::number(buttonIndex);
|
||||
}
|
||||
|
||||
int CJoystickButton::buttonIndexFromString(const QString &buttonName)
|
||||
{
|
||||
QString name("Button");
|
||||
if (!buttonName.startsWith(name)) return getInvalidIndex();
|
||||
|
||||
name.remove("Button");
|
||||
return name.toInt();
|
||||
if (!buttonName.startsWith(buttonIndentifier())) { return getInvalidIndex(); }
|
||||
QString name(buttonName);
|
||||
name.remove(buttonIndentifier());
|
||||
if (name.contains('-')) { name = name.mid(0, name.indexOf('-')); }
|
||||
return name.trimmed().toInt();
|
||||
}
|
||||
|
||||
QString CJoystickButton::convertToQString(bool /* i18n */) const
|
||||
{
|
||||
QString s = getButtonAsString();
|
||||
return s.trimmed();
|
||||
return getButtonAsString().trimmed();
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
||||
} // BlackMisc
|
||||
} // namespace
|
||||
} // namespacexs
|
||||
|
||||
@@ -81,16 +81,17 @@ namespace BlackMisc
|
||||
static int buttonIndexFromString(const QString &button);
|
||||
|
||||
//! Invalid button index
|
||||
static int getInvalidIndex() { return m_invalidIndex; }
|
||||
static int getInvalidIndex() { return InvalidButtonIndex; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
QString m_deviceName;
|
||||
int m_buttonIndex = m_invalidIndex;
|
||||
static const QString &buttonIndentifier() { static const QString bn("Button"); return bn; }
|
||||
static constexpr int InvalidButtonIndex = -1;
|
||||
|
||||
static constexpr int m_invalidIndex = -1;
|
||||
QString m_deviceName;
|
||||
int m_buttonIndex = InvalidButtonIndex;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CJoystickButton,
|
||||
@@ -98,8 +99,8 @@ namespace BlackMisc
|
||||
BLACK_METAMEMBER(buttonIndex)
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Input::CJoystickButton)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user