Skip to content

Commit e7c3f40

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

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

qml/windowed/AlphabetCategoryPopup.qml

Lines changed: 36 additions & 0 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,41 @@ Popup {
3132
width: alphabetCategoryContainer.width + 20
3233
height: alphabetCategoryContainer.height + 20
3334

35+
function setCurrentCategory(category) {
36+
currentCategory = category
37+
// 使用Timer延迟设置,确保model已经更新
38+
setIndexTimer.category = category
39+
setIndexTimer.restart()
40+
}
41+
42+
Timer {
43+
id: setIndexTimer
44+
interval: 10
45+
property string category: ""
46+
onTriggered: {
47+
if (category !== "") {
48+
for (let i = 0; i < alphabetCategoryDelegateModel.model.length; i++) {
49+
if (alphabetCategoryDelegateModel.model[i] === category) {
50+
// 临时禁用高亮移动动画,直接跳转到目标位置
51+
var originalDuration = alphabetCategoryContainer.highlightMoveDuration
52+
alphabetCategoryContainer.highlightMoveDuration = 0
53+
alphabetCategoryContainer.currentIndex = i
54+
// 恢复原来的动画时间
55+
alphabetCategoryContainer.highlightMoveDuration = originalDuration
56+
break
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
onCurrentCategoryChanged: {
64+
if (currentCategory !== "") {
65+
setIndexTimer.category = currentCategory
66+
setIndexTimer.restart()
67+
}
68+
}
69+
3470
DelegateModel {
3571
id: alphabetCategoryDelegateModel
3672

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ FocusScope {
3636
readonly property alias gridViewWidth: gridView.width
3737
property alias highlight: gridView.highlight
3838
property ScrollBar vScrollBar
39+
property alias currentIndex: gridView.currentIndex
40+
property alias highlightMoveDuration: gridView.highlightMoveDuration
3941

4042
function positionViewAtBeginning() {
4143
gridView.positionViewAtBeginning()
4244
}
4345

46+
function setCurrentIndex(index) {
47+
gridView.currentIndex = index
48+
}
49+
4450
function itemAt(x, y) {
4551
let point = mapToItem(gridView, x, y)
4652
return gridView.itemAt(point.x, point.y)

0 commit comments

Comments
 (0)