[Hotkey] Style

This commit is contained in:
Klaus Basan
2019-11-24 19:32:44 +01:00
committed by Mat Sutcliffe
parent 9dbb441e44
commit ef4640e66f
10 changed files with 54 additions and 60 deletions

View File

@@ -76,6 +76,7 @@ namespace BlackCore
void CInputManager::processKeyCombinationChanged(const CHotkeyCombination &combination)
{
// Merge in the joystick part
// mixed on purpose, as any joystick keyboard combination is possible
CHotkeyCombination copy(combination);
copy.setJoystickButtons(m_lastCombination.getJoystickButtons());
processCombination(copy);
@@ -83,7 +84,8 @@ namespace BlackCore
void CInputManager::processButtonCombinationChanged(const CHotkeyCombination &combination)
{
// Merge in the keyboard dkeys
// Merge in the keyboard keys
// mixed on purpose, as any joystick keyboard combination is possible
CHotkeyCombination copy(combination);
copy.setKeyboardKeys(m_lastCombination.getKeyboardKeys());
processCombination(copy);
@@ -124,7 +126,7 @@ namespace BlackCore
{
m_keyboard = IKeyboard::create(this);
m_joystick = IJoystick::create(this);
connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged, this, &CInputManager::processKeyCombinationChanged, Qt::QueuedConnection);
connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged, this, &CInputManager::processKeyCombinationChanged, Qt::QueuedConnection);
connect(m_joystick.get(), &IJoystick::buttonCombinationChanged, this, &CInputManager::processButtonCombinationChanged, Qt::QueuedConnection);
}

View File

@@ -113,7 +113,7 @@ namespace BlackGui
if (sGui && sGui->getInputManager())
{
connect(sGui->getInputManager(), &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged);
connect(sGui->getInputManager(), &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged);
connect(sGui->getInputManager(), &BlackCore::CInputManager::combinationSelectionFinished, this, &CHotkeyDialog::combinationSelectionFinished);
}
@@ -199,7 +199,7 @@ namespace BlackGui
void CHotkeyDialog::changeSelectedAction(const QItemSelection &selected, const QItemSelection &deselected)
{
Q_UNUSED(deselected);
Q_UNUSED(deselected)
if (selected.indexes().isEmpty()) { return; }
const auto index = selected.indexes().first();
m_actionHotkey.setAction(index.data(CActionModel::ActionRole).toString());
@@ -265,7 +265,7 @@ namespace BlackGui
void CHotkeyDialog::changeApplicableMachine(int index)
{
Q_UNUSED(index);
Q_UNUSED(index)
const QVariant userData = ui->cb_Identifier->currentData();
Q_ASSERT(userData.canConvert<CIdentifier>());
m_actionHotkey.setApplicableMachine(userData.value<CIdentifier>());

View File

@@ -24,8 +24,7 @@ namespace BlackGui
{
CActionHotkeyListModel::CActionHotkeyListModel(QObject *parent) :
QAbstractTableModel(parent)
{
}
{ }
int CActionHotkeyListModel::rowCount(const QModelIndex & /** parent **/) const
{
@@ -40,14 +39,13 @@ namespace BlackGui
QVariant CActionHotkeyListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) { return QVariant(); }
if (index.row() >= m_actionHotkeys.size() || index.row() < 0) { return QVariant(); }
if (role == Qt::DisplayRole)
{
if (index.column() == 0)
{
BlackMisc::CIdentifier identifier = m_actionHotkeys[index.row()].getApplicableMachine();
const CIdentifier identifier = m_actionHotkeys[index.row()].getApplicableMachine();
return identifier.getMachineName();
}
if (index.column() == 1)
@@ -62,7 +60,7 @@ namespace BlackGui
}
else if (role == ActionHotkeyRole)
{
auto hotkey = m_actionHotkeys[index.row()];
const auto hotkey = m_actionHotkeys[index.row()];
return QVariant::fromValue(hotkey);
}
return {};
@@ -72,15 +70,13 @@ namespace BlackGui
{
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Horizontal) {
if (orientation == Qt::Horizontal)
{
switch (section)
{
case 0:
return QStringLiteral("Machine");
case 1:
return QStringLiteral("Combination");
case 2:
return QStringLiteral("Action");
case 0: return QStringLiteral("Machine");
case 1: return QStringLiteral("Combination");
case 2: return QStringLiteral("Action");
}
}
}
@@ -89,7 +85,7 @@ namespace BlackGui
bool CActionHotkeyListModel::insertRows(int position, int rows, const QModelIndex &index)
{
Q_UNUSED(index);
Q_UNUSED(index)
beginInsertRows(QModelIndex(), position, position + rows - 1);
for (int row = 0; row < rows; ++row)
@@ -103,7 +99,7 @@ namespace BlackGui
bool CActionHotkeyListModel::removeRows(int position, int rows, const QModelIndex &index)
{
Q_UNUSED(index);
Q_UNUSED(index)
beginRemoveRows(QModelIndex(), position, position + rows - 1);
Q_ASSERT(position + rows - 1 < m_actionHotkeys.size());
@@ -136,6 +132,5 @@ namespace BlackGui
m_actionHotkeys.clear();
endResetModel();
}
}
} // namespace

View File

@@ -71,6 +71,7 @@ namespace BlackGui
private:
BlackMisc::Input::CActionHotkeyList m_actionHotkeys;
};
}
}
} // ns
} // ns
#endif // guard

View File

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

View File

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

View File

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

View File

@@ -98,7 +98,7 @@ namespace BlackMisc
QString asStringWithDeviceNames() const;
private:
CKeyboardKeyList m_keyboardKeys;
CKeyboardKeyList m_keyboardKeys;
CJoystickButtonList m_joystickButtons;
BLACK_METACLASS(

View File

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

View File

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