Autoformat
This commit is contained in:
parent
51f1923e22
commit
724e55c37d
4 changed files with 132 additions and 138 deletions
|
|
@ -19,7 +19,7 @@ Variants {
|
||||||
readonly property real scaling: modelData ? ScalingService.scale(modelData) : 1.0
|
readonly property real scaling: modelData ? ScalingService.scale(modelData) : 1.0
|
||||||
|
|
||||||
active: Settings.isLoaded && modelData && modelData.name ? (Settings.data.bar.monitors.includes(modelData.name)
|
active: Settings.isLoaded && modelData && modelData.name ? (Settings.data.bar.monitors.includes(modelData.name)
|
||||||
|| (Settings.data.bar.monitors.length === 0)) : false
|
|| (Settings.data.bar.monitors.length === 0)) : false
|
||||||
|
|
||||||
sourceComponent: PanelWindow {
|
sourceComponent: PanelWindow {
|
||||||
screen: modelData || null
|
screen: modelData || null
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ NPanel {
|
||||||
property bool isSubMenu: false
|
property bool isSubMenu: false
|
||||||
property bool isHovered: false
|
property bool isHovered: false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function showAt(item, x, y) {
|
function showAt(item, x, y) {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
Logger.warn("TrayMenu", "anchorItem is undefined, won't show menu.")
|
Logger.warn("TrayMenu", "anchorItem is undefined, won't show menu.")
|
||||||
|
|
@ -36,8 +34,6 @@ NPanel {
|
||||||
|
|
||||||
// Use NPanel's open method instead of PopupWindow's visible
|
// Use NPanel's open method instead of PopupWindow's visible
|
||||||
open(screen)
|
open(screen)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideMenu() {
|
function hideMenu() {
|
||||||
|
|
@ -77,17 +73,17 @@ NPanel {
|
||||||
if (menu && opener.children && opener.children.values.length === 0) {
|
if (menu && opener.children && opener.children.values.length === 0) {
|
||||||
// Menu not ready, try again later
|
// Menu not ready, try again later
|
||||||
Qt.callLater(() => {
|
Qt.callLater(() => {
|
||||||
if (opener.children && opener.children.values.length > 0) {
|
if (opener.children && opener.children.values.length > 0) {
|
||||||
// Menu is now ready
|
// Menu is now ready
|
||||||
root.menuItemCount = opener.children.values.length
|
root.menuItemCount = opener.children.values.length
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (opener.children && opener.children.values.length > 0) {
|
} else if (opener.children && opener.children.values.length > 0) {
|
||||||
root.menuItemCount = opener.children.values.length
|
root.menuItemCount = opener.children.values.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Flickable {
|
Flickable {
|
||||||
id: flickable
|
id: flickable
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Style.marginS * scaling
|
anchors.margins: Style.marginS * scaling
|
||||||
|
|
@ -95,149 +91,149 @@ NPanel {
|
||||||
interactive: true
|
interactive: true
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
// Use a ColumnLayout to handle menu item arrangement
|
// Use a ColumnLayout to handle menu item arrangement
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: columnLayout
|
id: columnLayout
|
||||||
width: flickable.width
|
width: flickable.width
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: opener.children ? [...opener.children.values] : []
|
model: opener.children ? [...opener.children.values] : []
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
id: entry
|
id: entry
|
||||||
required property var modelData
|
required property var modelData
|
||||||
|
|
||||||
Layout.preferredWidth: parent.width
|
Layout.preferredWidth: parent.width
|
||||||
Layout.preferredHeight: {
|
Layout.preferredHeight: {
|
||||||
if (modelData?.isSeparator) {
|
if (modelData?.isSeparator) {
|
||||||
return 8 * scaling
|
return 8 * scaling
|
||||||
} else {
|
} else {
|
||||||
// Calculate based on text content
|
// Calculate based on text content
|
||||||
const textHeight = text.contentHeight || (Style.fontSizeS * scaling * 1.2)
|
const textHeight = text.contentHeight || (Style.fontSizeS * scaling * 1.2)
|
||||||
return Math.max(28 * scaling, textHeight + (Style.marginS * 2 * scaling))
|
return Math.max(28 * scaling, textHeight + (Style.marginS * 2 * scaling))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
color: Color.transparent
|
color: Color.transparent
|
||||||
property var subMenu: null
|
property var subMenu: null
|
||||||
|
|
||||||
NDivider {
|
NDivider {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
width: parent.width - (Style.marginM * scaling * 2)
|
width: parent.width - (Style.marginM * scaling * 2)
|
||||||
visible: modelData?.isSeparator ?? false
|
visible: modelData?.isSeparator ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
|
||||||
color: mouseArea.containsMouse ? Color.mTertiary : Color.transparent
|
|
||||||
radius: Style.radiusS * scaling
|
|
||||||
visible: !(modelData?.isSeparator ?? false)
|
|
||||||
|
|
||||||
RowLayout {
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: Style.marginM * scaling
|
color: mouseArea.containsMouse ? Color.mTertiary : Color.transparent
|
||||||
anchors.rightMargin: Style.marginM * scaling
|
radius: Style.radiusS * scaling
|
||||||
spacing: Style.marginS * scaling
|
visible: !(modelData?.isSeparator ?? false)
|
||||||
|
|
||||||
NText {
|
RowLayout {
|
||||||
id: text
|
anchors.fill: parent
|
||||||
Layout.fillWidth: true
|
anchors.leftMargin: Style.marginM * scaling
|
||||||
color: (modelData?.enabled
|
anchors.rightMargin: Style.marginM * scaling
|
||||||
?? true) ? (mouseArea.containsMouse ? Color.mOnTertiary : Color.mOnSurface) : Color.mOnSurfaceVariant
|
spacing: Style.marginS * scaling
|
||||||
text: modelData?.text !== "" ? modelData?.text.replace(/[\n\r]+/g, ' ') : "..."
|
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
NText {
|
||||||
verticalAlignment: Text.AlignVCenter
|
id: text
|
||||||
wrapMode: Text.WordWrap
|
Layout.fillWidth: true
|
||||||
|
color: (modelData?.enabled
|
||||||
|
?? true) ? (mouseArea.containsMouse ? Color.mOnTertiary : Color.mOnSurface) : Color.mOnSurfaceVariant
|
||||||
|
text: modelData?.text !== "" ? modelData?.text.replace(/[\n\r]+/g, ' ') : "..."
|
||||||
|
font.pointSize: Style.fontSizeS * scaling
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
Image {
|
||||||
|
Layout.preferredWidth: Style.marginL * scaling
|
||||||
|
Layout.preferredHeight: Style.marginL * scaling
|
||||||
|
source: modelData?.icon ?? ""
|
||||||
|
visible: (modelData?.icon ?? "") !== ""
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
}
|
||||||
|
|
||||||
|
NIcon {
|
||||||
|
text: modelData?.hasChildren ? "menu" : ""
|
||||||
|
font.pointSize: Style.fontSizeS * scaling
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
visible: modelData?.hasChildren ?? false
|
||||||
|
color: Color.mOnSurface
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Image {
|
MouseArea {
|
||||||
Layout.preferredWidth: Style.marginL * scaling
|
id: mouseArea
|
||||||
Layout.preferredHeight: Style.marginL * scaling
|
anchors.fill: parent
|
||||||
source: modelData?.icon ?? ""
|
hoverEnabled: true
|
||||||
visible: (modelData?.icon ?? "") !== ""
|
enabled: (modelData?.enabled ?? true) && !(modelData?.isSeparator ?? false) && root.visible
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
}
|
|
||||||
|
|
||||||
NIcon {
|
onClicked: {
|
||||||
text: modelData?.hasChildren ? "menu" : ""
|
if (modelData && !modelData.isSeparator && !modelData.hasChildren) {
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
modelData.triggered()
|
||||||
verticalAlignment: Text.AlignVCenter
|
root.hideMenu()
|
||||||
visible: modelData?.hasChildren ?? false
|
}
|
||||||
color: Color.mOnSurface
|
}
|
||||||
|
|
||||||
|
onEntered: {
|
||||||
|
if (!root.visible)
|
||||||
|
return
|
||||||
|
|
||||||
|
// Close all sibling submenus
|
||||||
|
for (var i = 0; i < columnLayout.children.length; i++) {
|
||||||
|
const sibling = columnLayout.children[i]
|
||||||
|
if (sibling !== entry && sibling?.subMenu) {
|
||||||
|
sibling.subMenu.hideMenu()
|
||||||
|
sibling.subMenu.destroy()
|
||||||
|
sibling.subMenu = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create submenu if needed
|
||||||
|
if (modelData?.hasChildren) {
|
||||||
|
if (entry.subMenu) {
|
||||||
|
entry.subMenu.hideMenu()
|
||||||
|
entry.subMenu.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create submenu using the same TrayMenu component
|
||||||
|
entry.subMenu = Qt.createComponent("TrayMenu.qml").createObject(root, {
|
||||||
|
"menu": modelData,
|
||||||
|
"anchorItem": entry,
|
||||||
|
"anchorX": entry.width,
|
||||||
|
"anchorY": 0,
|
||||||
|
"isSubMenu": true
|
||||||
|
})
|
||||||
|
|
||||||
|
if (entry.subMenu) {
|
||||||
|
entry.subMenu.open(screen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onExited: {
|
||||||
|
Qt.callLater(() => {
|
||||||
|
if (entry.subMenu && !entry.subMenu.isHovered) {
|
||||||
|
entry.subMenu.hideMenu()
|
||||||
|
entry.subMenu.destroy()
|
||||||
|
entry.subMenu = null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
Component.onDestruction: {
|
||||||
id: mouseArea
|
if (subMenu) {
|
||||||
anchors.fill: parent
|
subMenu.destroy()
|
||||||
hoverEnabled: true
|
subMenu = null
|
||||||
enabled: (modelData?.enabled ?? true) && !(modelData?.isSeparator ?? false) && root.visible
|
|
||||||
|
|
||||||
onClicked: {
|
|
||||||
if (modelData && !modelData.isSeparator && !modelData.hasChildren) {
|
|
||||||
modelData.triggered()
|
|
||||||
root.hideMenu()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntered: {
|
|
||||||
if (!root.visible)
|
|
||||||
return
|
|
||||||
|
|
||||||
// Close all sibling submenus
|
|
||||||
for (var i = 0; i < columnLayout.children.length; i++) {
|
|
||||||
const sibling = columnLayout.children[i]
|
|
||||||
if (sibling !== entry && sibling?.subMenu) {
|
|
||||||
sibling.subMenu.hideMenu()
|
|
||||||
sibling.subMenu.destroy()
|
|
||||||
sibling.subMenu = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create submenu if needed
|
|
||||||
if (modelData?.hasChildren) {
|
|
||||||
if (entry.subMenu) {
|
|
||||||
entry.subMenu.hideMenu()
|
|
||||||
entry.subMenu.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create submenu using the same TrayMenu component
|
|
||||||
entry.subMenu = Qt.createComponent("TrayMenu.qml").createObject(root, {
|
|
||||||
"menu": modelData,
|
|
||||||
"anchorItem": entry,
|
|
||||||
"anchorX": entry.width,
|
|
||||||
"anchorY": 0,
|
|
||||||
"isSubMenu": true
|
|
||||||
})
|
|
||||||
|
|
||||||
if (entry.subMenu) {
|
|
||||||
entry.subMenu.open(screen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onExited: {
|
|
||||||
Qt.callLater(() => {
|
|
||||||
if (entry.subMenu && !entry.subMenu.isHovered) {
|
|
||||||
entry.subMenu.hideMenu()
|
|
||||||
entry.subMenu.destroy()
|
|
||||||
entry.subMenu = null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onDestruction: {
|
|
||||||
if (subMenu) {
|
|
||||||
subMenu.destroy()
|
|
||||||
subMenu = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,4 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ Loader {
|
||||||
Logger.warn("NPanel", "Cannot toggle panel: invalid screen object")
|
Logger.warn("NPanel", "Cannot toggle panel: invalid screen object")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!active || isClosing) {
|
if (!active || isClosing) {
|
||||||
open(aScreen, buttonItem)
|
open(aScreen, buttonItem)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -70,7 +70,7 @@ Loader {
|
||||||
Logger.warn("NPanel", "Cannot open panel: invalid screen object")
|
Logger.warn("NPanel", "Cannot open panel: invalid screen object")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aScreen !== null) {
|
if (aScreen !== null) {
|
||||||
screen = aScreen
|
screen = aScreen
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue