diff --git a/src/palette/internal/paletteconfiguration.cpp b/src/palette/internal/paletteconfiguration.cpp index e918a91101d78..7e26ad931d557 100644 --- a/src/palette/internal/paletteconfiguration.cpp +++ b/src/palette/internal/paletteconfiguration.cpp @@ -36,6 +36,7 @@ static const std::string MODULE_NAME("palette"); static const Settings::Key PALETTE_SCALE(MODULE_NAME, "application/paletteScale"); static const Settings::Key PALETTE_USE_SINGLE(MODULE_NAME, "application/useSinglePalette"); static const Settings::Key IS_SINGLE_CLICK_TO_OPEN_PALETTE(MODULE_NAME, "application/singleClickToOpenPalette"); +static const Settings::Key IS_PALETTE_DRAG_ENABLED(MODULE_NAME, "application/paletteDragEnabled"); void PaletteConfiguration::init() { @@ -56,6 +57,13 @@ void PaletteConfiguration::init() settings()->valueChanged(IS_SINGLE_CLICK_TO_OPEN_PALETTE).onReceive(this, [this](const Val& newValue) { m_isSingleClickToOpenPalette.set(newValue.toBool()); }); + + settings()->setDefaultValue(IS_PALETTE_DRAG_ENABLED, Val(true)); + + m_isPaletteDragEnabled.val = settings()->value(IS_PALETTE_DRAG_ENABLED).toBool(); + settings()->valueChanged(IS_PALETTE_DRAG_ENABLED).onReceive(this, [this](const Val& newValue) { + m_isPaletteDragEnabled.set(newValue.toBool()); + }); } double PaletteConfiguration::paletteScaling() const @@ -97,6 +105,16 @@ void PaletteConfiguration::setIsSingleClickToOpenPalette(bool isSingleClick) settings()->setSharedValue(IS_SINGLE_CLICK_TO_OPEN_PALETTE, Val(isSingleClick)); } +ValCh PaletteConfiguration::isPaletteDragEnabled() const +{ + return m_isPaletteDragEnabled; +} + +void PaletteConfiguration::setIsPaletteDragEnabled(bool enabled) +{ + settings()->setSharedValue(IS_PALETTE_DRAG_ENABLED, Val(enabled)); +} + QColor PaletteConfiguration::elementsBackgroundColor() const { return themeColor(BACKGROUND_PRIMARY_COLOR); diff --git a/src/palette/internal/paletteconfiguration.h b/src/palette/internal/paletteconfiguration.h index 42e3ea0cb40f4..45bd3e5eb7287 100644 --- a/src/palette/internal/paletteconfiguration.h +++ b/src/palette/internal/paletteconfiguration.h @@ -49,6 +49,9 @@ class PaletteConfiguration : public IPaletteConfiguration, public muse::async::A muse::ValCh isSingleClickToOpenPalette() const override; void setIsSingleClickToOpenPalette(bool isSingleClick) override; + muse::ValCh isPaletteDragEnabled() const override; + void setIsPaletteDragEnabled(bool enabled) override; + QColor elementsBackgroundColor() const override; QColor elementsColor() const override; QColor gridColor() const override; @@ -72,6 +75,7 @@ class PaletteConfiguration : public IPaletteConfiguration, public muse::async::A muse::ValCh m_isSinglePalette; muse::ValCh m_isSingleClickToOpenPalette; + muse::ValCh m_isPaletteDragEnabled; mutable QHash > m_paletteConfigs; mutable QHash > m_paletteCellsConfigs; diff --git a/src/palette/internal/paletteprovider.cpp b/src/palette/internal/paletteprovider.cpp index 869b2ea75418d..f741f5a6f6a22 100644 --- a/src/palette/internal/paletteprovider.cpp +++ b/src/palette/internal/paletteprovider.cpp @@ -614,6 +614,10 @@ void PaletteProvider::init() configuration()->isSingleClickToOpenPalette().ch.onReceive(this, [this](bool) { emit isSingleClickToOpenPaletteChanged(); }); + + configuration()->isPaletteDragEnabled().ch.onReceive(this, [this](bool) { + emit isPaletteDragEnabledChanged(); + }); } void PaletteProvider::setFilter(const QString& filter) @@ -654,6 +658,11 @@ bool PaletteProvider::isSingleClickToOpenPalette() const return configuration()->isSingleClickToOpenPalette().val; } +bool PaletteProvider::isPaletteDragEnabled() const +{ + return configuration()->isPaletteDragEnabled().val; +} + QAbstractItemModel* PaletteProvider::mainPaletteModel() { if (m_isSearching) { diff --git a/src/palette/internal/paletteprovider.h b/src/palette/internal/paletteprovider.h index aecfce8760991..c3934ce20f253 100644 --- a/src/palette/internal/paletteprovider.h +++ b/src/palette/internal/paletteprovider.h @@ -215,6 +215,7 @@ class PaletteProvider : public QObject, public IPaletteProvider, public muse::as Q_PROPERTY(bool isSinglePalette READ isSinglePalette NOTIFY isSinglePaletteChanged) Q_PROPERTY(bool isSingleClickToOpenPalette READ isSingleClickToOpenPalette NOTIFY isSingleClickToOpenPaletteChanged) + Q_PROPERTY(bool isPaletteDragEnabled READ isPaletteDragEnabled NOTIFY isPaletteDragEnabledChanged) public: void init() override; @@ -262,6 +263,7 @@ class PaletteProvider : public QObject, public IPaletteProvider, public muse::as bool isSinglePalette() const; bool isSingleClickToOpenPalette() const; + bool isPaletteDragEnabled() const; signals: void userPaletteChanged(); @@ -269,6 +271,7 @@ class PaletteProvider : public QObject, public IPaletteProvider, public muse::as void isSinglePaletteChanged(); void isSingleClickToOpenPaletteChanged(); + void isPaletteDragEnabledChanged(); private slots: void notifyAboutUserPaletteChanged() diff --git a/src/palette/ipaletteconfiguration.h b/src/palette/ipaletteconfiguration.h index 811a2e14afd7d..ad3936e70b0a4 100644 --- a/src/palette/ipaletteconfiguration.h +++ b/src/palette/ipaletteconfiguration.h @@ -49,6 +49,9 @@ class IPaletteConfiguration : MODULE_EXPORT_INTERFACE virtual muse::ValCh isSingleClickToOpenPalette() const = 0; virtual void setIsSingleClickToOpenPalette(bool isSingleClick) = 0; + virtual muse::ValCh isPaletteDragEnabled() const = 0; + virtual void setIsPaletteDragEnabled(bool enabled) = 0; + virtual QColor elementsBackgroundColor() const = 0; virtual QColor elementsColor() const = 0; virtual QColor gridColor() const = 0; diff --git a/src/palette/qml/MuseScore/Palette/internal/PaletteTree.qml b/src/palette/qml/MuseScore/Palette/internal/PaletteTree.qml index ef486a2e6b064..2562acd78c539 100644 --- a/src/palette/qml/MuseScore/Palette/internal/PaletteTree.qml +++ b/src/palette/qml/MuseScore/Palette/internal/PaletteTree.qml @@ -519,7 +519,7 @@ StyledListView { width: ListView.view.width - Drag.active: paletteHeaderDragArea.drag.active + Drag.active: paletteProvider.isPaletteDragEnabled && paletteHeaderDragArea.drag.active Drag.dragType: Drag.Automatic Drag.supportedActions: Qt.MoveAction Drag.proposedAction: Qt.MoveAction diff --git a/src/palette/view/palettespanelcontextmenumodel.cpp b/src/palette/view/palettespanelcontextmenumodel.cpp index 5d1e3e476771c..4cf9c9ddfeb17 100644 --- a/src/palette/view/palettespanelcontextmenumodel.cpp +++ b/src/palette/view/palettespanelcontextmenumodel.cpp @@ -35,6 +35,7 @@ using namespace muse::uicomponents; static const ActionCode TOGGLE_SINGLE_CLICK_CODE("toggle-single-click-to-open-palette"); static const ActionCode TOGGLE_SINGLE_PALETTE_CODE("toggle-single-palette"); +static const ActionCode TOGGLE_PALETTE_DRAG("toggle-palette-drag"); static const ActionCode EXPAND_ALL_CODE("expand-all-palettes"); static const ActionCode COLLAPSE_ALL_CODE("collapse-all-palettes"); @@ -48,6 +49,7 @@ void PalettesPanelContextMenuModel::load() MenuItemList items { createIsSingleClickToOpenPaletteItem(), createIsSinglePaletteItem(), + createIsDragEnabledItem(), makeSeparator(), createExpandCollapseAllItem(false), createExpandCollapseAllItem(true), @@ -121,6 +123,38 @@ MenuItem* PalettesPanelContextMenuModel::createIsSinglePaletteItem() return item; } +MenuItem* PalettesPanelContextMenuModel::createIsDragEnabledItem() +{ + MenuItem* item = new MenuItem(this); + item->setId(QString::fromStdString(TOGGLE_PALETTE_DRAG)); + + UiAction action; + action.title = TranslatableString("palette", "Allow reordering palettes"); + action.code = TOGGLE_PALETTE_DRAG; + action.checkable = Checkable::Yes; + item->setAction(action); + + ValCh checked = configuration()->isPaletteDragEnabled(); + + UiActionState state; + state.enabled = true; + state.checked = checked.val; + item->setState(state); + + checked.ch.onReceive(item, [item](bool newValue) { + UiActionState state = item->state(); + state.checked = newValue; + item->setState(state); + }); + + dispatcher()->reg(this, TOGGLE_PALETTE_DRAG, [this, item]() { + bool newValue = !item->state().checked; + configuration()->setIsPaletteDragEnabled(newValue); + }); + + return item; +} + MenuItem* PalettesPanelContextMenuModel::createExpandCollapseAllItem(bool expand) { MenuItem* item = new MenuItem(this); diff --git a/src/palette/view/palettespanelcontextmenumodel.h b/src/palette/view/palettespanelcontextmenumodel.h index c3d9a66019001..61af664959ca9 100644 --- a/src/palette/view/palettespanelcontextmenumodel.h +++ b/src/palette/view/palettespanelcontextmenumodel.h @@ -48,6 +48,7 @@ class PalettesPanelContextMenuModel : public muse::uicomponents::AbstractMenuMod private: muse::uicomponents::MenuItem* createIsSingleClickToOpenPaletteItem(); muse::uicomponents::MenuItem* createIsSinglePaletteItem(); + muse::uicomponents::MenuItem* createIsDragEnabledItem(); muse::uicomponents::MenuItem* createExpandCollapseAllItem(bool expand); }; } diff --git a/src/stubs/palette/paletteconfigurationstub.cpp b/src/stubs/palette/paletteconfigurationstub.cpp index 5fbd069fe7583..3b72c69727778 100644 --- a/src/stubs/palette/paletteconfigurationstub.cpp +++ b/src/stubs/palette/paletteconfigurationstub.cpp @@ -56,6 +56,15 @@ void PaletteConfigurationStub::setIsSingleClickToOpenPalette(bool) { } +ValCh PaletteConfigurationStub::isPaletteDragEnabled() const +{ + return ValCh(); +} + +void PaletteConfigurationStub::setIsPaletteDragEnabled(bool) +{ +} + QColor PaletteConfigurationStub::elementsBackgroundColor() const { return QColor(); diff --git a/src/stubs/palette/paletteconfigurationstub.h b/src/stubs/palette/paletteconfigurationstub.h index 90ecb1aafbd46..a677706b7152f 100644 --- a/src/stubs/palette/paletteconfigurationstub.h +++ b/src/stubs/palette/paletteconfigurationstub.h @@ -39,6 +39,9 @@ class PaletteConfigurationStub : public IPaletteConfiguration muse::ValCh isSingleClickToOpenPalette() const override; void setIsSingleClickToOpenPalette(bool isSingleClick) override; + muse::ValCh isPaletteDragEnabled() const override; + void setIsPaletteDragEnabled(bool isSingleClick) override; + QColor elementsBackgroundColor() const override; QColor elementsColor() const override; QColor gridColor() const override;