MediaMini: fix visualizer not showing when track length is unknown (twitch)
This commit is contained in:
parent
7b5c97f38a
commit
78cb7d4c15
1 changed files with 159 additions and 124 deletions
|
|
@ -18,12 +18,13 @@ RowLayout {
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
spacing: Style.marginS * scaling
|
spacing: Style.marginS * scaling
|
||||||
visible: MediaService.currentPlayer !== null && MediaService.canPlay
|
visible: MediaService.currentPlayer !== null && MediaService.canPlay
|
||||||
width: MediaService.currentPlayer !== null && MediaService.canPlay ? implicitWidth : 0
|
Layout.preferredWidth: MediaService.currentPlayer !== null && MediaService.canPlay ? implicitWidth : 0
|
||||||
|
|
||||||
function getTitle() {
|
function getTitle() {
|
||||||
return MediaService.trackTitle + (MediaService.trackArtist !== "" ? ` - ${MediaService.trackArtist}` : "")
|
return MediaService.trackTitle + (MediaService.trackArtist !== "" ? ` - ${MediaService.trackArtist}` : "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A hidden text element to safely measure the full title width
|
||||||
NText {
|
NText {
|
||||||
id: fullTitleMetrics
|
id: fullTitleMetrics
|
||||||
visible: false
|
visible: false
|
||||||
|
|
@ -33,20 +34,36 @@ RowLayout {
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: mediaMini
|
id: mediaMini
|
||||||
width: contentLayout.implicitWidth + Style.marginS * 2 * scaling
|
|
||||||
height: Math.round(Style.capsuleHeight * scaling)
|
Layout.preferredWidth: rowLayout.implicitWidth + Style.marginM * 2 * scaling
|
||||||
radius: Math.round(Style.radiusM * scaling)
|
Layout.preferredHeight: Math.round(Style.capsuleHeight * scaling)
|
||||||
color: Color.mSurfaceVariant
|
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
|
||||||
// --- Visualizer Loaders ---
|
radius: Math.round(Style.radiusM * scaling)
|
||||||
|
color: Color.mSurfaceVariant
|
||||||
|
|
||||||
|
// Used to anchor the tooltip, so the tooltip does not move when the content expands
|
||||||
|
Item {
|
||||||
|
id: anchor
|
||||||
|
height: parent.height
|
||||||
|
width: 200 * scaling
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: mainContainer
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.leftMargin: Style.marginS * scaling
|
||||||
|
anchors.rightMargin: Style.marginS * scaling
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
anchors.centerIn: parent
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
active: Settings.data.audio.showMiniplayerCava && Settings.data.audio.visualizerType == "linear"
|
active: Settings.data.audio.showMiniplayerCava && Settings.data.audio.visualizerType == "linear"
|
||||||
&& MediaService.isPlaying && MediaService.trackLength > 0
|
&& MediaService.isPlaying
|
||||||
z: 0
|
z: 0
|
||||||
|
|
||||||
sourceComponent: LinearSpectrum {
|
sourceComponent: LinearSpectrum {
|
||||||
width: mediaMini.width - Style.marginS * scaling
|
width: mainContainer.width - Style.marginS * scaling
|
||||||
height: 20 * scaling
|
height: 20 * scaling
|
||||||
values: CavaService.values
|
values: CavaService.values
|
||||||
fillColor: Color.mOnSurfaceVariant
|
fillColor: Color.mOnSurfaceVariant
|
||||||
|
|
@ -55,13 +72,15 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
anchors.centerIn: parent
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
active: Settings.data.audio.showMiniplayerCava && Settings.data.audio.visualizerType == "mirrored"
|
active: Settings.data.audio.showMiniplayerCava && Settings.data.audio.visualizerType == "mirrored"
|
||||||
&& MediaService.isPlaying && MediaService.trackLength > 0
|
&& MediaService.isPlaying
|
||||||
z: 0
|
z: 0
|
||||||
|
|
||||||
sourceComponent: MirroredSpectrum {
|
sourceComponent: MirroredSpectrum {
|
||||||
width: mediaMini.width - Style.marginS * scaling
|
width: mainContainer.width - Style.marginS * scaling
|
||||||
height: mediaMini.height - Style.marginS * scaling
|
height: mainContainer.height - Style.marginS * scaling
|
||||||
values: CavaService.values
|
values: CavaService.values
|
||||||
fillColor: Color.mOnSurfaceVariant
|
fillColor: Color.mOnSurfaceVariant
|
||||||
opacity: 0.4
|
opacity: 0.4
|
||||||
|
|
@ -69,50 +88,59 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
anchors.centerIn: parent
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
active: Settings.data.audio.showMiniplayerCava && Settings.data.audio.visualizerType == "wave"
|
active: Settings.data.audio.showMiniplayerCava && Settings.data.audio.visualizerType == "wave"
|
||||||
&& MediaService.isPlaying && MediaService.trackLength > 0
|
&& MediaService.isPlaying
|
||||||
z: 0
|
z: 0
|
||||||
|
|
||||||
sourceComponent: WaveSpectrum {
|
sourceComponent: WaveSpectrum {
|
||||||
width: mediaMini.width - Style.marginS * scaling
|
width: mainContainer.width - Style.marginS * scaling
|
||||||
height: mediaMini.height - Style.marginS * scaling
|
height: mainContainer.height - Style.marginS * scaling
|
||||||
values: CavaService.values
|
values: CavaService.values
|
||||||
fillColor: Color.mOnSurfaceVariant
|
fillColor: Color.mOnSurfaceVariant
|
||||||
opacity: 0.4
|
opacity: 0.4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Main Content Layout ---
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: contentLayout
|
id: rowLayout
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.leftMargin: Style.marginS * scaling
|
|
||||||
spacing: Style.marginS * scaling
|
spacing: Style.marginS * scaling
|
||||||
z: 1
|
z: 1 // Above the visualizer
|
||||||
|
|
||||||
NIcon {
|
NIcon {
|
||||||
id: windowIcon
|
id: windowIcon
|
||||||
text: MediaService.isPlaying ? "pause" : "play_arrow"
|
text: MediaService.isPlaying ? "pause" : "play_arrow"
|
||||||
font.pointSize: Style.fontSizeL * scaling
|
font.pointSize: Style.fontSizeL * scaling
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
visible: !Settings.data.audio.showMiniplayerAlbumArt && getTitle() !== "" && !trackArt.visible
|
visible: !Settings.data.audio.showMiniplayerAlbumArt && getTitle() !== "" && !trackArt.visible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
visible: Settings.data.audio.showMiniplayerAlbumArt
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.preferredWidth: Math.round(18 * scaling)
|
||||||
|
Layout.preferredHeight: Math.round(18 * scaling)
|
||||||
|
|
||||||
NImageCircled {
|
NImageCircled {
|
||||||
id: trackArt
|
id: trackArt
|
||||||
|
anchors.fill: parent
|
||||||
imagePath: MediaService.trackArtUrl
|
imagePath: MediaService.trackArtUrl
|
||||||
fallbackIcon: MediaService.isPlaying ? "pause" : "play_arrow"
|
fallbackIcon: MediaService.isPlaying ? "pause" : "play_arrow"
|
||||||
borderWidth: 0
|
borderWidth: 0
|
||||||
border.color: Color.transparent
|
border.color: Color.transparent
|
||||||
Layout.preferredWidth: Math.round(18 * scaling)
|
}
|
||||||
Layout.preferredHeight: Math.round(18 * scaling)
|
}
|
||||||
Layout.alignment: Qt.AlignVCenter
|
|
||||||
visible: Settings.data.audio.showMiniplayerAlbumArt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
id: titleText
|
id: titleText
|
||||||
|
|
||||||
Layout.preferredWidth: {
|
Layout.preferredWidth: {
|
||||||
if (mouseArea.containsMouse) {
|
if (mouseArea.containsMouse) {
|
||||||
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.maxWidth * scaling))
|
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.maxWidth * scaling))
|
||||||
|
|
@ -120,12 +148,14 @@ RowLayout {
|
||||||
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.minWidth * scaling))
|
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.minWidth * scaling))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
|
||||||
text: getTitle()
|
text: getTitle()
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
font.pointSize: Style.fontSizeS * scaling
|
||||||
font.weight: Style.fontWeightMedium
|
font.weight: Style.fontWeightMedium
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
color: Color.mTertiary
|
color: Color.mTertiary
|
||||||
Layout.alignment: Qt.AlignVCenter
|
|
||||||
|
|
||||||
Behavior on Layout.preferredWidth {
|
Behavior on Layout.preferredWidth {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
|
|
@ -136,6 +166,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mouse area for hover detection
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
@ -147,12 +178,15 @@ RowLayout {
|
||||||
MediaService.playPause()
|
MediaService.playPause()
|
||||||
} else if (mouse.button == Qt.RightButton) {
|
} else if (mouse.button == Qt.RightButton) {
|
||||||
MediaService.next()
|
MediaService.next()
|
||||||
|
// Need to hide the tooltip instantly
|
||||||
tooltip.visible = false
|
tooltip.visible = false
|
||||||
} else if (mouse.button == Qt.MiddleButton) {
|
} else if (mouse.button == Qt.MiddleButton) {
|
||||||
MediaService.previous()
|
MediaService.previous()
|
||||||
|
// Need to hide the tooltip instantly
|
||||||
tooltip.visible = false
|
tooltip.visible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntered: {
|
onEntered: {
|
||||||
if (tooltip.text !== "") {
|
if (tooltip.text !== "") {
|
||||||
tooltip.show()
|
tooltip.show()
|
||||||
|
|
@ -163,20 +197,21 @@ RowLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NTooltip {
|
NTooltip {
|
||||||
id: tooltip
|
id: tooltip
|
||||||
text: {
|
text: {
|
||||||
var str = ""
|
var str = ""
|
||||||
if (MediaService.canGoNext) {
|
if (MediaService.canGoNext) {
|
||||||
str += "Right click for next\n"
|
str += "Right click for next.\n"
|
||||||
}
|
}
|
||||||
if (MediaService.canGoPrevious) {
|
if (MediaService.canGoPrevious) {
|
||||||
str += "Middle click for previous\n"
|
str += "Middle click for previous."
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
target: mediaMini
|
target: anchor
|
||||||
positionAbove: Settings.data.bar.position === "bottom"
|
positionAbove: Settings.data.bar.position === "bottom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue