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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
|
/*
* Copyright (C) 2013 Andrew Hayzen <ahayzen@gmail.com>
* Daniel Holm <d.holmen@gmail.com>
* Victor Thompson <victor.thompson@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* 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 <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtQuick.LocalStorage 2.0
import QtMultimedia 5.0
import Ubuntu.Components 0.1
import Ubuntu.Components.Popups 0.1
import "settings.js" as Settings
Rectangle {
id: musicToolbarContainer
color: "transparent"
height: fullHeight
state: "minimized"
width: parent.width
x: parent.x
// Properties storing the current page info
property var currentParentPage: null
property var currentPageStack: null
property var currentPage: null
property var currentTab: null
// The current mode of the controls
property string currentMode: currentPage === nowPlaying ? "full" : "expanded"
// Properties for the different heights
property int minimizedHeight: units.gu(0.5)
property int expandedHeight: units.gu(8)
property int fullHeight: units.gu(11)
property int mouseAreaOffset: units.gu(2)
// Properties and signals for the toolbar
property string cachedState: ""
property bool shown: false
property int transitionDuration: 100
// Shown/hide relevant child items depending on mode
onCurrentModeChanged: {
musicToolbarExpandedContainer.visible = currentMode !== "full"
musicToolbarFullContainer.visible = currentMode === "full"
// Update the container state if required
if (state !== "minimized")
{
state = currentMode
}
}
// Emit toolbarShownChanged signal when the toolbar is shown/hidden
onShownChanged: {
onToolbarShownChanged(shown, currentPage, currentTab);
musicToolbar.opened = shown;
}
states: [
// State for when the toolbar is hidden
State {
name: "hidden"
PropertyChanges {
target: musicToolbarContainer
y: parent.height
}
PropertyChanges {
target: musicToolbarMouseArea
anchors.topMargin: 0
}
PropertyChanges {
target: musicToolbarSmallProgressBackground
opacity: 0
}
PropertyChanges {
target: musicToolbarFullProgressMouseArea
visible: false
}
},
// State for when the toolbar is minimized
State {
name: "minimized"
PropertyChanges {
target: musicToolbarContainer
y: parent.height - minimizedHeight
}
PropertyChanges {
target: musicToolbarMouseArea
anchors.topMargin: -mouseAreaOffset // should allow drag from outside the item
}
PropertyChanges {
target: musicToolbarSmallProgressBackground
opacity: 1
}
PropertyChanges {
target: musicToolbarFullProgressMouseArea
visible: false
}
},
// State for when the toolbar is shown
State {
name: "expanded"
PropertyChanges {
target: musicToolbarContainer
y: parent.height - expandedHeight - minimizedHeight
}
PropertyChanges {
target: musicToolbarMouseArea
anchors.topMargin: 0
}
PropertyChanges {
target: musicToolbarSmallProgressBackground
opacity: 1
}
PropertyChanges {
target: musicToolbarFullProgressMouseArea
visible: false
}
},
// State for when the toolbar is shown on the now playing page
State {
name: "full"
PropertyChanges {
target: musicToolbarContainer
y: parent.height - fullHeight
}
PropertyChanges {
target: musicToolbarMouseArea
anchors.topMargin: 0
}
PropertyChanges {
target: musicToolbarSmallProgressBackground
opacity: 0
}
PropertyChanges {
target: musicToolbarFullProgressMouseArea
visible: true
}
}
]
transitions: Transition {
from: "minimized,minimized,expanded,expanded,full,full"
to: "expanded,full,minimized,full,minimized,expanded"
NumberAnimation {
duration: transitionDuration
properties: "y,opacity"
}
onRunningChanged: {
musicToolbar.animating = running;
}
}
/* Helper functions */
// Disable the toolbar for this page/view (eg a dialog)
function disableToolbar()
{
cachedState = state;
state = "hidden";
}
// Enable the toolbar (run when closing a page that disabled it)
function enableToolbar()
{
if (cachedState !== "")
{
state = cachedState;
cachedState = "";
}
}
// Back button has been pressed, jump up pageStack or back to parent page
function goBack()
{
if (currentPageStack !== null)
{
currentPageStack.pop(currentPage)
}
else if (currentParentPage !== null)
{
currentParentPage.visible = false // force switch
currentPage.visible = false
currentParentPage.visible = true
}
musicToolbar.hideToolbar();
}
// Hide the toolbar
function hideToolbar()
{
musicToolbarContainer.state = "minimized";
shown = false;
}
// Set the current page, and any parent/stacks
function setPage(childPage, parentPage, pageStack)
{
currentPage = childPage;
currentParentPage = parentPage === undefined ? null : parentPage;
currentPageStack = pageStack === undefined ? null : pageStack;
}
// Show the toolbar
function showToolbar()
{
musicToolbarContainer.state = currentPage === nowPlaying ? "full" : "expanded";
shown = true;
}
/* Mouse area to block events going to items under the toolbar */
MouseArea {
anchors.fill: parent
onClicked: mouse.accepted = true
}
/* Expanded toolbar */
Rectangle {
id: musicToolbarExpandedContainer
color: "transparent"
anchors.left: parent.left
anchors.top: musicToolbarSmallProgressBackground.bottom
height: expandedHeight
width: parent.width
Rectangle {
id: musicToolbarPlayerControls
anchors.fill: parent
color: styleMusic.playerControls.backgroundColor
state: trackQueue.isEmpty === true ? "disabled" : "enabled"
states: [
State {
name: "disabled"
PropertyChanges {
target: disabledPlayerControlsGroup
visible: true
}
PropertyChanges {
target: enabledPlayerControlsGroup
visible: false
}
},
State {
name: "enabled"
PropertyChanges {
target: disabledPlayerControlsGroup
visible: false
}
PropertyChanges {
target: enabledPlayerControlsGroup
visible: true
}
}
]
Rectangle {
id: disabledPlayerControlsGroup
anchors.fill: parent
color: "transparent"
visible: trackQueue.isEmpty === true
Label {
id: noSongsInQueueLabel
anchors.left: parent.left
anchors.margins: units.gu(1)
anchors.top: parent.top
color: styleMusic.playerControls.labelColor
text: i18n.tr("No songs queued")
fontSize: "large"
}
Label {
id: tabToStartPlayingLabel
color: styleMusic.playerControls.labelColor
anchors.left: parent.left
anchors.margins: units.gu(1)
anchors.top: noSongsInQueueLabel.bottom
text: i18n.tr("Tap on a song to start playing")
}
}
Rectangle {
id: enabledPlayerControlsGroup
anchors.fill: parent
color: "transparent"
visible: trackQueue.isEmpty === false
/* Settings button */
// TODO: Enable settings when it is practical
/* Rectangle {
id: playerControlsSettings
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: units.gu(6)
height: width
color: "transparent"
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
height: units.gu(3)
source: Qt.resolvedUrl("images/settings.png")
width: height
}
MouseArea {
anchors.fill: parent
onClicked: {
console.debug('Debug: Show settings')
PopupUtils.open(Qt.resolvedUrl("MusicSettings.qml"), mainView,
{
title: i18n.tr("Settings")
} )
}
}
} */
/* Play/Pause button TODO: image and colours needs updating */
Rectangle {
id: playerControlsPlayButton
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
color: "#444"
height: units.gu(7)
radius: height / 2
width: height
// draws the outer shadow/highlight
Rectangle {
id: sourceOutter
anchors { fill: parent; margins: -units.gu(0.1) }
radius: (width / 2)
antialiasing: true
gradient: Gradient {
GradientStop { position: 0.0; color: "black" }
GradientStop { position: 0.5; color: "transparent" }
GradientStop { position: 1.0; color: UbuntuColors.warmGrey }
}
Rectangle {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
antialiasing: true
color: "#444"
height: playerControlsPlayButton.height - units.gu(.1)
radius: height / 2
width: height
Rectangle {
id: playerControlsPlayInnerCircle
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
height: units.gu(4.5)
radius: height / 2
width: height
color: styleMusic.toolbar.fullInnerPlayCircleColor
// draws the inner shadow/highlight
Rectangle {
id: sourceInner
anchors { fill: parent; margins: -units.gu(0.1) }
radius: (width / 2)
antialiasing: true
gradient: Gradient {
GradientStop { position: 0.0; color: UbuntuColors.warmGrey }
GradientStop { position: 0.5; color: "transparent" }
GradientStop { position: 1.0; color: "black" }
}
Rectangle {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
antialiasing: true
height: playerControlsPlayInnerCircle.height - units.gu(.1)
radius: height / 2
width: height
color: styleMusic.toolbar.fullInnerPlayCircleColor
Image {
id: playindicator
height: units.gu(4)
width: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
opacity: 1
source: player.playbackState === MediaPlayer.PlayingState ?
Qt.resolvedUrl("images/media-playback-pause.svg") : Qt.resolvedUrl("images/media-playback-start.svg")
}
}
}
}
}
}
MouseArea {
objectName: "playshape" // objectName doesn't work on Rectangle?
anchors.fill: parent
function inCircle(x, y) {
/*
Function that returns true if the mouse is inside the circle
Length = root((y2-y1)^2 + (x2-x1)^2)
*/
x = Math.pow(x - (width / 2), 2);
y = Math.pow(y - (height / 2), 2);
return Math.pow((x + y), 0.5) <= parent.radius;
}
onClicked: {
var accepted = inCircle(mouse.x, mouse.y);
mouse.accepted = accepted;
if (accepted)
{
if (player.playbackState === MediaPlayer.PlayingState)
{
player.pause()
}
else
{
player.play()
}
}
}
}
}
/* Back button to go up pageStack */
Item {
id: playerControlBackButton
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.verticalCenter: parent.verticalCenter
width: units.gu(6)
height: width
visible: currentPageStack !== null && currentParentPage !== null
Image {
height: units.gu(3)
source: Qt.resolvedUrl("images/back.svg")
width: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
goBack();
}
}
}
/* Container holding the labels for the toolbar */
Rectangle {
id: playerControlLabelContainer
anchors.bottom: parent.bottom
anchors.left: playerControlBackButton.right
anchors.right: playerControlsPlayButton.left
anchors.top: parent.top
color: "transparent"
MouseArea {
anchors.fill: parent
onClicked: {
nowPlaying.visible = true
}
}
/* Title of track */
Label {
id: playerControlsTitle
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
anchors.top: parent.top
anchors.topMargin: units.gu(1)
color: styleMusic.playerControls.labelColor
elide: Text.ElideRight
fontSize: "medium"
objectName: "playercontroltitle"
text: mainView.currentTracktitle === "" ? mainView.currentFile : mainView.currentTracktitle
}
/* Artist of track */
Label {
id: playerControlsArtist
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
anchors.top: playerControlsTitle.bottom
color: styleMusic.playerControls.labelColor
elide: Text.ElideRight
fontSize: "small"
text: mainView.currentArtist
}
/* Album of track */
Label {
id: playerControlsAlbum
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
anchors.top: playerControlsArtist.bottom
color: styleMusic.playerControls.labelColor
elide: Text.ElideRight
fontSize: "small"
text: mainView.currentAlbum
}
}
}
}
}
/* Full toolbar */
Rectangle {
id: musicToolbarFullContainer
anchors.left: parent.left
anchors.top: parent.top
color: styleMusic.toolbar.fullBackgroundColor
height: fullHeight
width: parent.width
/* Buttons component */
Rectangle {
id: musicToolbarFullButtonsContainer
anchors.left: parent.left
anchors.top: musicToolbarFullProgressContainer.bottom
color: "transparent"
height: parent.height - musicToolbarFullProgressContainer.height
width: parent.width
/* Repeat button */
Item {
id: nowPlayingRepeatButton
objectName: "repeatShape"
anchors.right: nowPlayingPreviousButton.left
anchors.rightMargin: units.gu(1)
anchors.verticalCenter: parent.verticalCenter
height: units.gu(6)
width: height
Image {
id: repeatIcon
height: units.gu(3)
width: height
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: Qt.resolvedUrl("images/media-playlist-repeat.svg")
verticalAlignment: Text.AlignVCenter
opacity: Settings.getSetting("repeat") === "1" ? 1 : .4
}
MouseArea {
anchors.fill: parent
onClicked: {
// Invert repeat settings
Settings.setSetting("repeat", !(Settings.getSetting("repeat") === "1"))
console.debug("Repeat:", Settings.getSetting("repeat") === "1")
repeatIcon.opacity = Settings.getSetting("repeat") === "1" ? 1 : .4
}
}
}
/* Previous button */
Item {
id: nowPlayingPreviousButton
anchors.right: nowPlayingPlayButton.left
anchors.rightMargin: units.gu(1)
anchors.verticalCenter: parent.verticalCenter
height: units.gu(6)
objectName: "previousshape"
width: height
Image {
id: nowPlayingPreviousIndicator
height: units.gu(3)
width: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: Qt.resolvedUrl("images/media-skip-backward.svg")
opacity: 1
}
MouseArea {
anchors.fill: parent
id: nowPlayingPreviousMouseArea
onClicked:
{
previousSong()
}
}
}
/* Play/Pause button */
Rectangle {
id: nowPlayingPlayButton
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
color: styleMusic.toolbar.fullOuterPlayCircleColor
height: units.gu(12)
radius: height / 2
width: height
// draws the outter shadow/highlight
Rectangle {
id: sourceOutterFull
anchors { fill: parent; margins: -units.gu(0.1) }
radius: (width / 2)
antialiasing: true
gradient: Gradient {
GradientStop { position: 0.0; color: "black" }
GradientStop { position: 0.5; color: "transparent" }
GradientStop { position: 1.0; color: UbuntuColors.warmGrey }
}
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
color: styleMusic.toolbar.fullOuterPlayCircleColor
height: nowPlayingPlayButton.height - units.gu(.1)
radius: height / 2
width: height
Rectangle {
id: nowPlayingPlayButtonInner
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
color: styleMusic.toolbar.fullInnerPlayCircleColor
height: units.gu(7)
radius: height / 2
width: height
// draws the inner shadow/highlight
Rectangle {
id: sourceInnerFull
anchors { fill: parent; margins: -units.gu(0.1) }
radius: (width / 2)
antialiasing: true
gradient: Gradient {
GradientStop { position: 0.0; color: UbuntuColors.warmGrey }
GradientStop { position: 0.5; color: "transparent" }
GradientStop { position: 1.0; color: "black" }
}
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
color: styleMusic.toolbar.fullInnerPlayCircleColor
height: nowPlayingPlayButtonInner.height - units.gu(.1)
radius: height / 2
width: height
Image {
id: nowPlayingPlayIndicator
height: units.gu(6)
width: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
opacity: 1
source: player.playbackState === MediaPlayer.PlayingState ?
Qt.resolvedUrl("images/media-playback-pause.svg") : Qt.resolvedUrl("images/media-playback-start.svg")
}
MouseArea {
objectName: "nowPlayingPlayShape"
anchors.fill: parent
id: nowPlayingPlayMouseArea
function inCircle(x, y) {
/*
Function that returns true if the mouse is inside the circle
Length = root((y2-y1)^2 + (x2-x1)^2)
*/
x = Math.pow(x - (width / 2), 2);
y = Math.pow(y - (height / 2), 2);
return Math.pow((x + y), 0.5) <= parent.radius;
}
onClicked:
{
if (!inCircle(mouse.x, mouse.y))
{
return;
}
if (player.playbackState === MediaPlayer.PlayingState)
{
player.pause()
}
else
{
player.play()
}
}
}
}
}
}
}
}
}
/* Next button */
Item {
id: nowPlayingNextButton
anchors.left: nowPlayingPlayButton.right
anchors.leftMargin: units.gu(1)
anchors.verticalCenter: parent.verticalCenter
height: units.gu(6)
objectName: "forwardshape"
width: height
Image {
id: nowPlayingNextIndicator
height: units.gu(3)
width: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: Qt.resolvedUrl("images/media-skip-forward.svg")
opacity: 1
}
MouseArea {
anchors.fill: parent
id: nowPlayingNextMouseArea
onClicked:
{
nextSong()
}
}
}
/* Shuffle button */
Item {
id: nowPlayingShuffleButton
objectName: "shuffleShape"
anchors.left: nowPlayingNextButton.right
anchors.leftMargin: units.gu(1)
anchors.verticalCenter: parent.verticalCenter
height: units.gu(6)
width: height
Image {
id: shuffleIcon
height: units.gu(3)
width: height
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: Qt.resolvedUrl("images/media-playlist-shuffle.svg")
opacity: Settings.getSetting("shuffle") === "1" ? 1 : .4
}
MouseArea {
anchors.fill: parent
onClicked: {
// Invert shuffle settings
mainView.random = !mainView.random
shuffleIcon.opacity = mainView.random ? 1 : .4
Settings.setSetting("shuffle", mainView.random)
console.debug("Shuffle:", Settings.getSetting("shuffle") === "1")
}
}
}
}
/* Progress bar component */
Rectangle {
id: musicToolbarFullProgressContainer
anchors.left: parent.left
anchors.top: parent.top
color: styleMusic.toolbar.fullBackgroundColor
height: units.gu(3)
width: parent.width
/* Position label */
Label {
id: musicToolbarFullPositionLabel
anchors.left: parent.left
anchors.leftMargin: units.gu(2)
anchors.top: parent.top
color: styleMusic.nowPlaying.labelColor
fontSize: "x-small"
height: parent.height
horizontalAlignment: Text.AlignHCenter
text: player.positionStr
verticalAlignment: Text.AlignVCenter
width: units.gu(3)
}
/* Progress bar */
Rectangle {
id: musicToolbarFullProgressBarContainer
anchors.left: musicToolbarFullPositionLabel.right
anchors.leftMargin: units.gu(2)
anchors.right: musicToolbarFullDurationLabel.left
anchors.rightMargin: units.gu(2)
anchors.verticalCenter: parent.verticalCenter
color: "transparent"
height: units.gu(1);
state: trackQueue.isEmpty === true ? "disabled" : "enabled"
states: [
State {
name: "disabled"
PropertyChanges {
target: musicToolbarFullProgressMouseArea
enabled: false
}
PropertyChanges {
target: musicToolbarFullProgressTrough
visible: false
}
PropertyChanges {
target: musicToolbarFullProgressHandle
visible: false
}
},
State {
name: "enabled"
PropertyChanges {
target: musicToolbarFullProgressMouseArea
enabled: true
}
PropertyChanges {
target: musicToolbarFullProgressTrough
visible: true
}
PropertyChanges {
target: musicToolbarFullProgressHandle
visible: true
}
}
]
// Connection from positionChanged signal
function updatePosition(position, duration)
{
if (player.seeking == false)
{
musicToolbarFullProgressHandle.x = ((position / duration) * musicToolbarFullProgressBarContainer.width)
- musicToolbarFullProgressHandle.width / 2;
}
}
Component.onCompleted: {
// Connect to signal from MediaPlayer
player.positionChange.connect(updatePosition)
}
// Black background behind the progress bar
Rectangle {
id: musicToolbarFullProgressBackground
anchors.verticalCenter: parent.verticalCenter;
color: styleMusic.toolbar.fullProgressBackgroundColor;
height: parent.height;
radius: units.gu(0.5)
width: parent.width;
}
// The orange fill of the progress bar
Rectangle {
id: musicToolbarFullProgressTrough
anchors.verticalCenter: parent.verticalCenter;
antialiasing: true
color: styleMusic.toolbar.fullProgressTroughColor;
height: parent.height;
radius: units.gu(0.5)
width: musicToolbarFullProgressHandle.x + (height / 2); // +radius
}
// The current position (handle) of the progress bar
Rectangle {
id: musicToolbarFullProgressHandle
anchors.verticalCenter: musicToolbarFullProgressBackground.verticalCenter
antialiasing: true
color: styleMusic.nowPlaying.progressHandleColor
height: units.gu(1.5)
radius: height / 2
width: height
// On X change update the position string
onXChanged: {
var fraction = (x + (width / 2)) / parent.width;
player.positionStr = __durationToString(fraction * player.duration);
}
transitions: Transition {
NumberAnimation {
properties: "x"
duration: 1000
}
}
}
}
/* Duration label */
Label {
id: musicToolbarFullDurationLabel
anchors.right: parent.right
anchors.rightMargin: units.gu(2)
anchors.top: parent.top
color: styleMusic.nowPlaying.labelColor
fontSize: "x-small"
height: parent.height
horizontalAlignment: Text.AlignHCenter
text: player.durationStr
verticalAlignment: Text.AlignVCenter
width: units.gu(3)
}
/* Border at the bottom */
Rectangle {
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
color: styleMusic.common.white
height: units.gu(0.1)
opacity: 0.1
}
}
}
/* Object which provides the progress bar when toolbar is minimized */
Rectangle {
id: musicToolbarSmallProgressBackground
anchors.left: parent.left
anchors.top: parent.top
color: styleMusic.common.black
height: minimizedHeight
width: parent.width
Rectangle {
id: musicToolbarSmallProgressHint
anchors.left: parent.left
anchors.top: parent.top
color: styleMusic.nowPlaying.progressForegroundColor
height: parent.height
width: 0
function updatePosition(position, duration)
{
musicToolbarSmallProgressHint.width = (position / duration) * musicToolbarSmallProgressBackground.width
}
Component.onCompleted: {
player.positionChange.connect(updatePosition)
}
}
}
/* Object which captures mouse drags to show/hide the toolbar */
MouseArea {
id: musicToolbarMouseArea
anchors.fill: parent
property bool changed: false
property int startContainerY: 0
property int startMouseY: 0
// Settings for dragging the container
drag.axis: Drag.YAxis
drag.maximumY: musicToolbarContainer.parent.height - minimizedHeight
drag.minimumY: currentMode === "full" ?
musicToolbarContainer.parent.height - fullHeight :
musicToolbarContainer.parent.height - expandedHeight - minimizedHeight
drag.target: musicToolbarContainer
propagateComposedEvents: true
onClicked: mouse.accepted = changed // pass clicked evented to children unless changed (YAxis)
onMouseYChanged: {
// Mouse has been accepted with YAxis changed and set changed to true
mouse.accepted = true;
changed = true;
}
onPressAndHold: {
// If the item hasn't moved then run the hint animation
if (musicToolbarContainer.y === startContainerY)
{
musicToolbarContainerHintAnimation.start();
mouse.accepted = true; // mouse has been accepted
}
else
{
mouse.accepted = false;
}
}
onPressed: {
mouse.accepted = false; // mouse not accepted yet
// Record starting positions for later
startContainerY = musicToolbarContainer.y;
startMouseY = mouse.y;
}
onReleased: {
mouse.accepted = changed; // mouse is accepted if the YAxis has changed
changed = false; // reset changed
// fix for flicker on first run (needs a value to have been set?)
musicToolbarContainer.y = musicToolbarContainer.y;
var diff = musicToolbarContainer.y - startContainerY;
if (diff > units.gu(3))
{
hideToolbar();
}
else if (diff < -units.gu(3))
{
showToolbar();
}
else
{
musicToolbarContainerReset.start();
}
}
// On pressandhold reveal part of the toolbar as a hint
NumberAnimation {
id: musicToolbarContainerHintAnimation
target: musicToolbarContainer
property: "y"
duration: musicToolbarContainer.transitionDuration
to: musicToolbarContainer.parent.height - minimizedHeight - units.gu(1.5)
}
// Animation to reset the toolbar if it hasn't been dragged far enough
NumberAnimation {
id: musicToolbarContainerReset
target: musicToolbarContainer
property: "y"
duration: musicToolbarContainer.transitionDuration
to: musicToolbarMouseArea.startContainerY
}
}
/* Mouse events for the progress bar
is after musicToolbarMouseArea so that it captures mouse events for dragging */
MouseArea {
id: musicToolbarFullProgressMouseArea
height: units.gu(2)
width: musicToolbarFullProgressBarContainer.width
x: musicToolbarFullProgressBarContainer.x
y: musicToolbarFullProgressBarContainer.y
drag.axis: Drag.XAxis
drag.minimumX: -(musicToolbarFullProgressHandle.width / 2)
drag.maximumX: musicToolbarFullProgressBarContainer.width - (musicToolbarFullProgressHandle.width / 2)
drag.target: musicToolbarFullProgressHandle
onPressed: {
player.seeking = true;
// Jump the handle to the current mouse position
musicToolbarFullProgressHandle.x = mouse.x - (musicToolbarFullProgressHandle.width / 2);
}
onReleased: {
var fraction = mouse.x / musicToolbarFullProgressBarContainer.width;
// Limit the bounds of the fraction
fraction = fraction < 0 ? 0 : fraction
fraction = fraction > 1 ? 1 : fraction
player.seek((fraction) * player.duration);
player.seeking = false;
}
}
}
|