From 2a347860398e4df5dddfdeceed7e054c4864975c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 24 Nov 2019 21:06:40 +0100 Subject: [PATCH] [Hotkey] Display hotkey name plus device name in hotkey model, resize view if new key has been added or removed --- src/blackgui/components/settingshotkeycomponent.cpp | 13 +++++++++++-- src/blackgui/components/settingshotkeycomponent.h | 3 ++- src/blackgui/models/actionhotkeylistmodel.cpp | 12 +++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp index e0482e011..39571177c 100644 --- a/src/blackgui/components/settingshotkeycomponent.cpp +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -76,12 +76,13 @@ namespace BlackGui const CActionHotkey selectedActionHotkey = CHotkeyDialog::getActionHotkey(CActionHotkey(), getAllIdentifiers(), this); if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey)) { - addHotkeytoSettings(selectedActionHotkey); + addHotkeyToSettings(selectedActionHotkey); const int position = m_model.rowCount(); m_model.insertRows(position, 1, QModelIndex()); const QModelIndex index = m_model.index(position, 0, QModelIndex()); m_model.setData(index, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole); } + this->resizeView(); } void CSettingsHotkeyComponent::editEntry() @@ -100,6 +101,7 @@ namespace BlackGui updateHotkeyInSettings(actionHotkey, selectedActionHotkey); m_model.setData(indexHotkey, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole); } + this->resizeView(); } void CSettingsHotkeyComponent::removeEntry() @@ -111,9 +113,10 @@ namespace BlackGui removeHotkeyFromSettings(actionHotkey); m_model.removeRows(index.row(), 1, QModelIndex()); } + this->resizeView(); } - void CSettingsHotkeyComponent::addHotkeytoSettings(const CActionHotkey &actionHotkey) + void CSettingsHotkeyComponent::addHotkeyToSettings(const CActionHotkey &actionHotkey) { CActionHotkeyList actionHotkeyList(m_actionHotkeys.getThreadLocal()); actionHotkeyList.push_back(actionHotkey); @@ -171,6 +174,7 @@ namespace BlackGui const QModelIndex index = m_model.index(position, 0, QModelIndex()); m_model.setData(index, QVariant::fromValue(hotkey), CActionHotkeyListModel::ActionHotkeyRole); } + this->resizeView(); } CIdentifierList CSettingsHotkeyComponent::getAllIdentifiers() const @@ -184,6 +188,11 @@ namespace BlackGui return identifiers; } + void CSettingsHotkeyComponent::resizeView() + { + ui->tv_Hotkeys->resizeRowsToContents(); + } + void CSettingsHotkeyComponent::hotkeySlot(bool keyDown) { if (keyDown) diff --git a/src/blackgui/components/settingshotkeycomponent.h b/src/blackgui/components/settingshotkeycomponent.h index 457c031d6..3db4055f3 100644 --- a/src/blackgui/components/settingshotkeycomponent.h +++ b/src/blackgui/components/settingshotkeycomponent.h @@ -55,11 +55,12 @@ namespace BlackGui void editEntry(); void removeEntry(); void hotkeySlot(bool keyDown); - void addHotkeytoSettings(const BlackMisc::Input::CActionHotkey &actionHotkey); + void addHotkeyToSettings(const BlackMisc::Input::CActionHotkey &actionHotkey); void updateHotkeyInSettings(const BlackMisc::Input::CActionHotkey &oldValue, const BlackMisc::Input::CActionHotkey &newValue); void removeHotkeyFromSettings(const BlackMisc::Input::CActionHotkey &actionHotkey); bool checkAndConfirmConflicts(const BlackMisc::Input::CActionHotkey &actionHotkey, const BlackMisc::Input::CActionHotkeyList &ignore = {}); BlackMisc::CIdentifierList getAllIdentifiers() const; + void resizeView(); QScopedPointer ui; Models::CActionHotkeyListModel m_model; //!< hotkeys model diff --git a/src/blackgui/models/actionhotkeylistmodel.cpp b/src/blackgui/models/actionhotkeylistmodel.cpp index 8bb5a13e3..abf2dce1c 100644 --- a/src/blackgui/models/actionhotkeylistmodel.cpp +++ b/src/blackgui/models/actionhotkeylistmodel.cpp @@ -43,17 +43,19 @@ namespace BlackGui if (role == Qt::DisplayRole) { - if (index.column() == 0) + const int col = index.column(); + if (col == 0) { const CIdentifier identifier = m_actionHotkeys[index.row()].getApplicableMachine(); return identifier.getMachineName(); } - if (index.column() == 1) + if (col == 1) { - CHotkeyCombination combination = m_actionHotkeys[index.row()].getCombination(); - return combination.toQString(); + const CHotkeyCombination combination = m_actionHotkeys[index.row()].getCombination(); + return combination.asStringWithDeviceNames(); + // return combination.toQString(); } - if (index.column() == 2) + if (col == 2) { return m_actionHotkeys[index.row()].getAction(); }