diff --git a/src/preferences/dialog/dlgprefeffects.cpp b/src/preferences/dialog/dlgprefeffects.cpp index bf057f6fe16..12916498b1e 100644 --- a/src/preferences/dialog/dlgprefeffects.cpp +++ b/src/preferences/dialog/dlgprefeffects.cpp @@ -1,6 +1,7 @@ #include "preferences/dialog/dlgprefeffects.h" #include +#include #include "effects/backends/effectmanifest.h" #include "effects/backends/effectsbackend.h" @@ -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); @@ -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(); @@ -162,7 +175,7 @@ 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); @@ -170,6 +183,17 @@ void DlgPrefEffects::updateButtons(int selectedIndices) { 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()) { @@ -201,6 +225,7 @@ void DlgPrefEffects::effectsTableItemSelected(const QModelIndex& selected) { // in eventFilter() if (!selected.isValid()) { clearEffectInfo(); + updateHideUnhideButtons(); return; } const auto* pModel = static_cast(selected.model()); @@ -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(pSourceList->model()); + VERIFY_OR_DEBUG_ASSERT(pSourceModel) { + return; + } + auto* pTargetModel = static_cast(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) { @@ -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() diff --git a/src/preferences/dialog/dlgprefeffects.h b/src/preferences/dialog/dlgprefeffects.h index bddf0d1d478..379e3bdec45 100644 --- a/src/preferences/dialog/dlgprefeffects.h +++ b/src/preferences/dialog/dlgprefeffects.h @@ -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(); @@ -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(); diff --git a/src/preferences/dialog/dlgprefeffectsdlg.ui b/src/preferences/dialog/dlgprefeffectsdlg.ui index a59bf462a10..6f4201b91c0 100644 --- a/src/preferences/dialog/dlgprefeffectsdlg.ui +++ b/src/preferences/dialog/dlgprefeffectsdlg.ui @@ -31,6 +31,7 @@ 0 + @@ -230,6 +231,7 @@ + @@ -243,7 +245,7 @@ - + Drag and drop to rearrange lists and show or hide effects. @@ -266,7 +268,7 @@ - + @@ -282,13 +284,95 @@ + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + 20 + 60 + + + + + + + + + + + + + 0 + 0 + + + + + 20 + 40 + + + + + + + + + + + + + 0 + 0 + + + + + 20 + 40 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + - + + @@ -469,6 +553,7 @@ + @@ -498,12 +583,15 @@ + chainListView quickEffectListView visibleEffectsTableView + hideButton + unhideButton hiddenEffectsTableView chainPresetImportButton chainPresetExportButton diff --git a/src/preferences/effectmanifesttablemodel.cpp b/src/preferences/effectmanifesttablemodel.cpp index 9b730e5c714..d4eceb54bd2 100644 --- a/src/preferences/effectmanifesttablemodel.cpp +++ b/src/preferences/effectmanifesttablemodel.cpp @@ -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(); } } diff --git a/src/preferences/effectmanifesttablemodel.h b/src/preferences/effectmanifesttablemodel.h index 7a097ebc2d5..8b53af711eb 100644 --- a/src/preferences/effectmanifesttablemodel.h +++ b/src/preferences/effectmanifesttablemodel.h @@ -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;