| 1 |
import QtQuick |
| 2 |
|
| 3 |
import Muse.UiComponents |
| 4 |
|
| 5 |
import Audacity.ProjectScene |
| 6 |
|
| 7 |
Item { |
| 8 |
|
| 9 |
id: root |
| 10 |
|
| 11 |
property alias trackId: clipsModel.trackId |
| 12 |
property alias context: clipsModel.context |
| 13 |
property var canvas: null |
| 14 |
|
| 15 |
property bool isDataSelected: false |
| 16 |
property bool isTrackSelected: false |
| 17 |
property bool isStereo: clipsModel.isStereo |
| 18 |
property double channelHeightRatio: isStereo ? 0.5 : 1 |
| 19 |
|
| 20 |
signal interactionStarted() |
| 21 |
signal interactionEnded() |
| 22 |
// mouse position event is not propagated on overlapping mouse areas |
| 23 |
// so we are handling it manually |
| 24 |
signal trackItemMousePositionChanged(real x, real y) |
| 25 |
signal clipSelectedRequested() |
| 26 |
|
| 27 |
signal selectionDraged(var x1, var x2, var completed) |
| 28 |
signal seekToX(var x) |
| 29 |
|
| 30 |
height: trackViewState.trackHeight |
| 31 |
|
| 32 |
ClipsListModel { |
| 33 |
id: clipsModel |
| 34 |
|
| 35 |
onRequestClipTitleEdit: function(index){ |
| 36 |
repeator.itemAt(index).editTitle() |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
TracksViewStateModel { |
| 41 |
id: trackViewState |
| 42 |
trackId: root.trackId |
| 43 |
} |
| 44 |
|
| 45 |
Component.onCompleted: { |
| 46 |
trackViewState.init() |
| 47 |
clipsModel.init() |
| 48 |
} |
| 49 |
|
| 50 |
function changeClipTitle(index, newTitle) { |
| 51 |
clipsModel.changeClipTitle(index, newTitle) |
| 52 |
clipsModel.resetSelectedClip() |
| 53 |
} |
| 54 |
|
| 55 |
Item { |
| 56 |
id: clipsContaner |
| 57 |
anchors.fill: parent |
| 58 |
anchors.bottomMargin: sep.height |
| 59 |
z: 1 |
| 60 |
|
| 61 |
Repeater { |
| 62 |
id: repeator |
| 63 |
|
| 64 |
model: clipsModel |
| 65 |
|
| 66 |
delegate: Loader { |
| 67 |
property QtObject clipItem: model.item |
| 68 |
|
| 69 |
height: parent.height |
| 70 |
width: Math.max(3, clipItem.width) |
| 71 |
x: clipItem.x |
| 72 |
|
| 73 |
asynchronous: true |
| 74 |
|
| 75 |
sourceComponent: { |
| 76 |
if ((clipItem.x + clipItem.width) < (0 - clipsModel.cacheBufferPx)) { |
| 77 |
return null |
| 78 |
} |
| 79 |
|
| 80 |
if (clipItem.x > (clipsContaner.width + clipsModel.cacheBufferPx)) { |
| 81 |
return null |
| 82 |
} |
| 83 |
|
| 84 |
//! NOTE This optimization is disabled, it is probably not needed, |
| 85 |
// and if it needs to be enabled, it should be modified, add handlers |
| 86 |
|
| 87 |
// if (clipItem.width < 24) { |
| 88 |
// return clipSmallComp |
| 89 |
// } |
| 90 |
|
| 91 |
return clipComp |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
Component { |
| 97 |
id: clipSmallComp |
| 98 |
|
| 99 |
ClipItemSmall { |
| 100 |
|
| 101 |
clipColor: clipItem.color |
| 102 |
collapsed: trackViewState.isTrackCollapsed |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
Component { |
| 107 |
id: clipComp |
| 108 |
|
| 109 |
ClipItem { |
| 110 |
|
| 111 |
context: root.context |
| 112 |
canvas: root.canvas |
| 113 |
title: clipItem.title |
| 114 |
clipColor: clipItem.color |
| 115 |
clipKey: clipItem.key |
| 116 |
clipTime: clipItem.time |
| 117 |
clipSelected: clipItem.selected |
| 118 |
isDataSelected: root.isDataSelected |
| 119 |
selectionStart: root.context.selectionStartPosition < clipItem.x ? 0 : root.context.selectionStartPosition - clipItem.x |
| 120 |
selectionWidth: root.context.selectionStartPosition < clipItem.x ? |
| 121 |
root.context.selectionEndPosition - clipItem.x : root.context.selectionEndPosition - root.context.selectionStartPosition |
| 122 |
leftVisibleMargin: clipItem.leftVisibleMargin |
| 123 |
rightVisibleMargin: clipItem.rightVisibleMargin |
| 124 |
collapsed: trackViewState.isTrackCollapsed |
| 125 |
channelHeightRatio: root.channelHeightRatio |
| 126 |
showChannelSplitter: isStereo |
| 127 |
|
| 128 |
onClipStartEditRequested: function() { |
| 129 |
clipsModel.startEditClip(clipItem.key) |
| 130 |
} |
| 131 |
|
| 132 |
onClipEndEditRequested: function() { |
| 133 |
clipsModel.endEditClip(clipItem.key) |
| 134 |
} |
| 135 |
|
| 136 |
onClipMoveRequested: function(completed) { |
| 137 |
clipsModel.moveClip(clipItem.key, completed) |
| 138 |
} |
| 139 |
|
| 140 |
onClipLeftTrimRequested: function(completed) { |
| 141 |
clipsModel.trimLeftClip(clipItem.key, completed) |
| 142 |
} |
| 143 |
|
| 144 |
onClipRightTrimRequested: function(completed) { |
| 145 |
clipsModel.trimRightClip(clipItem.key, completed) |
| 146 |
} |
| 147 |
|
| 148 |
onClipItemMousePositionChanged: function(xWithinClip, yWithinClip) { |
| 149 |
var yWithinTrack = yWithinClip |
| 150 |
var xWithinTrack = xWithinClip + clipItem.x |
| 151 |
trackItemMousePositionChanged(xWithinTrack, yWithinTrack) |
| 152 |
} |
| 153 |
|
| 154 |
onRequestSelected: { |
| 155 |
clipsModel.selectClip(clipItem.key) |
| 156 |
root.clipSelectedRequested() |
| 157 |
} |
| 158 |
|
| 159 |
onTitleEditStarted: { |
| 160 |
clipsModel.selectClip(clipItem.key) |
| 161 |
} |
| 162 |
|
| 163 |
onTitleEditAccepted: function(newTitle) { |
| 164 |
root.changeClipTitle(clipItem.key, newTitle) |
| 165 |
} |
| 166 |
|
| 167 |
onTitleEditCanceled: { |
| 168 |
clipsModel.resetSelectedClip() |
| 169 |
} |
| 170 |
|
| 171 |
onRatioChanged: function (ratio) { |
| 172 |
root.channelHeightRatio = ratio |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
// this one is transparent, it's on top of the clips |
| 179 |
// to have extend/reduce selection area handles |
| 180 |
ClipsSelection { |
| 181 |
id: clipsSelection |
| 182 |
|
| 183 |
isDataSelected: root.isDataSelected |
| 184 |
context: root.context |
| 185 |
|
| 186 |
anchors.fill: parent |
| 187 |
z: 1 |
| 188 |
|
| 189 |
onSelectionDraged: function(x1, x2, completed) { |
| 190 |
root.selectionDraged(x1, x2, completed) |
| 191 |
if (completed) { |
| 192 |
root.seekToX(Math.min(x1, x2)) |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
// this one is drawn below the clips |
| 198 |
Rectangle { |
| 199 |
id: clipSelectionRectangle |
| 200 |
|
| 201 |
x: root.context.selectionStartPosition |
| 202 |
width: root.context.selectionEndPosition - x |
| 203 |
|
| 204 |
anchors.top: root.top |
| 205 |
anchors.bottom: root.bottom |
| 206 |
|
| 207 |
visible: root.isDataSelected |
| 208 |
color: "#ABE7FF" |
| 209 |
opacity: 0.3 |
| 210 |
} |
| 211 |
|
| 212 |
Rectangle { |
| 213 |
id: selectedTrackHighlight |
| 214 |
z: 0 |
| 215 |
anchors.fill: parent |
| 216 |
color: "#FFFFFF" |
| 217 |
opacity: 0.05 |
| 218 |
visible: root.isDataSelected || root.isTrackSelected |
| 219 |
} |
| 220 |
|
| 221 |
MouseArea { |
| 222 |
id: dragArea |
| 223 |
|
| 224 |
anchors.left: parent.left |
| 225 |
anchors.right: parent.right |
| 226 |
anchors.bottom: parent.bottom |
| 227 |
height: 4 |
| 228 |
|
| 229 |
cursorShape: Qt.SizeVerCursor |
| 230 |
|
| 231 |
onPressed: { |
| 232 |
root.interactionStarted() |
| 233 |
} |
| 234 |
|
| 235 |
onPositionChanged: function(mouse) { |
| 236 |
mouse.accepted = true |
| 237 |
trackViewState.changeTrackHeight(mouse.y) |
| 238 |
} |
| 239 |
|
| 240 |
onReleased: { |
| 241 |
root.interactionEnded() |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
ChannelSplitter { |
| 246 |
id: channelSplitter |
| 247 |
|
| 248 |
anchors.fill: parent |
| 249 |
anchors.topMargin: trackViewState.isTrackCollapsed ? 1 : 21 |
| 250 |
anchors.bottomMargin: 3 |
| 251 |
|
| 252 |
channelHeightRatio: root.channelHeightRatio |
| 253 |
color: "#FFFFFF" |
| 254 |
opacity: 0.05 |
| 255 |
visible: isStereo |
| 256 |
|
| 257 |
onRatioChanged: function(ratio) { |
| 258 |
root.channelHeightRatio = ratio |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
SeparatorLine { |
| 263 |
id: sep |
| 264 |
color: "#FFFFFF" |
| 265 |
opacity: 0.1 |
| 266 |
anchors.bottom: parent.bottom |
| 267 |
thickness: 2 |
| 268 |
} |
| 269 |
} |