@@ -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
@@ -100,6 +136,19 @@ Popup {
100136 activeFocusOnTab: gridViewFocus
101137 }
102138
139+ Item {
140+ id: focusRouter
141+ focus: root .visible
142+ Keys .onPressed : function (event ) {
143+ if (event .key === Qt .Key_Left ||
144+ event .key === Qt .Key_Right ||
145+ event .key === Qt .Key_Up ||
146+ event .key === Qt .Key_Down ) {
147+ alphabetCategoryContainer .focus = true
148+ }
149+ }
150+ }
151+
103152 background: FloatingPanel {
104153 radius: DStyle .Style .popup .radius
105154 dropShadowColor: null
0 commit comments