implement and use clickable on mpris player
This commit is contained in:
parent
622d9fe7a7
commit
903803bdfd
3 changed files with 94 additions and 32 deletions
|
|
@ -16,8 +16,8 @@ Item {
|
||||||
|
|
||||||
Player {
|
Player {
|
||||||
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
visible: index === root.currentIndex && modelData.canControl
|
visible: index === root.currentIndex && modelData.canControl
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,21 @@
|
||||||
import Quickshell
|
|
||||||
import Quickshell.Services.Mpris
|
import Quickshell.Services.Mpris
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import "../../../../styled/"
|
import "../../../../styled/"
|
||||||
import "../../../../config/"
|
import "../../../../config/"
|
||||||
|
|
||||||
Item {
|
Loader {
|
||||||
required property MprisPlayer modelData
|
required property MprisPlayer modelData
|
||||||
required property int index
|
required property int index
|
||||||
|
|
||||||
signal nextPlayer
|
signal nextPlayer
|
||||||
signal previousPlayer
|
signal previousPlayer
|
||||||
|
|
||||||
implicitWidth: text.width
|
sourceComponent: player
|
||||||
implicitHeight: Dimensions.mpris.height
|
property Component player: Clickable {
|
||||||
|
id: clickable
|
||||||
|
|
||||||
StyledLabel {
|
implicitWidth: text.width
|
||||||
anchors.fill: text
|
implicitHeight: Dimensions.mpris.height
|
||||||
}
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
id: text
|
|
||||||
text: `${modelData.isPlaying ? "" : ""} ${modelData.trackTitle} - ${modelData.trackArtist}`
|
|
||||||
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
topPadding: Dimensions.mpris.verticalPadding
|
|
||||||
bottomPadding: Dimensions.mpris.verticalPadding
|
|
||||||
leftPadding: Dimensions.mpris.horizontalPadding
|
|
||||||
rightPadding: Dimensions.mpris.horizontalPadding
|
|
||||||
|
|
||||||
font.pixelSize: Dimensions.mpris.fontSize
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: text
|
|
||||||
|
|
||||||
cursorShape: Qt.PointingHandCursor
|
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!modelData.canTogglePlaying) {
|
if (!modelData.canTogglePlaying) {
|
||||||
|
|
@ -46,11 +27,39 @@ Item {
|
||||||
modelData.play();
|
modelData.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onWheel: event => {
|
onScrolledUp: parent.nextPlayer()
|
||||||
if (event.angleDelta.y > 0) {
|
onScrolledDown: parent.previousPlayer()
|
||||||
parent.nextPlayer();
|
|
||||||
} else if (event.angleDelta.y < 0) {
|
StyledText {
|
||||||
parent.previousPlayer();
|
id: text
|
||||||
|
text: `${modelData.isPlaying ? "" : ""} ${modelData.trackTitle} - ${modelData.trackArtist}`
|
||||||
|
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
topPadding: Dimensions.mpris.verticalPadding
|
||||||
|
bottomPadding: Dimensions.mpris.verticalPadding
|
||||||
|
leftPadding: Dimensions.mpris.horizontalPadding
|
||||||
|
rightPadding: Dimensions.mpris.horizontalPadding
|
||||||
|
|
||||||
|
font.pixelSize: Dimensions.mpris.fontSize
|
||||||
|
|
||||||
|
states: State {
|
||||||
|
name: "hovered"
|
||||||
|
when: clickable.hovered
|
||||||
|
PropertyChanges {
|
||||||
|
text {
|
||||||
|
color: Theme.palette.base300
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transitions: Transition {
|
||||||
|
from: ""
|
||||||
|
to: "hovered"
|
||||||
|
reversible: true
|
||||||
|
ColorAnimation {
|
||||||
|
properties: "color"
|
||||||
|
duration: 200
|
||||||
|
easing.type: Easing.InOutCubic
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
53
styled/Clickable.qml
Normal file
53
styled/Clickable.qml
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import QtQuick
|
||||||
|
import "../config/"
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: root
|
||||||
|
property bool disabled: false
|
||||||
|
property alias hovered: mouseArea.containsMouse
|
||||||
|
signal clicked
|
||||||
|
signal scrolledUp
|
||||||
|
signal scrolledDown
|
||||||
|
|
||||||
|
StyledLabel {
|
||||||
|
id: background
|
||||||
|
anchors.fill: parent
|
||||||
|
states: State {
|
||||||
|
name: "hovered"
|
||||||
|
when: mouseArea.containsMouse
|
||||||
|
PropertyChanges {
|
||||||
|
background {
|
||||||
|
color: Theme.palette.primary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transitions: Transition {
|
||||||
|
from: ""
|
||||||
|
to: "hovered"
|
||||||
|
reversible: true
|
||||||
|
ColorAnimation {
|
||||||
|
properties: "color"
|
||||||
|
duration: 200
|
||||||
|
easing.type: Easing.InOutCubic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: mouseArea
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
hoverEnabled: !disabled
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
|
||||||
|
onClicked: root.clicked()
|
||||||
|
|
||||||
|
onWheel: event => {
|
||||||
|
if (event.angleDelta.y > 0) {
|
||||||
|
root.scrolledUp();
|
||||||
|
} else if (event.angleDelta.y < 0) {
|
||||||
|
root.scrolledDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue