Commit 1d9492fd authored by Camilo Higuita's avatar Camilo Higuita

relocate mainPlaylist view

parent ca3562dd
This diff is collapsed.
......@@ -3,83 +3,82 @@ Qt.include("Icons.js")
function playTrack(track)
{
root.currentTrack = track
player.source(currentTrack.url);
root.mainPlaylist.currentTrack = track
player.source(root.mainPlaylist.currentTrack.url);
player.play()
root.title = currentTrack.title + " - " +currentTrack.artist
currentArtwork = con.getAlbumArt(currentTrack.album, currentTrack.artist) || con.getArtistArt(currentTrack.artist)
root.title = root.mainPlaylist.currentTrack.title + " - " +root.mainPlaylist.currentTrack.artist
root.mainPlaylist.currentArtwork = con.getAlbumArt(root.mainPlaylist.currentTrack.album,
root.mainPlaylist.currentTrack.artist)
|| con.getArtistArt(root.mainPlaylist.currentTrack.artist)
playIcon.text = Icon.pause
root.mainPlaylist.playIcon.text = Icon.pause
if(con.getTrackBabe(currentTrack.url))
babeBtnIcon.color = "#E91E63"
if(con.getTrackBabe(root.mainPlaylist.currentTrack.url))
root.mainPlaylist.babeBtnIcon.color = "#E91E63"
else
babeBtnIcon.color = babeBtnIcon.defaultColor
root.mainPlaylist.babeBtnIcon.color = root.mainPlaylist.babeBtnIcon.defaultColor
}
function stop()
{
player.stop()
progressBar.value = 0
coverPlay.visible = false
root.mainPlaylist.progressBar.value = 0
root.mainPlaylist.cover.visible = false
root.title = "Babe..."
playIcon.text = Icon.play
root.mainPlaylist.playIcon.text = Icon.play
}
function pauseTrack()
{
player.pause()
playIcon.text = Icon.play
root.mainPlaylist.playIcon.text = Icon.play
}
function resumeTrack()
{
player.play()
playIcon.text = Icon.pause
root.mainPlaylist.playIcon.text = Icon.pause
}
function nextTrack()
{
var next
console.log("shuffle<<", root.shuffle)
if(root.shuffle)
var next = 0
if(root.mainPlaylist.shuffle)
next = shuffle()
else
next = mainPlaylistTable.currentIndex+1 >= mainPlaylistTable.count? 0 : mainPlaylistTable.currentIndex+1
next = root.mainPlaylist.list.currentIndex+1 >= root.mainPlaylist.list.count? 0 : root.mainPlaylist.list.currentIndex+1
mainPlaylistTable.currentIndex = next
playTrack(mainPlaylistTable.model.get(next))
root.mainPlaylist.list.currentIndex = next
playTrack(root.mainPlaylist.list.model.get(next))
}
function previousTrack()
{
var previous = mainPlaylistTable.currentIndex-1 >= 0 ? mainPlaylistTable.currentIndex-1 : mainPlaylistTable.count-1
mainPlaylistTable.currentIndex = previous
playTrack(mainPlaylistTable.model.get(previous))
var previous = root.mainPlaylist.list.currentIndex-1 >= 0 ? root.mainPlaylist.list.currentIndex-1 : root.mainPlaylist.list.count-1
root.mainPlaylist.list.currentIndex = previous
playTrack(root.mainPlaylist.list.model.get(previous))
}
function shuffle()
{
var pos = Math.floor(Math.random() * mainPlaylistTable.count)
var pos = Math.floor(Math.random() * root.mainPlaylist.list.count)
return pos
}
function appendTrack(track)
{
var empty = root.mainPlaylist.list.count
root.mainPlaylist.list.model.append(track)
root.mainPlaylist.list.positionViewAtEnd()
var empty = mainPlaylistTable.count
mainPlaylistTable.model.append(track)
mainPlaylistTable.positionViewAtEnd()
if(empty === 0 && mainPlaylistTable.count>0)
if(empty === 0 && root.mainPlaylist.list.count>0)
{
mainPlaylistTable.currentIndex = 0
playTrack(mainPlaylistTable.model.get(0))
root.mainPlaylist.list.currentIndex = 0
playTrack(root.mainPlaylist.list.model.get(0))
}
}
function appendAlbum(tracks)
......@@ -91,24 +90,19 @@ function appendAlbum(tracks)
function savePlaylist()
{
var list = []
var n = mainPlaylistTable.count
var n = root.mainPlaylist.list.count
for(var i=0 ; i<n; i++)
{
var url = mainPlaylistTable.model.get(i).url
var url = root.mainPlaylist.list.model.get(i).url
list.push(url)
}
util.savePlaylist(list)
util.savePlaylistPos(root.mainPlaylist.list.currentIndex)
}
function savePlaylistPos()
{
util.savePlaylistPos(mainPlaylistTable.currentIndex)
}
function clearOutPlaylist()
{
mainPlaylistTable.clearTable()
root.mainPlaylist.list.clearTable()
stop()
}
......@@ -116,40 +110,40 @@ function cleanPlaylist()
{
var urls = []
for(var i = 0; i < mainPlaylistTable.count; i++)
for(var i = 0; i < root.mainPlaylist.list.count; i++)
{
var url = mainPlaylistTable.model.get(i).url
var url = root.mainPlaylist.list.model.get(i).url
if(urls.indexOf(url)<0)
urls.push(url)
else mainPlaylistTable.model.remove(i)
else root.mainPlaylist.list.model.remove(i)
}
}
function playAlbum(tracks)
{
mainPlaylistTable.clearTable()
root.mainPlaylist.list.clearTable()
for(var i in tracks)
appendTrack(tracks[i])
mainPlaylistTable.currentIndex = 0
playTrack(mainPlaylistTable.model.get(0))
root.mainPlaylist.list.currentIndex = 0
playTrack(root.mainPlaylist.list.model.get(0))
root.currentView = 0
}
function babeTrack()
{
if(con.getTrackBabe(root.currentTrack.url))
if(con.getTrackBabe(root.mainPlaylist.currentTrack.url))
{
con.babeTrack(root.currentTrack.url, false)
babeBtnIcon.text = Icon.heartOutline
babeBtnIcon.color = babeBtnIcon.defaultColor
con.babeTrack(root.mainPlaylist.currentTrack.url, false)
root.mainPlaylist.babeBtnIcon.text = Icon.heartOutline
root.mainPlaylist.babeBtnIcon.color = root.mainPlaylist.babeBtnIcon.defaultColor
}else
{
con.babeTrack(root.currentTrack.url, true)
babeBtnIcon.text = Icon.heartOutline
babeBtnIcon.color = "#E91E63"
con.babeTrack(root.mainPlaylist.currentTrack.url, true)
root.mainPlaylist.babeBtnIcon.text = Icon.heartOutline
root.mainPlaylist.babeBtnIcon.color = "#E91E63"
}
}
import QtQuick.Controls 2.2
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtLocation 5.9
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
Column
import "../utils/Icons.js" as MdiFont
import "../utils/Player.js" as Player
import "../utils"
import "../view_models"
import "../widgets"
Item
{
property string coverArt: "qrc:/assets/cover.png"
id: layout
width:parent.width
height:parent.height
}
property var currentTrack
property string currentArtwork
property bool shuffle : false
property alias progressBar : progressBar
property alias cover : cover
property alias list : list
property alias playIcon : playIcon
property alias babeBtnIcon: babeBtnIcon
// Component.onCompleted:
// {
// if(list.count>0)
// root.width = columnWidth
// else
// root.width = columnWidth*3
// }
GridLayout
{
id: playlistLayout
width: parent.width
height: parent.height
columns: 1
rows: 4
rowSpacing: 0
Rectangle
{
id: cover
Layout.row: 1
height: columnWidth
width: parent.width
Layout.fillWidth: true
visible: list.count>0
FastBlur
{
anchors.fill: cover
source: artwork
radius: 100
}
Image
{
id: artwork
width: parent.width < columnWidth ? parent.width : columnWidth
height: parent.height
anchors.centerIn: parent
source: currentArtwork ? "file://"+encodeURIComponent(currentArtwork) : "qrc:/assets/cover.png"
fillMode: Image.PreserveAspectFit
}
}
Slider
{
id: progressBar
Layout.fillWidth: true
Layout.fillHeight: true
Layout.row: 3
height: 16
from: 0
to: 1000
value: 0
visible: list.count>0
spacing: 0
onMoved: player.seek(player.duration() / 1000 * value);
Rectangle
{
anchors.fill: parent
color: util.midColor()
z: -999
}
}
Rectangle
{
id: playbackControls
Layout.fillWidth: true
Layout.row: 2
height: 48
visible: list.count>0
color: util.midColor()
onYChanged:
{
if(playbackControls.y<columnWidth/4)
{
cover.visible= false
playbackControls.y = 0
}else
{
cover.visible= true
playbackControls.y = columnWidth
}
}
PlaylistMenu
{
id: playlistMenu
onClearOut: Player.clearOutPlaylist()
onHideCover: cover.visible = !cover.visible
onClean: Player.cleanPlaylist()
}
MouseArea
{
anchors.fill: parent
drag.target: playbackControls
drag.axis: Drag.YAxis
drag.minimumY: 0
drag.maximumY: columnWidth
onClicked:
{
if(Qt.platform.os === "linux")
cover.visible = !cover.visible
}
}
RowLayout
{
width: parent.width
height: parent.height
anchors.fill: parent
ToolButton
{
id: menuBtn
Icon {text: MdiFont.Icon.dotsVertical}
onClicked: playlistMenu.open()
}
Row
{
anchors.centerIn: parent
ToolButton
{
Icon
{
id: babeBtnIcon
text: MdiFont.Icon.heartOutline
color: defaultColor
}
onClicked: Player.babeTrack()
}
ToolButton
{
id: previousBtn
Icon {text: MdiFont.Icon.skipPrevious}
onClicked: Player.previousTrack()
}
ToolButton
{
id: playBtn
Icon {id: playIcon; text: MdiFont.Icon.play }
onClicked:
{
if(player.isPaused()) Player.resumeTrack()
else Player.pauseTrack()
}
}
ToolButton
{
id: nextBtn
Icon{text: MdiFont.Icon.skipNext}
onClicked: Player.nextTrack()
}
ToolButton
{
id: shuffleBtn
Icon { text: shuffle ? MdiFont.Icon.shuffle : MdiFont.Icon.shuffleDisabled}
onClicked: shuffle = !shuffle
}
}
}
}
Rectangle
{
id: mainPlaylist
Layout.fillWidth: true
Layout.fillHeight: true
Layout.row: 4
color: "transparent"
BabeTable
{
id: list
width: parent.width
height: parent.height
onRowClicked: Player.playTrack(model.get(index))
holder.message: "Empty playlist..."
Component.onCompleted:
{
var list = util.lastPlaylist()
var n = list.length
for(var i = 0; i < n; i++)
{
var track = con.get("select * from tracks where url = \""+list[i]+"\"")
Player.appendTrack(track[0])
}
// var pos = util.lastPlaylistPos()
// console.log("POSSS:", pos)
// list.currentIndex = pos
// play(list.model.get(pos))
}
}
}
}
}
......@@ -26,7 +26,7 @@ Menu
}
MenuItem
{
text: qsTr("Hide cover...")
text: cover.visible ? qsTr("Hide cover...") : qsTr("Show cover...")
onTriggered: hideCover()
}
MenuItem
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment