Skip to content

Commit 80796ab

Browse files
committed
fix: missing FocusBorder for WindowButton in TitleBar
Refacting WindowButton, and use IconButton instead of Control to display the icon, support topRightRadiusfor last WindowButton. Fix missing hovered state for Controls in TitleBar. pms: TASK-368399
1 parent ff28ee0 commit 80796ab

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

qt6/src/qml/TitleBar.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ Item {
5252
palette.windowText: D.ColorSelector.textColor
5353

5454
HoverHandler {
55-
enabled: __isFullScreen && autoHideOnFullscreen
5655
id: hoverHandler
56+
// reset it's parent to disable HoverHandler
57+
parent: __isFullScreen && autoHideOnFullscreen ? control : null
5758
}
5859
TapHandler {
5960
acceptedButtons: Qt.RightButton | Qt.LeftButton

qt6/src/qml/WindowButton.qml

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,53 @@ import QtQuick
66
import org.deepin.dtk 1.0 as D
77
import org.deepin.dtk.style 1.0 as DS
88

9-
Control {
9+
D.IconButton {
1010
id: control
11-
property alias icon: iconLoader
12-
readonly property bool pressed: mouseArea.pressed
13-
signal clicked(var mouse)
14-
property D.Palette textColor: DS.Style.button.text
15-
property D.Palette backgroundColor: DS.Style.windowButton.background
1611

17-
palette.windowText: D.ColorSelector.textColor
18-
hoverEnabled: true
19-
contentItem: D.DciIcon {
20-
id: iconLoader
21-
palette: D.DTK.makeIconPalette(control.palette)
22-
sourceSize {
23-
width: DS.Style.windowButton.width
24-
height: DS.Style.windowButton.height
12+
property int topRightRadius: (Window.window.visibility !== Window.Maximized &&
13+
Window.window.visibility !== Window.FullScreen &&
14+
isOnRightEdgeOfWindow) ? D.DTK.platformTheme.windowRadius : 0
15+
readonly property bool isOnRightEdgeOfWindow: __itemGlobalPoint.x + control.width >= Window.window.width
16+
17+
readonly property var __itemGlobalPoint: {
18+
var a = control
19+
var x = 0, y = 0
20+
while(a.parent) {
21+
x += a.x
22+
y += a.y
23+
a = a.parent
2524
}
26-
mode: control.D.ColorSelector.controlState
27-
theme: control.D.ColorSelector.controlTheme
25+
return Qt.point(x, y)
2826
}
29-
MouseArea {
30-
id: mouseArea
31-
anchors.fill: parent
32-
Component.onCompleted: clicked.connect(control.clicked)
27+
28+
topPadding: 0
29+
bottomPadding: 0
30+
leftPadding: 0
31+
rightPadding: 0
32+
icon {
33+
width: DS.Style.windowButton.width
34+
height: DS.Style.windowButton.height
3335
}
34-
background: Rectangle {
36+
background: D.BoxPanel {
3537
implicitWidth: DS.Style.windowButton.width
3638
implicitHeight: DS.Style.windowButton.height
37-
color: control.D.ColorSelector.backgroundColor
39+
insideBorderColor: null
40+
outsideBorderColor: null
41+
color1: DS.Style.windowButton.background
42+
color2: color1
43+
radius: 0
44+
45+
Loader {
46+
anchors.fill: parent
47+
active: control.visualFocus
48+
sourceComponent: Rectangle {
49+
topRightRadius: control.topRightRadius
50+
color: "transparent"
51+
border {
52+
width: DS.Style.control.focusBorderWidth
53+
color: control.palette.highlight
54+
}
55+
}
56+
}
3857
}
3958
}

0 commit comments

Comments
 (0)