Skip to content

Commit

Permalink
allow disabling drag to reorder palettes
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMigros committed Aug 27, 2024
1 parent 009e351 commit 9f07d94
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/palette/internal/paletteconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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
Expand Down Expand Up @@ -97,6 +105,16 @@ void PaletteConfiguration::setIsSingleClickToOpenPalette(bool isSingleClick)
settings()->setSharedValue(IS_SINGLE_CLICK_TO_OPEN_PALETTE, Val(isSingleClick));
}

ValCh<bool> 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);
Expand Down
4 changes: 4 additions & 0 deletions src/palette/internal/paletteconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class PaletteConfiguration : public IPaletteConfiguration, public muse::async::A
muse::ValCh<bool> isSingleClickToOpenPalette() const override;
void setIsSingleClickToOpenPalette(bool isSingleClick) override;

muse::ValCh<bool> isPaletteDragEnabled() const override;
void setIsPaletteDragEnabled(bool enabled) override;

QColor elementsBackgroundColor() const override;
QColor elementsColor() const override;
QColor gridColor() const override;
Expand All @@ -72,6 +75,7 @@ class PaletteConfiguration : public IPaletteConfiguration, public muse::async::A

muse::ValCh<bool> m_isSinglePalette;
muse::ValCh<bool> m_isSingleClickToOpenPalette;
muse::ValCh<bool> m_isPaletteDragEnabled;

mutable QHash<QString, muse::ValCh<PaletteConfig> > m_paletteConfigs;
mutable QHash<QString, muse::ValCh<PaletteCellConfig> > m_paletteCellsConfigs;
Expand Down
9 changes: 9 additions & 0 deletions src/palette/internal/paletteprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ void PaletteProvider::init()
configuration()->isSingleClickToOpenPalette().ch.onReceive(this, [this](bool) {
emit isSingleClickToOpenPaletteChanged();
});

configuration()->isPaletteDragEnabled().ch.onReceive(this, [this](bool) {
emit isPaletteDragEnabledChanged();
});
}

void PaletteProvider::setSearching(bool searching)
Expand Down Expand Up @@ -646,6 +650,11 @@ bool PaletteProvider::isSingleClickToOpenPalette() const
return configuration()->isSingleClickToOpenPalette().val;
}

bool PaletteProvider::isPaletteDragEnabled() const
{
return configuration()->isPaletteDragEnabled().val;
}

QAbstractItemModel* PaletteProvider::mainPaletteModel()
{
if (m_isSearching) {
Expand Down
3 changes: 3 additions & 0 deletions src/palette/internal/paletteprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -261,13 +262,15 @@ class PaletteProvider : public QObject, public IPaletteProvider, public muse::as

bool isSinglePalette() const;
bool isSingleClickToOpenPalette() const;
bool isPaletteDragEnabled() const;

signals:
void userPaletteChanged();
void mainPaletteChanged();

void isSinglePaletteChanged();
void isSingleClickToOpenPaletteChanged();
void isPaletteDragEnabledChanged();

private slots:
void notifyAboutUserPaletteChanged()
Expand Down
3 changes: 3 additions & 0 deletions src/palette/ipaletteconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class IPaletteConfiguration : MODULE_EXPORT_INTERFACE
virtual muse::ValCh<bool> isSingleClickToOpenPalette() const = 0;
virtual void setIsSingleClickToOpenPalette(bool isSingleClick) = 0;

virtual muse::ValCh<bool> isPaletteDragEnabled() const = 0;
virtual void setIsPaletteDragEnabled(bool enabled) = 0;

virtual QColor elementsBackgroundColor() const = 0;
virtual QColor elementsColor() const = 0;
virtual QColor gridColor() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/palette/qml/MuseScore/Palette/internal/PaletteTree.qml
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,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
Expand Down
34 changes: 34 additions & 0 deletions src/palette/view/palettespanelcontextmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -48,6 +49,7 @@ void PalettesPanelContextMenuModel::load()
MenuItemList items {
createIsSingleClickToOpenPaletteItem(),
createIsSinglePaletteItem(),
createIsDragEnabledItem(),
makeSeparator(),
createExpandCollapseAllItem(false),
createExpandCollapseAllItem(true),
Expand Down Expand Up @@ -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 of palettes");
action.code = TOGGLE_PALETTE_DRAG;
action.checkable = Checkable::Yes;
item->setAction(action);

ValCh<bool> 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);
Expand Down
1 change: 1 addition & 0 deletions src/palette/view/palettespanelcontextmenumodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
Expand Down
9 changes: 9 additions & 0 deletions src/stubs/palette/paletteconfigurationstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ void PaletteConfigurationStub::setIsSingleClickToOpenPalette(bool)
{
}

ValCh<bool> PaletteConfigurationStub::isPaletteDragEnabled() const
{
return ValCh<bool>();
}

void PaletteConfigurationStub::setIsPaletteDragEnabled(bool)
{
}

QColor PaletteConfigurationStub::elementsBackgroundColor() const
{
return QColor();
Expand Down
3 changes: 3 additions & 0 deletions src/stubs/palette/paletteconfigurationstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class PaletteConfigurationStub : public IPaletteConfiguration
muse::ValCh<bool> isSingleClickToOpenPalette() const override;
void setIsSingleClickToOpenPalette(bool isSingleClick) override;

muse::ValCh<bool> isPaletteDragEnabled() const override;
void setIsPaletteDragEnabled(bool isSingleClick) override;

QColor elementsBackgroundColor() const override;
QColor elementsColor() const override;
QColor gridColor() const override;
Expand Down

0 comments on commit 9f07d94

Please sign in to comment.