| 1 |
import QtQuick |
| 2 |
|
| 3 |
import Muse.Ui |
| 4 |
import Muse.UiComponents |
| 5 |
import Muse.GraphicalEffects |
| 6 |
|
| 7 |
import Audacity.ProjectScene |
| 8 |
|
| 9 |
Rectangle { |
| 10 |
|
| 11 |
id: root |
| 12 |
|
| 13 |
property alias context: waveView.context |
| 14 |
property alias clipKey: waveView.clipKey |
| 15 |
property alias clipTime: waveView.clipTime |
| 16 |
property alias title: titleLabel.text |
| 17 |
property alias showChannelSplitter: channelSplitter.visible |
| 18 |
property alias channelHeightRatio: channelSplitter.channelHeightRatio |
| 19 |
property var canvas: null |
| 20 |
property color clipColor: "#677CE4" |
| 21 |
property bool clipSelected: false |
| 22 |
property bool isDataSelected: false |
| 23 |
property int selectionStart: 0 |
| 24 |
property int selectionWidth: 0 |
| 25 |
|
| 26 |
property real leftVisibleMargin: 0 |
| 27 |
property real rightVisibleMargin: 0 |
| 28 |
|
| 29 |
property bool collapsed: false |
| 30 |
|
| 31 |
signal clipStartEditRequested() |
| 32 |
signal clipEndEditRequested() |
| 33 |
|
| 34 |
signal clipMoveRequested(bool completed) |
| 35 |
signal clipLeftTrimRequested(bool completed) |
| 36 |
signal clipRightTrimRequested(bool completed) |
| 37 |
|
| 38 |
signal requestSelected() |
| 39 |
signal ratioChanged(double val) |
| 40 |
|
| 41 |
signal titleEditStarted() |
| 42 |
signal titleEditAccepted(var newTitle) |
| 43 |
signal titleEditCanceled() |
| 44 |
|
| 45 |
// mouse position event is not propagated on overlapping mouse areas |
| 46 |
// so we are handling it manually |
| 47 |
signal clipItemMousePositionChanged(real x, real y) |
| 48 |
|
| 49 |
radius: 4 |
| 50 |
color: clipSelected ? "white" : clipColor |
| 51 |
border.color: "#000000" |
| 52 |
|
| 53 |
property int borderWidth: 1 |
| 54 |
property bool hover: hoverArea.containsMouse || headerDragArea.containsMouse |
| 55 |
|
| 56 |
function editTitle() { |
| 57 |
editLoader.edit(titleLabel.text) |
| 58 |
} |
| 59 |
|
| 60 |
function acceptEditTitle(newTitle) { |
| 61 |
Qt.callLater(root.titleEditAccepted, newTitle) |
| 62 |
} |
| 63 |
|
| 64 |
ClipContextMenuModel { |
| 65 |
id: contextMenuModel |
| 66 |
clipKey: root.clipKey |
| 67 |
} |
| 68 |
|
| 69 |
Component.onCompleted: { |
| 70 |
contextMenuModel.load() |
| 71 |
} |
| 72 |
|
| 73 |
ContextMenuLoader { |
| 74 |
id: contextMenuLoader |
| 75 |
|
| 76 |
onHandleMenuItem: function(itemId) { |
| 77 |
contextMenuModel.handleMenuItem(itemId) |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
MouseArea { |
| 82 |
id: hoverArea |
| 83 |
anchors.fill: parent |
| 84 |
acceptedButtons: Qt.RightButton |
| 85 |
hoverEnabled: true |
| 86 |
|
| 87 |
onClicked: function(e) { |
| 88 |
contextMenuLoader.show(Qt.point(e.x, e.y), contextMenuModel.items) |
| 89 |
root.requestSelected() |
| 90 |
} |
| 91 |
|
| 92 |
onPositionChanged: { |
| 93 |
clipItemMousePositionChanged(mouseX, mouseY) |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
Rectangle { |
| 98 |
id: inner |
| 99 |
|
| 100 |
anchors.fill: parent |
| 101 |
anchors.margins: 1 |
| 102 |
|
| 103 |
layer.enabled: true |
| 104 |
layer.effect: EffectOpacityMask { |
| 105 |
maskSource: RoundedRectangle { |
| 106 |
width: inner.width |
| 107 |
height: inner.height |
| 108 |
radius: root.radius |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
Rectangle { |
| 113 |
id: header |
| 114 |
anchors.top: parent.top |
| 115 |
anchors.left: parent.left |
| 116 |
anchors.right: parent.right |
| 117 |
|
| 118 |
height: 20 |
| 119 |
z: 2 |
| 120 |
|
| 121 |
visible: !root.collapsed || root.hover |
| 122 |
|
| 123 |
Rectangle { |
| 124 |
id: headerSelectionRectangle |
| 125 |
|
| 126 |
x: root.selectionStart |
| 127 |
z: 0 // Ensure this is below the header content |
| 128 |
width: Math.min(root.selectionWidth, header.width) |
| 129 |
|
| 130 |
anchors.top: header.top |
| 131 |
anchors.bottom: header.bottom |
| 132 |
|
| 133 |
color: waveView.transformColor(clipColor) |
| 134 |
visible: root.isDataSelected |
| 135 |
} |
| 136 |
|
| 137 |
MouseArea { |
| 138 |
id: headerDragArea |
| 139 |
anchors.fill: parent |
| 140 |
|
| 141 |
hoverEnabled: true |
| 142 |
cursorShape: Qt.OpenHandCursor |
| 143 |
|
| 144 |
property bool moveActive: false |
| 145 |
|
| 146 |
onPositionChanged: function(e) { |
| 147 |
root.clipItemMousePositionChanged(e.x, e.y) |
| 148 |
|
| 149 |
if (pressed) { |
| 150 |
root.clipMoveRequested(false) |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
onPressed: function(e) { |
| 155 |
root.requestSelected() |
| 156 |
|
| 157 |
root.clipStartEditRequested() |
| 158 |
} |
| 159 |
|
| 160 |
onReleased: function(e) { |
| 161 |
root.clipMoveRequested(true) |
| 162 |
|
| 163 |
root.clipEndEditRequested() |
| 164 |
} |
| 165 |
|
| 166 |
onDoubleClicked: root.editTitle() |
| 167 |
} |
| 168 |
|
| 169 |
StyledTextLabel { |
| 170 |
id: titleLabel |
| 171 |
anchors.top: parent.top |
| 172 |
anchors.bottom: parent.bottom |
| 173 |
anchors.left: parent.left |
| 174 |
anchors.right: menuBtn.left |
| 175 |
anchors.leftMargin: root.leftVisibleMargin + 4 |
| 176 |
anchors.rightMargin: 8 |
| 177 |
horizontalAlignment: Qt.AlignLeft |
| 178 |
} |
| 179 |
|
| 180 |
Loader { |
| 181 |
id: editLoader |
| 182 |
|
| 183 |
anchors.fill: titleLabel |
| 184 |
|
| 185 |
property bool isEditState: false |
| 186 |
sourceComponent: editLoader.isEditState ? titleEditComp : null |
| 187 |
|
| 188 |
function edit(text) { |
| 189 |
root.titleEditStarted() |
| 190 |
editLoader.isEditState = true |
| 191 |
editLoader.item.currentText = text |
| 192 |
editLoader.item.newTitle = text |
| 193 |
editLoader.item.visible = true |
| 194 |
editLoader.item.ensureActiveFocus() |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
Component { |
| 199 |
id: titleEditComp |
| 200 |
TextInputField { |
| 201 |
id: titleEdit |
| 202 |
|
| 203 |
property string newTitle: "" |
| 204 |
|
| 205 |
anchors.fill: parent |
| 206 |
background.color: header.color |
| 207 |
background.border.width: 0 |
| 208 |
background.radius: 0 |
| 209 |
inputField.color: titleLabel.color |
| 210 |
textSidePadding: 0 |
| 211 |
visible: false |
| 212 |
|
| 213 |
onTextChanged: function(text) { |
| 214 |
titleEdit.newTitle = text |
| 215 |
} |
| 216 |
|
| 217 |
onAccepted: { |
| 218 |
root.acceptEditTitle(titleEdit.newTitle) |
| 219 |
editLoader.isEditState = false |
| 220 |
} |
| 221 |
|
| 222 |
onEscaped: { |
| 223 |
editLoader.isEditState = false |
| 224 |
} |
| 225 |
|
| 226 |
onFocusChanged: { |
| 227 |
if (!titleEdit.focus) { |
| 228 |
titleEdit.visible = false |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
MenuButton { |
| 235 |
id: menuBtn |
| 236 |
width: 16 |
| 237 |
height: 16 |
| 238 |
anchors.right: parent.right |
| 239 |
anchors.rightMargin: 4 |
| 240 |
anchors.verticalCenter: parent.verticalCenter |
| 241 |
|
| 242 |
menuModel: contextMenuModel |
| 243 |
|
| 244 |
onHandleMenuItem: function(itemId) { |
| 245 |
contextMenuModel.handleMenuItem(itemId) |
| 246 |
} |
| 247 |
|
| 248 |
onClicked: { |
| 249 |
root.requestSelected() |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
WaveView { |
| 255 |
id: waveView |
| 256 |
anchors.top: (!root.collapsed && header.visible) ? header.bottom : parent.top |
| 257 |
anchors.left: parent.left |
| 258 |
anchors.right: parent.right |
| 259 |
anchors.bottom: parent.bottom |
| 260 |
|
| 261 |
channelHeightRatio: showChannelSplitter ? root.channelHeightRatio : 1 |
| 262 |
|
| 263 |
clipColor: root.clipColor |
| 264 |
clipSelected: root.clipSelected |
| 265 |
|
| 266 |
ChannelSplitter { |
| 267 |
id: channelSplitter |
| 268 |
|
| 269 |
anchors.fill: parent |
| 270 |
|
| 271 |
color: "#000000" |
| 272 |
opacity: 0.10 |
| 273 |
|
| 274 |
onRatioChanged: function (ratio) { |
| 275 |
root.ratioChanged(ratio) |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
Rectangle { |
| 281 |
id: selectionHighlight |
| 282 |
anchors.fill: parent |
| 283 |
border.width: 1 |
| 284 |
border.color: root.clipSelected ? "white" : "transparent" |
| 285 |
color: "transparent" |
| 286 |
radius: root.radius |
| 287 |
z: 2 |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
ClipHandles { |
| 292 |
id: clipHandles |
| 293 |
|
| 294 |
// +1 not to overlap with header |
| 295 |
y: header.height + 1 |
| 296 |
width: root.width |
| 297 |
handlesVisible: root.clipSelected |
| 298 |
canvas: root.canvas |
| 299 |
|
| 300 |
|
| 301 |
// make sure clip handles are visible on top of nearby clips |
| 302 |
onHandlesVisibleChanged: { |
| 303 |
if (handlesVisible) { |
| 304 |
root.parent.z = 1 |
| 305 |
} else { |
| 306 |
root.parent.z = 0 |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
onClipHandlesMousePositionChanged: function(xWithinClipHandles, yWithinClipHandles) { |
| 311 |
var xWithinClipItem = xWithinClipHandles |
| 312 |
var yWithinClipItem = header.height + 1 + yWithinClipHandles |
| 313 |
clipItemMousePositionChanged(xWithinClipItem, yWithinClipItem) |
| 314 |
} |
| 315 |
|
| 316 |
onClipStartEditRequested: function() { |
| 317 |
root.clipStartEditRequested() |
| 318 |
} |
| 319 |
|
| 320 |
onClipEndEditRequested: function() { |
| 321 |
root.clipEndEditRequested() |
| 322 |
} |
| 323 |
|
| 324 |
onTrimLeftRequested: function(completed) { |
| 325 |
root.clipLeftTrimRequested(completed) |
| 326 |
} |
| 327 |
|
| 328 |
onTrimRightRequested: function(completed) { |
| 329 |
root.clipRightTrimRequested(completed) |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
state: "NORMAL" |
| 334 |
states: [ |
| 335 |
State { |
| 336 |
name: "NORMAL" |
| 337 |
when: !root.clipSelected && !headerDragArea.containsMouse |
| 338 |
PropertyChanges { target: header; color: root.clipColor } |
| 339 |
PropertyChanges { target: titleLabel; color: "#000000"} |
| 340 |
PropertyChanges { target: menuBtn; iconColor: "#000000"} |
| 341 |
}, |
| 342 |
|
| 343 |
State { |
| 344 |
name: "SELECTED" |
| 345 |
when: root.clipSelected && !headerDragArea.containsMouse |
| 346 |
PropertyChanges { target: header; color: ui.blendColors("#ffffff", root.clipColor, 0.3) } |
| 347 |
PropertyChanges { target: titleLabel; color: "#000000" } |
| 348 |
PropertyChanges { target: menuBtn; iconColor: "#000000"} |
| 349 |
}, |
| 350 |
|
| 351 |
State { |
| 352 |
name: "NORMAL_HEADER_HOVERED" |
| 353 |
when: !root.clipSelected && headerDragArea.containsMouse |
| 354 |
PropertyChanges { target: header; color: ui.blendColors("#ffffff", root.clipColor, 0.8)} |
| 355 |
PropertyChanges { target: titleLabel; color: "#ffffff"} |
| 356 |
PropertyChanges { target: menuBtn; iconColor: "#ffffff"} |
| 357 |
}, |
| 358 |
|
| 359 |
State { |
| 360 |
name: "SELECTED_HEADER_HOVERED" |
| 361 |
when: root.clipSelected && headerDragArea.containsMouse |
| 362 |
PropertyChanges { target: header; color: ui.blendColors("#ffffff", root.clipColor, 0.2) } |
| 363 |
PropertyChanges { target: titleLabel; color: "#000000"} |
| 364 |
PropertyChanges { target: menuBtn; iconColor: "#000000"} |
| 365 |
} |
| 366 |
] |
| 367 |
} |