Skip to content

Commit

Permalink
Minor refactor - rename drag to swap
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Nov 28, 2024
1 parent fb5cfc7 commit 3c00846
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
42 changes: 21 additions & 21 deletions src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Item {
readonly property int numColumns: model.numColumns
readonly property int spacing: 12

property Item draggedPad: null
property Item swapOriginPad: null

QtObject {
id: gridPrv
Expand Down Expand Up @@ -245,10 +245,10 @@ Item {
panelMode: percModel.currentPanelMode
useNotationPreview: percModel.useNotationPreview

// When dragging, only show the outline for the dragged pad and the drag target...
// When swapping, only show the outline for the swap origin and the swap target...
showEditOutline: percModel.currentPanelMode === PanelMode.EDIT_LAYOUT
&& (!Boolean(padGrid.draggedPad) || padGrid.draggedPad === pad || pad.containsDrag)
showOriginBackground: pad.containsDrag || pad === padGrid.draggedPad
&& (!Boolean(padGrid.swapOriginPad) || padGrid.swapOriginPad === pad || pad.containsDrag)
showOriginBackground: pad.containsDrag || pad === padGrid.swapOriginPad

dragParent: root

Expand All @@ -257,20 +257,20 @@ Item {
padNavigationCtrl.panel: padsNavPanel
footerNavigationCtrl.panel: padFootersNavPanel

onDragStarted: {
padGrid.draggedPad = pad
padGrid.model.startDrag(index)
onStartPadSwapRequested: {
padGrid.swapOriginPad = pad
padGrid.model.startPadSwap(index)
}

onDropped: function(dropEvent) {
padGrid.draggedPad = null
padGrid.model.endDrag(index)
padGrid.swapOriginPad = null
padGrid.model.endPadSwap(index)
dropEvent.accepted = true
}

onDragCancelled: {
padGrid.draggedPad = null
padGrid.model.endDrag(-1)
onCancelPadSwapRequested: {
padGrid.swapOriginPad = null
padGrid.model.endPadSwap(-1)
}

onHasActiveControlChanged: {
Expand All @@ -282,22 +282,22 @@ Item {
}

states: [
// If this is the drop target - move the draggable area to the origin of the dragged pad (preview the drop)
// If this is the swap target - move the swappable area to the swap origin (preview the swap)
State {
name: "DROP_TARGET"
when: Boolean(padGrid.draggedPad) && pad.containsDrag && padGrid.draggedPad !== pad
name: "SWAP_TARGET"
when: Boolean(padGrid.swapOriginPad) && pad.containsDrag && padGrid.swapOriginPad !== pad
ParentChange {
target: pad.draggableArea
parent: padGrid.draggedPad
target: pad.swappableArea
parent: padGrid.swapOriginPad
}
AnchorChanges {
target: pad.draggableArea
anchors.verticalCenter: padGrid.draggedPad.verticalCenter
anchors.horizontalCenter: padGrid.draggedPad.horizontalCenter
target: pad.swappableArea
anchors.verticalCenter: padGrid.swapOriginPad.verticalCenter
anchors.horizontalCenter: padGrid.swapOriginPad.horizontalCenter
}
// Origin background not needed for the dragged pad when a preview is taking place...
PropertyChanges {
target: padGrid.draggedPad
target: padGrid.swapOriginPad
showOriginBackground: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DropArea {

property alias totalBorderWidth: padLoader.anchors.margins
property alias showOriginBackground: originBackground.visible
property alias draggableArea: draggableArea
property alias swappableArea: swappableArea

property int navigationRow: -1
property int navigationColumn: -1
Expand All @@ -49,8 +49,8 @@ DropArea {
readonly property bool hasActiveControl: padNavCtrl.active || footerNavCtrl.active

property var dragParent: null
signal dragStarted()
signal dragCancelled()
signal startPadSwapRequested()
signal cancelPadSwapRequested()

QtObject {
id: prv
Expand Down Expand Up @@ -119,7 +119,7 @@ DropArea {
}

Rectangle {
id: draggableArea
id: swappableArea

// Protrudes slightly from behind the components in the loader to produce the edit mode "border with gap" effect
width: root.width
Expand All @@ -135,18 +135,18 @@ DropArea {
DragHandler {
id: dragHandler

target: draggableArea
target: swappableArea
enabled: Boolean(root.padModel) && root.panelMode === PanelMode.EDIT_LAYOUT

dragThreshold: 0 // prevents the flickable from stealing drag events

onActiveChanged: {
if (dragHandler.active) {
root.dragStarted()
root.startPadSwapRequested()
return
}
if (!draggableArea.Drag.drop()) {
root.dragCancelled()
if (!swappableArea.Drag.drop()) {
root.cancelPadSwapRequested()
}
}
}
Expand All @@ -161,15 +161,15 @@ DropArea {

anchors.fill: parent
// Defined as 1 in the spec, but causes some aliasing in practice...
anchors.margins: 2 + draggableArea.border.width
anchors.margins: 2 + swappableArea.border.width

// Can't simply use clip as this won't take into account radius...
layer.enabled: ui.isEffectsAllowed
layer.effect: EffectOpacityMask {
maskSource: Rectangle {
width: padLoader.width
height: padLoader.height
radius: draggableArea.radius - padLoader.anchors.margins
radius: swappableArea.radius - padLoader.anchors.margins
}
}

Expand All @@ -185,7 +185,7 @@ DropArea {

footerHeight: prv.footerHeight

dragActive: dragHandler.active
padSwapActive: dragHandler.active
}
}

Expand Down Expand Up @@ -228,11 +228,11 @@ DropArea {
name: "DRAGGED"
when: dragHandler.active
ParentChange {
target: draggableArea
target: swappableArea
parent: root.dragParent
}
AnchorChanges {
target: draggableArea
target: swappableArea
anchors.horizontalCenter: undefined
anchors.verticalCenter: undefined
}
Expand All @@ -243,7 +243,7 @@ DropArea {
name: "DROPPED"
when: !dragHandler.active
ParentChange {
target: draggableArea
target: swappableArea
parent: root
}
}
Expand All @@ -255,19 +255,19 @@ DropArea {

anchors.fill: parent

radius: draggableArea.radius
radius: swappableArea.radius

border.color: draggableArea.border.color
border.width: draggableArea.border.width
border.color: swappableArea.border.color
border.width: swappableArea.border.width

color: draggableArea.color
color: swappableArea.color

Rectangle {
id: originBackgroundFill

anchors.fill: parent
anchors.margins: padLoader.anchors.margins
radius: draggableArea.radius - originBackgroundFill.anchors.margins
radius: swappableArea.radius - originBackgroundFill.anchors.margins

color: root.containsDrag ? ui.theme.buttonColor : prv.enabledBackgroundColor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Column {

property alias footerHeight: footerArea.height

property bool dragActive: false
property bool padSwapActive: false

Rectangle {
id: mainContentArea
Expand Down Expand Up @@ -87,15 +87,15 @@ Column {
states: [
State {
name: "MOUSE_HOVERED"
when: mouseArea.containsMouse && !mouseArea.pressed && !root.dragActive
when: mouseArea.containsMouse && !mouseArea.pressed && !root.padSwapActive
PropertyChanges {
target: mainContentArea
color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityHover)
}
},
State {
name: "MOUSE_HIT"
when: mouseArea.pressed || root.dragActive
when: mouseArea.pressed || root.padSwapActive
PropertyChanges {
target: mainContentArea
color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityHit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ bool PercussionPanelPadListModel::rowIsEmpty(int row) const
return numEmptySlotsAtRow(row) == NUM_COLUMNS;
}

void PercussionPanelPadListModel::startDrag(int startIndex)
void PercussionPanelPadListModel::startPadSwap(int startIndex)
{
m_dragStartIndex = startIndex;
m_padSwapStartIndex = startIndex;
}

void PercussionPanelPadListModel::endDrag(int endIndex)
void PercussionPanelPadListModel::endPadSwap(int endIndex)
{
if (indexIsValid(m_dragStartIndex) && indexIsValid(endIndex)) {
movePad(m_dragStartIndex, endIndex);
if (indexIsValid(m_padSwapStartIndex) && indexIsValid(endIndex)) {
movePad(m_padSwapStartIndex, endIndex);
} else {
emit layoutChanged();
}
m_dragStartIndex = -1;
m_padSwapStartIndex = -1;
}

void PercussionPanelPadListModel::setDrumset(const engraving::Drumset* drumset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class PercussionPanelPadListModel : public QAbstractListModel, public muse::asyn

Q_INVOKABLE bool rowIsEmpty(int row) const;

Q_INVOKABLE void startDrag(int startIndex);
Q_INVOKABLE void endDrag(int endIndex);
Q_INVOKABLE void startPadSwap(int startIndex);
Q_INVOKABLE void endPadSwap(int endIndex);

bool hasActivePads() const { return m_drumset; }

Expand Down Expand Up @@ -97,7 +97,7 @@ class PercussionPanelPadListModel : public QAbstractListModel, public muse::asyn
engraving::Drumset* m_drumset = nullptr; //! NOTE: Pointer may be invalid, see PercussionPanelModel::setUpConnections
QList<PercussionPanelPadModel*> m_padModels;

int m_dragStartIndex = -1;
int m_padSwapStartIndex = -1;

muse::async::Notification m_hasActivePadsChanged;
muse::async::Channel<int /*pitch*/> m_triggeredChannel;
Expand Down

0 comments on commit 3c00846

Please sign in to comment.