Skip to content

Commit

Permalink
Effect chain selectors: add empty item to allow clearing the chain
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Aug 12, 2022
1 parent 5473fa8 commit d04b428
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/effects/effectchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ const QString& EffectChain::presetName() const {

void EffectChain::loadChainPreset(EffectChainPresetPointer pPreset) {
slotControlClear(1);
VERIFY_OR_DEBUG_ASSERT(pPreset) {
if (!pPreset) {
// This may happen when a chain is cleared by selecting the
// empty '---' item in skins or DlgPrefEq (deck QuickEffects).
m_presetName = kNoEffectString;
emit chainPresetChanged(kNoEffectString);
setControlLoadedPresetIndex(-1);
return;
}

Expand Down
11 changes: 7 additions & 4 deletions src/preferences/dialog/dlgprefeq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,13 @@ void DlgPrefEQ::slotQuickEffectChangedOnDeck(int effectIndex) {
QString deckGroupName = PlayerManager::groupForDeck(deckNumber);
QString unitGroup = QuickEffectChain::formatEffectChainGroup(deckGroupName);
EffectChainPointer pChain = m_pEffectsManager->getEffectChain(unitGroup);
QList<EffectChainPresetPointer> presetList =
m_pChainPresetManager->getQuickEffectPresetsSorted();
if (pChain && effectIndex > 0 && effectIndex <= presetList.size()) {
pChain->loadChainPreset(presetList[effectIndex - 1]);
QList<EffectChainPresetPointer> presetList;
// add nullptr for empty '---' combobox dummy item (both are first in each list)
presetList.append(nullptr);
// add available Quick Effect chains
presetList.append(m_pChainPresetManager->getQuickEffectPresetsSorted());
if (pChain && effectIndex > -1 && effectIndex <= presetList.size()) {
pChain->loadChainPreset(presetList[effectIndex]);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/widget/weffectchainpresetbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ void WEffectChainPresetButton::populateMenu() {
for (const auto& pChainPreset : m_pChainPresetManager->getPresetsSorted()) {
QString title = pChainPreset->name();
if (title == m_pChain->presetName()) {
// TODO(ronso0) use icon instead to allow custom styles
title = QChar(0x2713) + // CHECK MARK
QChar(' ') + title;
chainIsPreset = true;
}
// TODO(ronso0) Test if the checkmark icon can be set via checkable() state
// addAction(icon, title, receiver, member);
m_pMenu->addAction(title, this, [this, pChainPreset]() {
m_pChain->loadChainPreset(pChainPreset);
});
}

m_pMenu->addSeparator();

if (chainIsPreset) {
m_pMenu->addAction(tr("Update Preset"), this, [this]() {
m_pChainPresetManager->updatePreset(m_pChain);
Expand Down
5 changes: 5 additions & 0 deletions src/widget/weffectchainpresetselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ void WEffectChainPresetSelector::populate() {

QFontMetrics metrics(font());

// Add empty item: no effect
addItem(kNoEffectString, kNoEffectString);
setItemData(0, QVariant(tr("No effect loaded.")), Qt::ToolTipRole);

QList<EffectChainPresetPointer> presetList;
if (m_bQuickEffectChain) {
presetList = m_pEffectsManager->getChainPresetManager()->getQuickEffectPresetsSorted();
Expand Down Expand Up @@ -91,6 +95,7 @@ void WEffectChainPresetSelector::slotEffectChainPresetSelected(int index) {
// After selecting an effect send Shift+Tab to move focus to the next
// keyboard-focusable widget (tracks table in official skins) in order
// to immediately allow keyboard shortcuts again.
// TODO use FocusWidget
QKeyEvent backwardFocusKeyEvent =
QKeyEvent{QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier};
QApplication::sendEvent(this, &backwardFocusKeyEvent);
Expand Down

0 comments on commit d04b428

Please sign in to comment.