Skip to content

Commit

Permalink
Raise player on cover click and Ctrl+click from panel
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbocanegra committed Jul 7, 2024
1 parent b04f6bd commit d6bb4f2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/contents/ui/PanelIcon.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ Item {
Layout.preferredHeight: size
Layout.preferredWidth: size

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

onTypeChanged: () => {
if ([ "icon", "image" ].includes(type)) {
console.error("Panel icon type not supported")
Expand Down
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();
}
}
32 changes: 32 additions & 0 deletions src/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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 d6bb4f2

Please sign in to comment.