1 Star 0 Fork 9

小蜗牛的长征/Qml--mediaPlayer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
SongList.qml 24.29 KB
一键复制 编辑 原始数据 按行查看 历史
破忆断回 提交于 2019-12-18 22:18 . 第一次提交
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
import QtQuick 2.12
import QtQuick.Controls 1.4 as Q14
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 2.12
Item {
id: tabelViewTestItem
// width: parent.width
// height: parent.height
Flickable {
anchors.fill: parent
anchors.topMargin: 20
Rectangle {
id: pageMessage
height: 250
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
Image {
id: playListImage
anchors.left: parent.left
anchors.margins: 10
anchors.top: parent.top
cache: false
source: "qrc:/listImage/otherImage/v2-f7069c486b92523f1a8d86f900872e1b_r.jpg"
width: 200
height: 200
MouseArea {
anchors.fill: parent
anchors.margins: -5
onClicked: {
swipeView.currentIndex = 2
console.log("go to playing zone ")
}
}
}
Rectangle {
anchors.leftMargin: 25
anchors.right: parent.right
anchors.bottom: playListImage.bottom
anchors.top: parent.top
anchors.topMargin: 0
anchors.left: playListImage.right
Column {
id: column
spacing: 15
anchors.fill: parent
Rectangle {
id: rectangle1
width: parent.width
height: 35
Rectangle {
id: rectangle
width: 40
height: 30
color: "#ee0000"
Text {
text: qsTr("歌单")
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: root.fontSize
}
}
Text {
anchors.left: rectangle.right
id: songListName
font.pixelSize: 20
text: qsTr("主歌单")
anchors.top: parent.top
anchors.topMargin: 0
}
}
Text {
id: currentDateText
width: parent.width
height: 35
font.pixelSize: root.fontSize
property var locale: Qt.locale()
property date currentTime: new Date()
property string timeString
Component.onCompleted: {
timeString =
currentTime.toLocaleTimeString(locale, Locale.ShortFormat);
currentDateText.text=
Date.fromLocaleTimeString(locale, timeString, Locale.ShortFormat);
}
}
Row {
width: parent.width
height: 35
spacing: 20
Button {
id:playAll
height: parent.height
text: qsTr("播放全部")
flat: true
background: Rectangle{
anchors.fill: parent
border.width: 1
border.color: "silver"
radius: 5
MouseArea{
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: {
parent.color="silver"
}
onExited: {
parent.color="white"
}
}
}
icon.source: "qrc:/play/Iamges/play/bofang.png"
display: AbstractButton.TextBesideIcon
onPressed: {
mediaPlayer.play()
}
}
Button {
height: parent.height
text: qsTr("收藏")
flat: true
icon.source: "qrc:/menu/Iamges/menu/shoucang.png"
display: AbstractButton.TextBesideIcon
background: Rectangle{
anchors.fill: parent
border.width: 1
border.color: "silver"
radius: 5
MouseArea{
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: {
parent.color="silver"
}
onExited: {
parent.color="white"
}
}
}
}
Button {
height: parent.height
text: qsTr("分享")
display: AbstractButton.TextBesideIcon
flat: true
icon.source: "qrc:/menu/Iamges/menu/fenxiang.png"
background: Rectangle{
anchors.fill: parent
border.width: 1
border.color: "silver"
radius: 5
MouseArea{
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: {
parent.color="silver"
}
onExited: {
parent.color="white"
}
}
}
}
Button {
height: parent.height
text: qsTr("下载全部")
flat: true
icon.source: "qrc:/menu/Iamges/menu/xiazai.png"
background: Rectangle{
anchors.fill: parent
border.width: 1
border.color: "silver"
radius: 5
MouseArea{
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: {
parent.color="silver"
}
onExited: {
parent.color="white"
}
}
}
}
}
Text {
id: label
text: qsTr("标签")
}
Text {
id: description
text: qsTr("简介")
}
}
}
}
Q14.TableView {
id: tableView
height: 200
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.top: pageMessage.bottom
antialiasing: true
visible: true
sortIndicatorOrder: Qt.AscendingOrder
sortIndicatorVisible: true
property string currentFilePath: ""
style: TableViewStyle {
headerDelegate: Rectangle {
//设置表头的样式
implicitWidth: /*styleData.value===""? 10:*/ tableView.width / 3
implicitHeight: fontSize * 2
border.width: 1
border.color: "gray"
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 0
text: styleData.value
color: styleData.pressed ? "burlywood" : "darkgray"
font.bold: true
}
}
itemDelegate: Text {
text: styleData.value
elide: Text.ElideLeft
property bool selected: styleData.selected
onSelectedChanged: {
if (selected
&& styleData.column === tableView.columnCount - 1) {
// 显示的是所有被选中项
console.log("当前路径为" + styleData.value.toString())
tableView.currentFilePath = styleData.value.toString()
}
}
}
rowDelegate: Rectangle {
height: root.fontSize * 2
color: styleData.selected ? "burlywood" : "darkgray"
property string lastColor: ""
//property int row: styleData.row
anchors.leftMargin: 2
/* MouseArea {
// anchors.fill: parent
// acceptedButtons: Qt.NoButton
// propagateComposedEvents: false
// hoverEnabled: true
// onEntered: {
// if(parent.row !== tableView.currentRow){
// parent.lastColor = parent.color
// parent.color = "#deb660"
// }else {
// parent.lastColor = parent.color
// parent.color = "#deb660"
// }
// }
// onExited: {
//// if (!styleData.selected
//// && parent.row !== tableView.currentRow) {
//// parent.color = "darkgray"
//// console.log("离开时的事件触发 ")
//// } else {
//// parent.lastColor = parent.color
//// parent.color = "#deb660"
//// }
//// if(parent.row!==tableView.currentRow)
//// parent.color="darkgray"
// }
//// onClicked: {
//// console.log("click")
//// if (mouse.button === Qt.LeftButton) {
//// var currentRow = tableView.rowAt(mouseX, mouseY)
//// if (currentRow !== -1) {
//// tableView.selection.deselect(
//// 0, tableView.rowCount - 1)
//// tableView.selection.select(currentRow)
//// tableView.currentRow = currentRow
//// }
//// }
//// }
// }
// }*/
}
}
MouseArea {
id: mouseRegion
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.topMargin: 0
acceptedButtons: Qt.RightButton | Qt.LeftButton // 激活右键(别落下这个)
drag.filterChildren: true
propagateComposedEvents: true
onClicked: {
if (mouse.button === Qt.LeftButton) {
var currentRow = tableView.rowAt(mouseX, mouseY)
if (currentRow !== -1) {
tableView.selection.deselect(0,
tableView.rowCount - 1)
tableView.selection.select(currentRow)
}
}
if (mouse.button === Qt.RightButton /* ||mouse.button===Qt.LeftButton*/
) {
// 右键菜单
currentRow = tableView.rowAt(mouseX, mouseY)
if (currentRow !== -1) {
tableView.selection.deselect(0,
tableView.rowCount - 1)
tableView.selection.select(currentRow)
contentMenu.popup()
}
}
}
onDoubleClicked: {
if (mouse.button === Qt.LeftButton) {
var currentRow = tableView.rowAt(mouseX, mouseY)
if (currentRow !== -1) {
console.log("应该播放此歌曲")
tableView.selection.deselect(0,
tableView.rowCount - 1)
tableView.selection.select(currentRow)
if (playlist.currentItemSource !== tableView.currentFilePath) {
playlist.addItem(tableView.currentFilePath)
playlist.currentIndex = playlist.itemCount - 1
mediaPlayer.play()
}
}
}
}
}
Button {
anchors.right: parent.right
anchors.bottom: parent.top
id: openFile
text: qsTr("新增文件夹")
font.pointSize: root.fontSize / 2
onClicked: {
fileDialog.visible = true
}
}
Menu {
// 右键菜单
//title: "Edit"
id: contentMenu
MenuItem {
text: qsTr("查看评论")
icon.width: 16
icon.height: 16
icon.source: "qrc:/menu/Iamges/menu/bianji.png"
font.pixelSize: root.fontSize
onTriggered: {
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
MenuItem {
text: qsTr("播放")
font.pixelSize: root.fontSize
icon.width: 16
icon.height: 16
icon.source: "qrc:/play/Iamges/play/bofang.png"
onTriggered: {
if (playlist.currentItemSource !== tableView.currentFilePath) {
playlist.addItem(tableView.currentFilePath)
playlist.currentIndex = playlist.itemCount - 1
mediaPlayer.play()
}
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
MenuItem {
text: qsTr("下一首播放")
icon.source: "qrc:/play/Iamges/play/xiayishou-yuanshijituantubiao.png"
icon.width: 16
icon.height: 16
font.pixelSize: root.fontSize
onTriggered: {
if (playlist.itemSource(
(playlist.currentIndex + 1)) !== tableView.currentFilePath) {
playlist.insertItem(playlist.currentIndex + 1,
tableView.currentFilePath)
}
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
Menu {
title: qsTr("收藏到歌单")
font.family: root.fontFamily
font.pixelSize: root.fontSize
Repeater {
model: listView.model
MenuItem {
text: qsTr("收藏到歌单")
icon.width: 16
icon.height: 16
icon.source: "qrc:/menu/Iamges/menu/shoucang.png"
font.pixelSize: root.fontSize
onTriggered: {
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
}
}
MenuItem {
text: qsTr("分享")
icon.source: "qrc:/listImage/otherImage/1/fenxiang.png"
icon.width: 16
icon.height: 16
font.pixelSize: root.fontSize
onTriggered: {
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
MenuItem {
text: qsTr("复制链接")
icon.source: "qrc:/menu/Iamges/menu/fenxiang.png"
font.pixelSize: root.fontSize
icon.width: 16
icon.height: 16
onTriggered: {
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
MenuItem {
text: qsTr("下载")
icon.source: "qrc:/menu/Iamges/menu/xiazai.png"
font.pixelSize: root.fontSize
icon.width: 16
icon.height: 16
onTriggered: {
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
MenuItem {
text: qsTr("从歌单中删除")
icon.source: "qrc:/menu/Iamges/menu/shanchu.png"
font.pixelSize: root.fontSize
icon.width: 16
icon.height: 16
onTriggered: {
mySql.removeMusic(tableView.currentFilePath)
}
background: Rectangle {
anchors.fill: parent
MouseArea {
anchors.fill: parent
onEntered: {
parent.color = "silver"
}
onExited: {
parent.color = "white"
}
}
}
}
}
/* function changed(index) {
console.log("当前点击的路径为")
}
// Connections {
// target: tableView
// onCurrentIndexChanged: {
// console.log(tableView.currentIndex + " is clicked!" + tableView.currentTab)
// changed(tableView.currentIndex)
// }
// }*/
model: myModel
Component.onCompleted: {
console.log("现在数据有多少行" + myModel.rowCount())
}
Q14.TableViewColumn {
role: ""
title: " "
}
Q14.TableViewColumn {
role: "id"
title: ""
}
Q14.TableViewColumn {
role: "musicName"
title: "名字"
}
Q14.TableViewColumn {
role: "artist"
title: "作者"
}
Q14.TableViewColumn {
role: "album"
title: "专辑"
}
Q14.TableViewColumn {
role: "duration"
title: "时长"
}
Q14.TableViewColumn {
visible: false
role: "filePath"
title: ""
}
}
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
QML
1
https://gitee.com/xwn/Qml--mediaPlayer.git
git@gitee.com:xwn/Qml--mediaPlayer.git
xwn
Qml--mediaPlayer
Qml--mediaPlayer
master

搜索帮助