Skip to content

Commit

Permalink
Refactor partial tie popup menu
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Jan 10, 2025
1 parent 7a93c89 commit 6b26f3e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@
*/
import QtQuick 2.15

import Muse.Ui 1.0

Item {
id: container

// Useful for static context menus
property var items: []


property NavigationSection notationViewNavigationSection: null
property int navigationOrderStart: 0

property alias closeMenuOnSelection: contextMenuLoader.closeMenuOnSelection
property alias opensUpward: contextMenuLoader.opensUpward
property alias focusOnOpened: contextMenuLoader.focusOnOpened
property alias item: contextMenuLoader.item

signal handleMenuItem(string itemId)
signal opened()
signal closed()
Expand All @@ -47,13 +36,6 @@ Item {
width: 0
height: 0

onNotationViewNavigationSectionChanged: function() {
contextMenuLoader.item.navigationSectionOverride = container.notationViewNavigationSection
}
onNavigationOrderStartChanged: function() {
contextMenuLoader.item.navigationOrderStart = container.navigationOrderStart
}

function show(position: point, items) {
if (!items) {
items = container.items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
import QtQuick 2.15

import Muse.Ui 1.0
import Muse.UiComponents 1.0

import "internal"
Expand All @@ -38,13 +37,6 @@ Loader {
property StyledMenu menu: loader.item as StyledMenu
property Item menuAnchorItem: null
property bool hasSiblingMenus: false
property bool closeMenuOnSelection: true
property bool focusOnOpened: true

property NavigationSection notationViewNavigationSection: null
property int navigationOrderStart: 0

property bool opensUpward: false

property alias isMenuOpened: loader.active

Expand Down Expand Up @@ -73,9 +65,7 @@ Loader {
accessibleName: loader.accessibleName

onHandleMenuItem: function(itemId) {
if (loader.closeMenuOnSelection) {
itemMenu.close()
}
itemMenu.close()
Qt.callLater(loader.handleMenuItem, itemId)
}

Expand All @@ -92,9 +82,7 @@ Loader {
}

onOpened: {
if (focusOnOpened) {
focusOnOpenedMenuTimer.start()
}
focusOnOpenedMenuTimer.start()
}
}

Expand Down Expand Up @@ -145,8 +133,6 @@ Loader {

menu.closeSubMenu()

menu.setOpensUpward(loader.opensUpward)

if (x !== -1) {
menu.x = x
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ MenuView {

property alias model: view.model

property NavigationSection navigationSectionOverride: null
property int navigationOrderStart: 0

property int preferredAlign: Qt.AlignRight // Left, HCenter, Right
property bool hasSiblingMenus: loader.hasSiblingMenus

Expand Down Expand Up @@ -137,9 +134,9 @@ MenuView {

property NavigationPanel navigationPanel: NavigationPanel {
name: "StyledMenu"
section: content.navigationSection
direction: NavigationPanel.Vertical
section: root.navigationSectionOverride ?? content.navigationSection
order: root.navigationOrderStart
order: 1

accessible.name: root.accessibleName

Expand Down
1 change: 1 addition & 0 deletions src/notation/notationscene.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
<file>qml/MuseScore/NotationScene/internal/EditStyle/IconAndTextButtonSelector.qml</file>
<file>qml/MuseScore/NotationScene/PercussionPanelPadSwapDialog.qml</file>
<file>qml/MuseScore/NotationScene/internal/PartialTiePopup.qml</file>
<file>qml/MuseScore/NotationScene/internal/PartialTieMenuRowItem.qml</file>
</qresource>
</RCC>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2025 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15

import Muse.Ui 1.0
import Muse.UiComponents 1.0
import MuseScore.NotationScene 1.0

ListItemBlank {
function calculateWidth() {
let result = 0

result += rowLayout.anchors.leftMargin

result += Math.ceil(checkIcon.Layout.preferredWidth)
result += rowLayout.spacing

result += Math.ceil(titleLabel.implicitWidth)
result += rowLayout.spacing
result += rowLayout.anchors.rightMargin

return result
}

RowLayout {
id: rowLayout

anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 12
anchors.right: parent.right
anchors.rightMargin: 12

spacing: 12

StyledIconLabel {
id: checkIcon
Layout.alignment: Qt.AlignLeft
Layout.preferredWidth: 16
iconCode: modelData.checked ? IconCode.TICK_RIGHT_ANGLE : IconCode.NONE
}

StyledTextLabel {
id: titleLabel
Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft

text: modelData.title

textFormat: Text.RichText
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2022 MuseScore BVBA and others
* Copyright (C) 2025 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
Expand All @@ -32,6 +32,9 @@ StyledPopupView {
id: root
margins: 0

contentWidth: content.width
contentHeight: content.height

property alias notationViewNavigationSection: partialTieNavPanel.section
property alias navigationOrderStart: partialTieNavPanel.order
readonly property alias navigationOrderEnd: partialTieNavPanel.order
Expand All @@ -40,39 +43,31 @@ StyledPopupView {

showArrow: false

onOpened: {
tieMenuLoader.show(Qt.point(0, 0))
}

onClosed: {
tieMenuLoader.close()
partialTiePopupModel.onClosed()
}

signal elementRectChanged(var elementRect)

function updatePosition() {
const opensUp = partialTiePopupModel.tieDirection
const popupHeight = tieMenuLoader.item.height + root.margins * 2 + root.padding * 2
const popupHeight = content.height + root.margins * 2 + root.padding * 2
root.x = partialTiePopupModel.dialogPosition.x - root.parent.x
root.y = partialTiePopupModel.dialogPosition.y - root.parent.y - (opensUp ? popupHeight : 0)
root.setOpensUpward(opensUp)
}

contentWidth: tieMenuLoader.width
contentHeight: tieMenuLoader.childrenRect.height

ContextMenuLoader {
id: tieMenuLoader
closeMenuOnSelection: false
focusOnOpened: false
opensUpward: root.opensUpward
tieMenuList.calculateWidth()
}

items: partialTiePopupModel.items
Component.onCompleted: {
partialTiePopupModel.init()
}

onHandleMenuItem: function(itemId) {
partialTiePopupModel.toggleItemChecked(itemId)
}
Column {
id: content
width: tieMenuList.width
height: tieMenuList.height
spacing: 0

PartialTiePopupModel {
id: partialTiePopupModel
Expand All @@ -82,26 +77,54 @@ StyledPopupView {
}

onItemsChanged: function() {
tieMenuLoader.show(Qt.point(0, 0))
tieMenuList.model = partialTiePopupModel.items
}
}

Component.onCompleted: {
partialTiePopupModel.init()
}

NavigationPanel {
id: partialTieNavPanel
name: "PartialTieMenu"
direction: NavigationPanel.Vertical
accessible.name: qsTrc("notation", "Partial tie menu items")
}

StyledListView {
id: tieMenuList

property int itemHeight: 32

implicitWidth: contentItem.childrenRect.width
height: itemHeight * count

spacing: 0
arrowControlsAvailable: false

onSectionChanged: function() {
tieMenuLoader.notationViewNavigationSection = section
model: partialTiePopupModel.items

visible: true

function calculateWidth() {
var result = 0
for (var item in tieMenuList.contentItem.children) {
var row = tieMenuList.contentItem.children[item];
if (!(row instanceof ListItemBlank)) {
continue
}
result = Math.max(result, tieMenuList.contentItem.children[item].calculateWidth())
}

tieMenuList.width = result
}

onOrderChanged: function() {
tieMenuLoader.navigationOrderStart = order
delegate: PartialTieMenuRowItem {
implicitHeight: tieMenuList.itemHeight
hoverHitColor: ui.theme.accentColor
anchors.left: parent ? parent.left : undefined
anchors.right: parent ? parent.right : undefined

onClicked: {
partialTiePopupModel.toggleItemChecked(modelData.id)
}
}
}
}
Expand Down

0 comments on commit 6b26f3e

Please sign in to comment.