@@ -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 {
0 commit comments