Skip to content

Commit

Permalink
fix: Application tray position drift
Browse files Browse the repository at this point in the history
Bind the location of the application tray

Issue: linuxdeepin/developer-center#9603
  • Loading branch information
mhduiy authored and 18202781743 committed Jul 23, 2024
1 parent f08a9c7 commit 0331152
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
42 changes: 16 additions & 26 deletions panels/dock/tray/package/ActionShowStashDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ D.ToolButton {
leftPadding: itemPadding
rightPadding: itemPadding

property var itemGlobalPoint: {
var a = root
var x = 0, y = 0
while(a.parent) {
x += a.x
y += a.y
a = a.parent
}

return Qt.point(x + width / 2, y + height / 2)
}

onItemGlobalPointChanged: {
stashedPopup.collapsedBtnCenterPoint = itemGlobalPoint
}

states: [
State {
name: "opened"
Expand All @@ -55,32 +71,6 @@ D.ToolButton {
}

onClicked: {
switch (Panel.position) {
case Dock.Top: {
var point = root.mapToItem(null, root.width / 2, 0)
stashedPopup.popupX = Qt.binding(function () { return point.x - stashedPopup.width / 2 })
stashedPopup.popupY = Qt.binding(function () { return Panel.rootObject.dockSize + 10 })
break
}
case Dock.Bottom: {
var point = root.mapToItem(null, root.width / 2, 0)
stashedPopup.popupX = Qt.binding(function () { return point.x - stashedPopup.width / 2 })
stashedPopup.popupY = Qt.binding(function () { return -stashedPopup.height - 10 })
break
}
case Dock.Left: {
var point = root.mapToItem(null, 0, root.height / 2)
stashedPopup.popupX = Qt.binding(function () { return Panel.rootObject.dockSize + 10 })
stashedPopup.popupY = Qt.binding(function () { return point.y - stashedPopup.height / 2 })
break
}
case Dock.Right: {
var point = root.mapToItem(null, 0, root.height / 2)
stashedPopup.popupX = Qt.binding(function () { return -stashedPopup.width - 10 })
stashedPopup.popupY = Qt.binding(function () { return point.y - stashedPopup.height / 2 })
break
}
}
stashedPopup.open()
}
}
20 changes: 15 additions & 5 deletions panels/dock/tray/package/tray.qml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ AppletItem {
width: stashedContainer.width
height: stashedContainer.height

popupX: DockPanelPositioner.x
popupY: DockPanelPositioner.y

property point collapsedBtnCenterPoint: Qt.point(0, 0)

Control {
id: stashedContainer
contentItem: StashContainer {
Expand All @@ -116,15 +121,20 @@ AppletItem {
anchors.centerIn: parent
}
}

Component.onCompleted: {
DockPanelPositioner.bounding = Qt.binding(function () {
return Qt.rect(collapsedBtnCenterPoint.x, collapsedBtnCenterPoint.y, stashedPopup.width, stashedPopup.height)
})
}
}
Connections {
target: DDT.TraySortOrderModel
function onActionsAlwaysVisibleChanged(val) {
if (val) {
if (!stashedPopup.popupVisible) {
// TODO: position?
stashedPopup.open()
}
if (val && !stashedPopup.popupVisible) {
stashedPopup.open()
} else if (!val) {
stashedPopup.close()
}
}
}
Expand Down

0 comments on commit 0331152

Please sign in to comment.