Skip to content

Commit 1b3d6cd

Browse files
committed
feat: add focus with AlphabetCategory when change to another word.
as title. PMS-BUG-289159
1 parent 67784c6 commit 1b3d6cd

3 files changed

Lines changed: 70 additions & 5 deletions

File tree

qml/windowed/AlphabetCategoryPopup.qml

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Popup {
2222

2323
property alias existingSections: alphabetCategoryDelegateModel.model
2424
property int columns: 5
25+
property string currentCategory: ""
2526

2627
readonly property int cellWidth: 24
2728
readonly property int cellHeight: 24
@@ -31,6 +32,54 @@ Popup {
3132
width: alphabetCategoryContainer.width + 20
3233
height: alphabetCategoryContainer.height + 20
3334

35+
onOpened: {
36+
alphabetCategoryContainer.gridViewFocus = true
37+
alphabetCategoryContainer.focus = true
38+
alphabetCategoryContainer.showFocusHighlight = false
39+
}
40+
41+
// 弹窗关闭时清除焦点状态
42+
onClosed: {
43+
alphabetCategoryContainer.gridViewFocus = false
44+
alphabetCategoryContainer.focus = false
45+
alphabetCategoryContainer.showFocusHighlight = false
46+
}
47+
48+
function setCurrentCategory(category) {
49+
currentCategory = category
50+
// 使用Timer延迟设置,确保model已经更新
51+
setIndexTimer.category = category
52+
setIndexTimer.restart()
53+
}
54+
55+
Timer {
56+
id: setIndexTimer
57+
interval: 10
58+
property string category: ""
59+
onTriggered: {
60+
if (category !== "") {
61+
for (let i = 0; i < alphabetCategoryDelegateModel.model.length; i++) {
62+
if (alphabetCategoryDelegateModel.model[i] === category) {
63+
// 临时禁用高亮移动动画,直接跳转到目标位置
64+
var originalDuration = alphabetCategoryContainer.highlightMoveDuration
65+
alphabetCategoryContainer.highlightMoveDuration = 0
66+
alphabetCategoryContainer.currentIndex = i
67+
// 恢复原来的动画时间
68+
alphabetCategoryContainer.highlightMoveDuration = originalDuration
69+
break
70+
}
71+
}
72+
}
73+
}
74+
}
75+
76+
onCurrentCategoryChanged: {
77+
if (currentCategory !== "") {
78+
setIndexTimer.category = currentCategory
79+
setIndexTimer.restart()
80+
}
81+
}
82+
3483
DelegateModel {
3584
id: alphabetCategoryDelegateModel
3685

@@ -77,14 +126,14 @@ Popup {
77126
id: alphabetCategoryContainer
78127

79128
anchors.centerIn: parent
80-
81129
model: alphabetCategoryDelegateModel
82130
columns: root.columns
83131
rows: model.count / columns + (model.count % columns > 0 ? 1 : 0)
84132
cellWidth: root.cellWidth
85133
cellHeight: root.cellHeight
86134
paddingColumns: root.paddingColumns
87135
paddingRows: root.paddingRows
136+
showFocusHighlight: false
88137

89138
highlight: Item {
90139
FocusBoxBorder {
@@ -93,11 +142,18 @@ Popup {
93142
height: root.cellHeight
94143
radius: root.cellWidth / 2
95144
color: parent.palette.highlight
96-
visible: alphabetCategoryContainer.activeFocus
145+
visible: alphabetCategoryContainer.gridViewFocus && alphabetCategoryContainer.showFocusHighlight
97146
}
98147
}
99148

100-
activeFocusOnTab: gridViewFocus
149+
activeFocusOnTab: true
150+
151+
Keys.onTabPressed: {
152+
if (gridViewFocus) {
153+
showFocusHighlight = !showFocusHighlight
154+
event.accepted = true
155+
}
156+
}
101157
}
102158

103159
background: FloatingPanel {

qml/windowed/AppListView.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ FocusScope {
129129
onClicked: {
130130
if (CategorizedSortProxyModel.categoryType === CategorizedSortProxyModel.Alphabetary) {
131131
alphabetCategoryPopup.existingSections = CategorizedSortProxyModel.alphabetarySections()
132+
alphabetCategoryPopup.setCurrentCategory(section.toUpperCase())
132133
var mousePos = mapToItem(listView, mouseX, mouseY)
133134
var y = (mousePos.y + alphabetCategoryPopup.height) < listView.height ? mousePos.y : listView.height - alphabetCategoryPopup.height
134135
alphabetCategoryPopup.y = y
@@ -396,6 +397,7 @@ FocusScope {
396397

397398
onCategoryClicked: {
398399
scrollToAlphabetCategory(character)
400+
alphabetCategoryPopup.setCurrentCategory(character)
399401
close()
400402
}
401403

qml/windowed/GridViewContainer.qml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ FocusScope {
3131
property real cellHeight: 82
3232
property real cellWidth: 80
3333
property Transition itemMove
34+
property bool showFocusHighlight: true
3435

3536
readonly property alias currentItem: gridView.currentItem
3637
readonly property alias gridViewWidth: gridView.width
3738
property alias highlight: gridView.highlight
3839
property ScrollBar vScrollBar
40+
property alias currentIndex: gridView.currentIndex
41+
property alias highlightMoveDuration: gridView.highlightMoveDuration
3942

4043
function positionViewAtBeginning() {
4144
gridView.positionViewAtBeginning()
4245
}
4346

47+
function setCurrentIndex(index) {
48+
gridView.currentIndex = index
49+
}
50+
4451
function itemAt(x, y) {
4552
let point = mapToItem(gridView, x, y)
4653
return gridView.itemAt(point.x, point.y)
@@ -106,12 +113,12 @@ FocusScope {
106113
event.key === Qt.Key_Right ||
107114
event.key === Qt.Key_Up ||
108115
event.key === Qt.Key_Down) {
109-
110116
if (!keyTimer.running) {
111117
keyTimer.start()
112-
} else {
118+
}else{
113119
event.accepted = true
114120
}
121+
root.showFocusHighlight = true
115122
}
116123
}
117124
Timer {

0 commit comments

Comments
 (0)