refactor: extract HoverPanel component, replace inline PanelWindows in Volume, Backlight, Mpris
This commit is contained in:
parent
50af43a76e
commit
0fd3c78fb0
5 changed files with 686 additions and 840 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Services.Mpris
|
||||
import "." as M
|
||||
|
||||
|
|
@ -58,9 +57,8 @@ M.BarSection {
|
|||
|
||||
required property var bar
|
||||
|
||||
property bool _panelHovered: false
|
||||
property bool _pinned: false
|
||||
readonly property bool _anyHover: root._hovered || _panelHovered
|
||||
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
|
||||
readonly property bool _showPanel: _anyHover || _pinned
|
||||
|
||||
on_AnyHoverChanged: {
|
||||
|
|
@ -97,383 +95,290 @@ M.BarSection {
|
|||
}
|
||||
}
|
||||
|
||||
PanelWindow {
|
||||
id: panel
|
||||
M.HoverPanel {
|
||||
id: hoverPanel
|
||||
showPanel: root._showPanel
|
||||
anchorX: root.mapToGlobal(root.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0)
|
||||
accentColor: root.accentColor
|
||||
panelNamespace: "nova-mpris"
|
||||
contentWidth: 280
|
||||
animateHeight: true
|
||||
|
||||
screen: QsWindow.window?.screen ?? null
|
||||
visible: _winVisible
|
||||
color: "transparent"
|
||||
// Album art
|
||||
Item {
|
||||
width: parent.width
|
||||
height: _artImg._hasArt ? 140 : 60
|
||||
clip: true
|
||||
|
||||
property bool _winVisible: false
|
||||
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.exclusiveZone: 0
|
||||
WlrLayershell.namespace: "nova-mpris"
|
||||
|
||||
anchors.top: true
|
||||
anchors.left: true
|
||||
|
||||
margins.top: 0
|
||||
margins.left: Math.max(0, Math.min(Math.round(root.mapToGlobal(root.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0) - implicitWidth / 2), (panel.screen?.width ?? 1920) - implicitWidth))
|
||||
|
||||
implicitWidth: panelContent.width
|
||||
implicitHeight: panelContent.height
|
||||
Behavior on implicitHeight {
|
||||
NumberAnimation {
|
||||
duration: 100
|
||||
easing.type: Easing.OutCubic
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: M.Theme.base02
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: root
|
||||
function on_ShowPanelChanged() {
|
||||
if (root._showPanel) {
|
||||
panel._winVisible = true;
|
||||
hideAnim.stop();
|
||||
showAnim.start();
|
||||
} else {
|
||||
showAnim.stop();
|
||||
hideAnim.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Image {
|
||||
id: _artImg
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
visible: _hasArt
|
||||
asynchronous: true
|
||||
source: root._cachedArt
|
||||
|
||||
ParallelAnimation {
|
||||
id: showAnim
|
||||
NumberAnimation {
|
||||
target: panelContent
|
||||
property: "opacity"
|
||||
to: 1
|
||||
duration: 120
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
NumberAnimation {
|
||||
target: panelContent
|
||||
property: "y"
|
||||
to: 0
|
||||
duration: 150
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
|
||||
ParallelAnimation {
|
||||
id: hideAnim
|
||||
NumberAnimation {
|
||||
target: panelContent
|
||||
property: "opacity"
|
||||
to: 0
|
||||
duration: 150
|
||||
easing.type: Easing.InCubic
|
||||
}
|
||||
NumberAnimation {
|
||||
target: panelContent
|
||||
property: "y"
|
||||
to: -panelContent.height
|
||||
duration: 150
|
||||
easing.type: Easing.InCubic
|
||||
}
|
||||
onFinished: panel._winVisible = false
|
||||
}
|
||||
|
||||
HoverHandler {
|
||||
onHoveredChanged: root._panelHovered = hovered
|
||||
}
|
||||
|
||||
M.PopupBackground {
|
||||
x: panelContent.x
|
||||
y: panelContent.y
|
||||
width: panelContent.width
|
||||
height: panelContent.height
|
||||
opacity: panelContent.opacity * Math.max(M.Theme.barOpacity, 0.85)
|
||||
accentColor: root.accentColor
|
||||
}
|
||||
|
||||
Column {
|
||||
id: panelContent
|
||||
width: 280
|
||||
opacity: 0
|
||||
y: -height
|
||||
topPadding: 4
|
||||
bottomPadding: 4
|
||||
spacing: 2
|
||||
|
||||
// Album art
|
||||
Item {
|
||||
width: parent.width
|
||||
height: _artImg._hasArt ? 140 : 60
|
||||
clip: true
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: M.Theme.base02
|
||||
}
|
||||
|
||||
Image {
|
||||
id: _artImg
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
visible: _hasArt
|
||||
asynchronous: true
|
||||
source: root._cachedArt
|
||||
|
||||
property bool _hasArt: false
|
||||
onStatusChanged: if (status === Image.Ready)
|
||||
_hasArt = true
|
||||
Connections {
|
||||
target: root
|
||||
function on_CachedArtChanged() {
|
||||
if (!root._cachedArt)
|
||||
_artImg._hasArt = false;
|
||||
}
|
||||
property bool _hasArt: false
|
||||
onStatusChanged: if (status === Image.Ready)
|
||||
_hasArt = true
|
||||
Connections {
|
||||
target: root
|
||||
function on_CachedArtChanged() {
|
||||
if (!root._cachedArt)
|
||||
_artImg._hasArt = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Visualizer bars
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
height: parent.height * 0.6
|
||||
spacing: 2
|
||||
visible: root.playing
|
||||
opacity: 0.5
|
||||
// Visualizer bars
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
height: parent.height * 0.6
|
||||
spacing: 2
|
||||
visible: root.playing
|
||||
opacity: 0.5
|
||||
|
||||
Repeater {
|
||||
model: 16
|
||||
Rectangle {
|
||||
required property int index
|
||||
width: (parent.width - 15 * parent.spacing) / 16
|
||||
height: parent.height * (root._cavaBars[index] ?? 0)
|
||||
anchors.bottom: parent.bottom
|
||||
color: root.accentColor
|
||||
radius: 1
|
||||
Repeater {
|
||||
model: 16
|
||||
Rectangle {
|
||||
required property int index
|
||||
width: (parent.width - 15 * parent.spacing) / 16
|
||||
height: parent.height * (root._cavaBars[index] ?? 0)
|
||||
anchors.bottom: parent.bottom
|
||||
color: root.accentColor
|
||||
radius: 1
|
||||
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
duration: 50
|
||||
}
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
duration: 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
height: 40
|
||||
visible: _artImg.visible
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: "transparent"
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: M.Theme.base01
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "\uF001"
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: 28
|
||||
font.family: M.Theme.iconFontFamily
|
||||
visible: _artImg.status !== Image.Ready
|
||||
}
|
||||
}
|
||||
|
||||
// Track info
|
||||
Item {
|
||||
width: parent.width
|
||||
height: titleCol.implicitHeight + 8
|
||||
|
||||
Column {
|
||||
id: titleCol
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.leftMargin: 12
|
||||
anchors.rightMargin: 12
|
||||
spacing: 2
|
||||
|
||||
Text {
|
||||
width: parent.width
|
||||
text: root.player?.trackTitle || "No track"
|
||||
color: M.Theme.base05
|
||||
font.pixelSize: M.Theme.fontSize + 1
|
||||
font.family: M.Theme.fontFamily
|
||||
font.bold: true
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
Text {
|
||||
width: parent.width
|
||||
text: {
|
||||
const p = root.player;
|
||||
if (!p)
|
||||
return "";
|
||||
const artist = Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : (p.trackArtists || "");
|
||||
return [artist, p.trackAlbum].filter(s => s).join(" \u2014 ");
|
||||
}
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 1
|
||||
font.family: M.Theme.fontFamily
|
||||
elide: Text.ElideRight
|
||||
visible: text !== ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Progress
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 20
|
||||
|
||||
readonly property real pos: root.player?.position ?? 0
|
||||
readonly property real dur: root.player?.length ?? 0
|
||||
readonly property real frac: dur > 0 ? pos / dur : 0
|
||||
|
||||
function _fmtTime(ms) {
|
||||
const s = Math.floor(ms / 1000);
|
||||
const m = Math.floor(s / 60);
|
||||
return m + ":" + String(s % 60).padStart(2, "0");
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: parent._fmtTime(parent.pos)
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
Text {
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: parent._fmtTime(parent.dur)
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
|
||||
Item {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: parent.width - 80
|
||||
height: 4
|
||||
|
||||
Rectangle {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
height: 40
|
||||
visible: _artImg.visible
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: "transparent"
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: M.Theme.base01
|
||||
}
|
||||
}
|
||||
anchors.fill: parent
|
||||
color: M.Theme.base02
|
||||
radius: 2
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "\uF001"
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: 28
|
||||
font.family: M.Theme.iconFontFamily
|
||||
visible: _artImg.status !== Image.Ready
|
||||
Rectangle {
|
||||
width: parent.width * Math.min(1, Math.max(0, parent.parent.frac))
|
||||
height: parent.height
|
||||
color: root.accentColor
|
||||
radius: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Track info
|
||||
Item {
|
||||
width: parent.width
|
||||
height: titleCol.implicitHeight + 8
|
||||
// Transport controls
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 36
|
||||
|
||||
Column {
|
||||
id: titleCol
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.leftMargin: 12
|
||||
anchors.rightMargin: 12
|
||||
spacing: 2
|
||||
|
||||
Text {
|
||||
width: parent.width
|
||||
text: root.player?.trackTitle || "No track"
|
||||
color: M.Theme.base05
|
||||
font.pixelSize: M.Theme.fontSize + 1
|
||||
font.family: M.Theme.fontFamily
|
||||
font.bold: true
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
Text {
|
||||
width: parent.width
|
||||
text: {
|
||||
const p = root.player;
|
||||
if (!p)
|
||||
return "";
|
||||
const artist = Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : (p.trackArtists || "");
|
||||
return [artist, p.trackAlbum].filter(s => s).join(" \u2014 ");
|
||||
}
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 1
|
||||
font.family: M.Theme.fontFamily
|
||||
elide: Text.ElideRight
|
||||
visible: text !== ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Progress
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 20
|
||||
|
||||
readonly property real pos: root.player?.position ?? 0
|
||||
readonly property real dur: root.player?.length ?? 0
|
||||
readonly property real frac: dur > 0 ? pos / dur : 0
|
||||
|
||||
function _fmtTime(ms) {
|
||||
const s = Math.floor(ms / 1000);
|
||||
const m = Math.floor(s / 60);
|
||||
return m + ":" + String(s % 60).padStart(2, "0");
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: parent._fmtTime(parent.pos)
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
Text {
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: parent._fmtTime(parent.dur)
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
|
||||
Item {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: parent.width - 80
|
||||
height: 4
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: M.Theme.base02
|
||||
radius: 2
|
||||
}
|
||||
Rectangle {
|
||||
width: parent.width * Math.min(1, Math.max(0, parent.parent.frac))
|
||||
height: parent.height
|
||||
color: root.accentColor
|
||||
radius: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Transport controls
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 36
|
||||
|
||||
Row {
|
||||
anchors.centerIn: parent
|
||||
spacing: 24
|
||||
|
||||
Text {
|
||||
text: "\uF048"
|
||||
color: root.player?.canGoPrevious ? M.Theme.base05 : M.Theme.base03
|
||||
font.pixelSize: M.Theme.fontSize + 4
|
||||
font.family: M.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
enabled: root.player?.canGoPrevious ?? false
|
||||
onClicked: root.player.previous()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: root.playing ? "\uF04C" : "\uF04B"
|
||||
color: root.accentColor
|
||||
font.pixelSize: M.Theme.fontSize + 8
|
||||
font.family: M.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.player?.togglePlaying()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: "\uF051"
|
||||
color: root.player?.canGoNext ? M.Theme.base05 : M.Theme.base03
|
||||
font.pixelSize: M.Theme.fontSize + 4
|
||||
font.family: M.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
enabled: root.player?.canGoNext ?? false
|
||||
onClicked: root.player.next()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Player switcher
|
||||
Row {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
height: 22
|
||||
spacing: 6
|
||||
anchors.centerIn: parent
|
||||
spacing: 24
|
||||
|
||||
Repeater {
|
||||
model: root._players
|
||||
Text {
|
||||
text: "\uF048"
|
||||
color: root.player?.canGoPrevious ? M.Theme.base05 : M.Theme.base03
|
||||
font.pixelSize: M.Theme.fontSize + 4
|
||||
font.family: M.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
enabled: root.player?.canGoPrevious ?? false
|
||||
onClicked: root.player.previous()
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
required property var modelData
|
||||
required property int index
|
||||
Text {
|
||||
text: root.playing ? "\uF04C" : "\uF04B"
|
||||
color: root.accentColor
|
||||
font.pixelSize: M.Theme.fontSize + 8
|
||||
font.family: M.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.player?.togglePlaying()
|
||||
}
|
||||
}
|
||||
|
||||
readonly property bool _active: index === root._playerIdx
|
||||
Text {
|
||||
text: "\uF051"
|
||||
color: root.player?.canGoNext ? M.Theme.base05 : M.Theme.base03
|
||||
font.pixelSize: M.Theme.fontSize + 4
|
||||
font.family: M.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
enabled: root.player?.canGoNext ?? false
|
||||
onClicked: root.player.next()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
width: _pLabel.implicitWidth + 12
|
||||
height: 18
|
||||
radius: 9
|
||||
color: _active ? M.Theme.base02 : (pArea.containsMouse ? M.Theme.base02 : "transparent")
|
||||
border.color: _active ? root.accentColor : M.Theme.base03
|
||||
border.width: _active ? 1 : 0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
// Player switcher
|
||||
Row {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
height: 22
|
||||
spacing: 6
|
||||
|
||||
Text {
|
||||
id: _pLabel
|
||||
anchors.centerIn: parent
|
||||
text: modelData.identity ?? "Player"
|
||||
color: _active ? root.accentColor : M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
font.bold: _active
|
||||
}
|
||||
Repeater {
|
||||
model: root._players
|
||||
|
||||
MouseArea {
|
||||
id: pArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root._playerIdx = index
|
||||
}
|
||||
delegate: Rectangle {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
readonly property bool _active: index === root._playerIdx
|
||||
|
||||
width: _pLabel.implicitWidth + 12
|
||||
height: 18
|
||||
radius: 9
|
||||
color: _active ? M.Theme.base02 : (pArea.containsMouse ? M.Theme.base02 : "transparent")
|
||||
border.color: _active ? root.accentColor : M.Theme.base03
|
||||
border.width: _active ? 1 : 0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text {
|
||||
id: _pLabel
|
||||
anchors.centerIn: parent
|
||||
text: modelData.identity ?? "Player"
|
||||
color: _active ? root.accentColor : M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
font.bold: _active
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: pArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root._playerIdx = index
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue