-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
ParamsGridView.qml
136 lines (103 loc) · 3.87 KB
/
ParamsGridView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2024 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 MuseScore.Ui 1.0
import MuseScore.UiComponents 1.0
Column {
id: root
property alias title: titleLabel.text
property alias model: repeaterPreset.model
property var selectionModel: null
property bool isTruncated: flickable.contentHeight > prv.flickableMaxHeight
property bool needAddPaddingForScrollbar: false
property NavigationPanel navigationPanel: NavigationPanel {
name: "SoundFlagParams" + title
direction: NavigationPanel.Vertical
accessible.name: title
}
signal toggleParamRequested(string paramCode)
spacing: 8
QtObject {
id: prv
property int flickableMaxHeight: 132
}
StyledTextLabel {
id: titleLabel
width: parent.width
horizontalAlignment: Text.AlignLeft
wrapMode: Text.Wrap
}
StyledFlickable {
id: flickable
width: parent.width
height: Math.min(contentHeight, prv.flickableMaxHeight)
contentHeight: gridView.implicitHeight
ScrollBar.vertical: StyledScrollBar {
id: scrollBar
padding: 0
policy: root.isTruncated ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded
}
GridLayout {
id: gridView
width: parent.width - (root.needAddPaddingForScrollbar ? scrollBar.width + 8 : 0)
columns: 2
rows: Math.ceil(root.model.length / 2)
columnSpacing: 4
rowSpacing: 4
Repeater {
id: repeaterPreset
width: parent.width
height: parent.height
FlatButton {
id: button
Layout.preferredWidth: (gridView.width - gridView.rowSpacing) / 2
Layout.preferredHeight: implicitHeight
text: modelData["name"]
accentButton: root.selectionModel.indexOf(modelData["code"]) !== -1
drawFocusBorderInsideRect: true
navigation.name: "Param" + index
navigation.panel: root.navigationPanel
navigation.row: index
navigation.column: 1
navigation.onHighlightChanged: {
if (navigation.highlight) {
var pos = button.mapToItem(gridView, 0, 0)
var rect = Qt.rect(pos.x, pos.y, button.width, button.height)
Utils.ensureContentVisible(flickable, rect, 0)
}
}
accessible.name: text + "; " + (accentButton ? qsTrc("global", "On") : qsTrc("global", "Off"))
onClicked: {
root.toggleParamRequested(modelData["code"])
}
contentItem: StyledTextLabel {
width: button.width - 24 // 12px padding on each side
text: button.text
font: ui.theme.bodyFont
}
}
}
}
}
}