Skip to content

Commit

Permalink
feat: Raise player on cover click in full view or ctrl+click in panel
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbocanegra committed Jul 13, 2024
1 parent b04f6bd commit 655bea8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/contents/ui/Player.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ QtObject {
readonly property bool canPlay: ready ? mpris2Model.currentPlayer.canPlay : false
readonly property bool canPause: ready ? mpris2Model.currentPlayer.canPause : false
readonly property bool canSeek: ready ? mpris2Model.currentPlayer.canSeek : false
readonly property bool canRaise: ready ? mpris2Model.currentPlayer.canRaise : false

// To know whether Shuffle and Loop can be changed we have to check if the property is defined,
// unlike the other commands, LoopStatus and Shuffle hasn't a specific propety such as
Expand Down Expand Up @@ -77,4 +78,8 @@ QtObject {
function setLoopStatus(loopStatus) {
mpris2Model.currentPlayer.loopStatus = loopStatus
}

function raise() {
mpris2Model.currentPlayer.Raise();
}
}
62 changes: 59 additions & 3 deletions src/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ PlasmoidItem {
}
readonly property font boldTextFont: Qt.font(Object.assign({}, textFont, {weight: Font.Bold}))

toolTipSubText: player.canRaise ? i18n("Ctrl+Click to bring player to the front") : i18n("This player can't be raised")

Player {
id: player
sourceName: plasmoid.configuration.sources[plasmoid.configuration.sourceIndex]
Expand All @@ -40,6 +42,19 @@ PlasmoidItem {
}
}

MouseArea {
anchors.fill: parent
propagateComposedEvents: true
onClicked: (mouse) => {
if (mouse.modifiers & Qt.ControlModifier) {
if (player.canRaise) player.raise()
} else {
mouse.accepted = false
}
}
z: 999
}

RowLayout {
id: row
spacing: 0
Expand Down Expand Up @@ -97,7 +112,10 @@ PlasmoidItem {
icon.name: "media-skip-backward"
implicitWidth: compact.controlsSize
implicitHeight: compact.controlsSize
onClicked: player.previous()
MouseArea {
anchors.fill: parent
onClicked: player.previous()
}
}

PlasmaComponents3.ToolButton {
Expand All @@ -106,7 +124,10 @@ PlasmoidItem {
implicitWidth: compact.controlsSize
implicitHeight: compact.controlsSize
icon.name: player.playbackStatus === Mpris.PlaybackStatus.Playing ? "media-playback-pause" : "media-playback-start"
onClicked: player.playPause()
MouseArea {
anchors.fill: parent
onClicked: player.playPause()
}
}

PlasmaComponents3.ToolButton {
Expand All @@ -115,7 +136,10 @@ PlasmoidItem {
implicitWidth: compact.controlsSize
implicitHeight: compact.controlsSize
icon.name: "media-skip-forward"
onClicked: player.next()
MouseArea {
anchors.fill: parent
onClicked: player.next()
}
}
}
}
Expand All @@ -141,6 +165,38 @@ PlasmoidItem {
visible: player.artUrl
source: player.artUrl
fillMode: Image.PreserveAspectFit
MouseArea {
id: coverMouseArea
anchors.fill: parent
cursorShape: player.canRaise ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: {
if (player.canRaise) player.raise()
}
hoverEnabled: true
}
PlasmaComponents3.ToolTip {
id: raisePlayerTooltip
anchors.centerIn: parent
text: player.canRaise ? i18n("Bring player to the front") : i18n("This player can't be raised")
width: parent.width - Kirigami.Units.largeSpacing
contentItem: PlasmaComponents3.Label {
text: raisePlayerTooltip.text
font.pointSize: 16
font.weight: Font.Bold
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
// prevents tooltip from stealing the cursor
MouseArea {
anchors.centerIn: parent
width: raisePlayerTooltip.width
height: raisePlayerTooltip.height
propagateComposedEvents: true
cursorShape: Qt.PointingHandCursor
}
}
visible: coverMouseArea.containsMouse
delay: 0
}
}
}

Expand Down

0 comments on commit 655bea8

Please sign in to comment.