mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-07 12:25:15 +00:00
MediaCard: Using the new NContextMenu
This commit is contained in:
@@ -32,11 +32,11 @@ NBox {
|
|||||||
color: Color.mPrimary
|
color: Color.mPrimary
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
}
|
}
|
||||||
NText {
|
// NText {
|
||||||
text: "No media player detected"
|
// text: "No media player detected"
|
||||||
color: Color.mOnSurfaceVariant
|
// color: Color.mOnSurfaceVariant
|
||||||
Layout.alignment: Qt.AlignHCenter
|
// Layout.alignment: Qt.AlignHCenter
|
||||||
}
|
// }
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@@ -51,98 +51,71 @@ NBox {
|
|||||||
visible: MediaService.currentPlayer && MediaService.canPlay
|
visible: MediaService.currentPlayer && MediaService.canPlay
|
||||||
spacing: Style.marginM * scaling
|
spacing: Style.marginM * scaling
|
||||||
|
|
||||||
// Player selector
|
// Player selector using NContextMenu
|
||||||
ComboBox {
|
Rectangle {
|
||||||
id: playerSelector
|
id: playerSelectorButton
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: Style.barHeight * 0.83 * scaling
|
Layout.preferredHeight: Style.barHeight * scaling
|
||||||
visible: MediaService.getAvailablePlayers().length > 1
|
visible: MediaService.getAvailablePlayers().length > 1
|
||||||
model: MediaService.getAvailablePlayers()
|
radius: Style.radiusM * scaling
|
||||||
textRole: "identity"
|
color: Color.transparent
|
||||||
currentIndex: MediaService.selectedPlayerIndex
|
|
||||||
|
|
||||||
background: Rectangle {
|
property var currentPlayer: MediaService.getAvailablePlayers()[MediaService.selectedPlayerIndex]
|
||||||
visible: false
|
|
||||||
// implicitWidth: 120 * scaling
|
|
||||||
// implicitHeight: 30 * scaling
|
|
||||||
color: Color.transparent
|
|
||||||
border.color: playerSelector.activeFocus ? Color.mSecondary : Color.mOutline
|
|
||||||
border.width: Math.max(1, Style.borderS * scaling)
|
|
||||||
radius: Style.radiusM * scaling
|
|
||||||
}
|
|
||||||
|
|
||||||
contentItem: NText {
|
RowLayout {
|
||||||
visible: false
|
anchors.fill: parent
|
||||||
leftPadding: Style.marginM * scaling
|
spacing: Style.marginS * scaling
|
||||||
rightPadding: playerSelector.indicator.width + playerSelector.spacing
|
|
||||||
text: playerSelector.displayText
|
|
||||||
font.pointSize: Style.fontSizeXS * scaling
|
|
||||||
color: Color.mOnSurface
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
elide: Text.ElideRight
|
|
||||||
}
|
|
||||||
|
|
||||||
indicator: NIcon {
|
NIcon {
|
||||||
x: playerSelector.width - width
|
icon: "caret-down"
|
||||||
y: playerSelector.topPadding + (playerSelector.availableHeight - height) / 2
|
font.pointSize: Style.fontSizeXXL * scaling
|
||||||
icon: "caret-down"
|
color: Color.mOnSurfaceVariant
|
||||||
font.pointSize: Style.fontSizeXXL * scaling
|
|
||||||
color: Color.mOnSurface
|
|
||||||
horizontalAlignment: Text.AlignRight
|
|
||||||
}
|
|
||||||
|
|
||||||
popup: Popup {
|
|
||||||
id: popup
|
|
||||||
x: playerSelector.width * 0.5
|
|
||||||
y: playerSelector.height * 0.75
|
|
||||||
width: playerSelector.width * 0.5
|
|
||||||
implicitHeight: Math.min(160 * scaling, contentItem.implicitHeight + Style.marginM * 2 * scaling)
|
|
||||||
padding: Style.marginS * scaling
|
|
||||||
|
|
||||||
onOpened: {
|
|
||||||
PanelService.willOpenPopup(root)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onClosed: {
|
NText {
|
||||||
PanelService.willClosePopup(root)
|
text: playerSelectorButton.currentPlayer ? playerSelectorButton.currentPlayer.identity : ""
|
||||||
}
|
font.pointSize: Style.fontSizeXS * scaling
|
||||||
|
color: Color.mOnSurfaceVariant
|
||||||
contentItem: NListView {
|
Layout.fillWidth: true
|
||||||
implicitHeight: contentHeight
|
|
||||||
model: playerSelector.popup.visible ? playerSelector.delegateModel : null
|
|
||||||
currentIndex: playerSelector.highlightedIndex
|
|
||||||
horizontalPolicy: ScrollBar.AlwaysOff
|
|
||||||
verticalPolicy: ScrollBar.AsNeeded
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: Color.mSurface
|
|
||||||
border.color: Color.mOutline
|
|
||||||
border.width: Math.max(1, Style.borderS * scaling)
|
|
||||||
radius: Style.radiusS * scaling
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: ItemDelegate {
|
MouseArea {
|
||||||
width: playerSelector.width
|
id: playerSelectorMouseArea
|
||||||
highlighted: playerSelector.highlightedIndex === index
|
anchors.fill: parent
|
||||||
background: Rectangle {
|
hoverEnabled: true
|
||||||
width: popup.width - Style.marginS * scaling * 2
|
cursorShape: Qt.PointingHandCursor
|
||||||
color: highlighted ? Color.mTertiary : Color.transparent
|
|
||||||
radius: Style.radiusXS * scaling
|
onClicked: {
|
||||||
}
|
// Create menu items from available players
|
||||||
contentItem: NText {
|
var menuItems = []
|
||||||
text: modelData.identity
|
var players = MediaService.getAvailablePlayers()
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
for (var i = 0; i < players.length; i++) {
|
||||||
color: highlighted ? Color.mOnTertiary : Color.mOnSurface
|
menuItems.push({
|
||||||
verticalAlignment: Text.AlignVCenter
|
label: players[i].identity,
|
||||||
elide: Text.ElideRight
|
action: i.toString(),
|
||||||
|
icon: "disc",
|
||||||
|
enabled: true,
|
||||||
|
visible: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
playerContextMenu.model = menuItems
|
||||||
|
playerContextMenu.openAtItem(playerSelectorButton, playerSelectorButton.width - playerContextMenu.width, playerSelectorButton.height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivated: {
|
NContextMenu {
|
||||||
MediaService.selectedPlayerIndex = currentIndex
|
id: playerContextMenu
|
||||||
MediaService.updateCurrentPlayer()
|
parent: root
|
||||||
|
width: 200 * scaling
|
||||||
|
|
||||||
|
onTriggered: function(action) {
|
||||||
|
var index = parseInt(action)
|
||||||
|
if (!isNaN(index)) {
|
||||||
|
MediaService.selectedPlayerIndex = index
|
||||||
|
MediaService.updateCurrentPlayer()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +173,7 @@ NBox {
|
|||||||
NText {
|
NText {
|
||||||
visible: MediaService.trackArtist !== ""
|
visible: MediaService.trackArtist !== ""
|
||||||
text: MediaService.trackArtist
|
text: MediaService.trackArtist
|
||||||
color: Color.mOnSurface
|
color: Color.mPrimary
|
||||||
font.pointSize: Style.fontSizeXS * scaling
|
font.pointSize: Style.fontSizeXS * scaling
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|||||||
Reference in New Issue
Block a user