Skip to content

Commit

Permalink
Merge pull request mixxxdj#13329 from ronso0/effects-pref-hide-unhide…
Browse files Browse the repository at this point in the history
…-btn

Preferences Effects: add Hide/Unhide (move) buttons to Effects tab
  • Loading branch information
daschuer authored Jan 19, 2025
2 parents 42ebc92 + 5d2d4f7 commit c327cf1
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 13 deletions.
72 changes: 69 additions & 3 deletions src/preferences/dialog/dlgprefeffects.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "preferences/dialog/dlgprefeffects.h"

#include <QFocusEvent>
#include <QMimeData>

#include "effects/backends/effectmanifest.h"
#include "effects/backends/effectsbackend.h"
Expand Down Expand Up @@ -36,6 +37,17 @@ DlgPrefEffects::DlgPrefEffects(QWidget* pParent,
hiddenEffectsTableView->setModel(m_pHiddenEffectsModel);
setupManifestTableView(hiddenEffectsTableView);

updateHideUnhideButtons();
// TODO Use only one button, set text/icon depending on focused list view?
connect(hideButton,
&QPushButton::clicked,
this,
&DlgPrefEffects::slotHideUnhideEffect);
connect(unhideButton,
&QPushButton::clicked,
this,
&DlgPrefEffects::slotHideUnhideEffect);

setupChainListView(chainListView);
setupChainListView(quickEffectListView);

Expand Down Expand Up @@ -112,10 +124,11 @@ void DlgPrefEffects::slotUpdate() {
hiddenEffects.removeAll(pManifest);
}
m_pHiddenEffectsModel->setList(hiddenEffects);
updateHideUnhideButtons();

// No chain preset is selected when the preferences are opened
clearChainInfo();
updateButtons(0);
updateChainPresetButtons(0);

loadChainPresetLists();

Expand Down Expand Up @@ -162,14 +175,25 @@ void DlgPrefEffects::clearChainInfo() {
}
}

void DlgPrefEffects::updateButtons(int selectedIndices) {
void DlgPrefEffects::updateChainPresetButtons(int selectedIndices) {
// Allow Delete and Export of multiple presets
chainPresetDeleteButton->setEnabled(selectedIndices > 0);
chainPresetExportButton->setEnabled(selectedIndices > 0);
// Enable Rename only for one preset
chainPresetRenameButton->setEnabled(selectedIndices == 1);
}

void DlgPrefEffects::updateHideUnhideButtons(const QModelIndex& selected) {
if (!selected.isValid() || m_pFocusedEffectList == nullptr) {
hideButton->setEnabled(false);
unhideButton->setEnabled(false);
return;
}
bool enableHide = m_pFocusedEffectList == visibleEffectsTableView;
hideButton->setEnabled(enableHide);
unhideButton->setEnabled(!enableHide);
}

void DlgPrefEffects::loadChainPresetLists() {
QStringList chainPresetNames;
for (const auto& pChainPreset : m_pChainPresetManager->getPresetsSorted()) {
Expand Down Expand Up @@ -201,6 +225,7 @@ void DlgPrefEffects::effectsTableItemSelected(const QModelIndex& selected) {
// in eventFilter()
if (!selected.isValid()) {
clearEffectInfo();
updateHideUnhideButtons();
return;
}
const auto* pModel = static_cast<const EffectManifestTableModel*>(selected.model());
Expand All @@ -217,6 +242,47 @@ void DlgPrefEffects::effectsTableItemSelected(const QModelIndex& selected) {
effectDescription->setText(pManifest->description());
effectVersion->setText(pManifest->version());
effectType->setText(EffectsBackend::translatedBackendName(pManifest->backendType()));
updateHideUnhideButtons(selected);
}

void DlgPrefEffects::slotHideUnhideEffect() {
auto* pSourceList = m_pFocusedEffectList;
auto* pTargetList = unfocusedEffectList();
VERIFY_OR_DEBUG_ASSERT(pSourceList && pTargetList) {
return;
}
auto* pSelectionModel = pSourceList->selectionModel();
if (!pSelectionModel || pSelectionModel->selectedRows().size() != 1) {
return;
}
auto* pSourceModel = static_cast<EffectManifestTableModel*>(pSourceList->model());
VERIFY_OR_DEBUG_ASSERT(pSourceModel) {
return;
}
auto* pTargetModel = static_cast<EffectManifestTableModel*>(pTargetList->model());
VERIFY_OR_DEBUG_ASSERT(pTargetModel) {
return;
}
QModelIndex selIdx = pSelectionModel->selectedRows().first();
EffectManifestPointer pManifest = pSourceModel->getList().at(selIdx.row());
VERIFY_OR_DEBUG_ASSERT(pManifest) {
return;
}

QMimeData* mimeData = new QMimeData;
mimeData->setText(pManifest->uniqueId());
// Append the selected effect to the target list
if (!pTargetModel->dropMimeData(mimeData)) {
return;
}
// Note the added item so we can remove it if necessary
QModelIndex pMovedEffect = pTargetModel->index(pTargetModel->rowCount() - 1, 0);
DEBUG_ASSERT(pMovedEffect.isValid());

if (!pSourceModel->removeRows(selIdx.row(), 1, selIdx.parent())) {
// If removing failed, undo add to target list
pTargetModel->removeRows(pMovedEffect.row(), 1, pMovedEffect.parent());
}
}

void DlgPrefEffects::slotChainPresetSelectionChanged(const QItemSelection& selected) {
Expand All @@ -227,7 +293,7 @@ void DlgPrefEffects::slotChainPresetSelectionChanged(const QItemSelection& selec
auto* pSelModel = m_pFocusedChainList->selectionModel();
auto selIndices = pSelModel->selectedIndexes();

updateButtons(selIndices.count());
updateChainPresetButtons(selIndices.count());

// Clear the info box and return if the index is invalid, e.g. after clearCurrentIndex()
// in eventFilter()
Expand Down
4 changes: 3 additions & 1 deletion src/preferences/dialog/dlgprefeffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DlgPrefEffects : public DlgPreferencePage, public Ui::DlgPrefEffectsDlg {

private slots:
void effectsTableItemSelected(const QModelIndex& selected);
void slotHideUnhideEffect();
void slotChainPresetSelectionChanged(const QItemSelection& selected);
void slotImportPreset();
void slotExportPreset();
Expand All @@ -35,7 +36,8 @@ class DlgPrefEffects : public DlgPreferencePage, public Ui::DlgPrefEffectsDlg {

void clearEffectInfo();
void clearChainInfo();
void updateButtons(int selectedIndices);
void updateChainPresetButtons(int selectedIndices);
void updateHideUnhideButtons(const QModelIndex& selected = QModelIndex());
void loadChainPresetLists();
void saveChainPresetLists();

Expand Down
94 changes: 91 additions & 3 deletions src/preferences/dialog/dlgprefeffectsdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<property name="currentIndex">
<number>0</number>
</property>

<widget class="QWidget" name="chainPresetsTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
Expand Down Expand Up @@ -230,6 +231,7 @@
</item>
</layout>
</widget>

<widget class="QWidget" name="visibleEffectsTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
Expand All @@ -243,7 +245,7 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="effectsTablesGridLayout">
<item row="0" column="0" colspan="2">
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="effectsTablesHeaderLabel">
<property name="text">
<string>Drag and drop to rearrange lists and show or hide effects.</string>
Expand All @@ -266,7 +268,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="2">
<widget class="QLabel" name="hiddenEffectsTableLabel">
<property name="font">
<font>
Expand All @@ -282,13 +284,95 @@
</property>
</widget>
</item>

<item row="2" column="0">
<widget class="QTableView" name="visibleEffectsTableView"/>
</item>

<item row="2" column="1">
<layout class="QVBoxLayout" name="moveButtonslayout">
<item>
<spacer name="hideShowVSpacerTop">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="fixedSize">
<size>
<width>20</width>
<height>60</height>
</size>
</property>
</spacer>
</item>

<item>
<widget class="QPushButton" name="hideButton">
<property name="text">
<string>❯</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="fixedSize">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</item>

<item>
<widget class="QPushButton" name="unhideButton">
<property name="text">
<string>❮</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="fixedSize">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</item>

<item>
<spacer name="hideShowVSpacerBottom">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>

</layout>
</item>

<item row="2" column="2">
<widget class="QTableView" name="hiddenEffectsTableView"/>
</item>
<item row="3" column="0" colspan="2">

<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
Expand Down Expand Up @@ -469,6 +553,7 @@
</widget>
</widget>
</item>

<item>
<widget class="QGroupBox" name="groupMetaKnobOption">
<property name="title">
Expand Down Expand Up @@ -498,12 +583,15 @@
</layout>
</widget>
</item>

</layout>
</widget>
<tabstops>
<tabstop>chainListView</tabstop>
<tabstop>quickEffectListView</tabstop>
<tabstop>visibleEffectsTableView</tabstop>
<tabstop>hideButton</tabstop>
<tabstop>unhideButton</tabstop>
<tabstop>hiddenEffectsTableView</tabstop>
<tabstop>chainPresetImportButton</tabstop>
<tabstop>chainPresetExportButton</tabstop>
Expand Down
6 changes: 4 additions & 2 deletions src/preferences/effectmanifesttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ bool EffectManifestTableModel::dropMimeData(const QMimeData* data,
return false;
}
if (row == -1) {
row = parent.row();
if (parent.isValid()) {
row = parent.row();
}
// Dropping onto an empty model or dropping past the end of a model
if (parent.row() == -1) {
if (row == -1) {
row = m_manifests.size();
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/preferences/effectmanifesttablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class EffectManifestTableModel : public QAbstractTableModel {
// These functions are required for drag and drop.
Qt::ItemFlags flags(const QModelIndex& index) const override;
QMimeData* mimeData(const QModelIndexList& indexes) const override;
// Set defaults so we can call it with mime data only for inserting
// an effect at the end
bool dropMimeData(
const QMimeData* data,
Qt::DropAction action,
int row,
int column,
const QModelIndex& parent) override;
Qt::DropAction action = Qt::MoveAction,
int row = -1,
int column = -1,
const QModelIndex& parent = QModelIndex()) override;
QStringList mimeTypes() const override;
Qt::DropActions supportedDropActions() const override;
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
Expand Down

0 comments on commit c327cf1

Please sign in to comment.