Skip to content

Commit a4d25d7

Browse files
committed
fix: improve folder grid view navigation and focus handling
1. Changed from onCurrentIndexChanged to onCurrentItemChanged for focus reset to ensure target page is loaded before setting focus 2. Added pendingFocusIndex property to track desired focus position when switching pages 3. Enhanced resetGridFocus function to handle focus index calculation and delayed execution via Qt.callLater 4. Added left/right key navigation for both grid view modes (icon and list) to enable cross-page navigation 5. Implemented circular navigation within pages and between pages 6. Improved model count detection to handle different model types (count property vs rowCount method) Log: Improved folder navigation with keyboard arrow keys and fixed focus issues when switching pages Influence: 1. Test left/right arrow key navigation within a folder page 2. Verify focus correctly transfers when navigating between pages using arrow keys 3. Test circular navigation when reaching page boundaries 4. Verify focus position is maintained when switching pages 5. Test with empty folders and single-page folders 6. Verify both icon view and list view modes work correctly 7. Test focus behavior when quickly switching between pages fix: 改进文件夹网格视图导航和焦点处理 1. 将焦点重置从 onCurrentIndexChanged 改为 onCurrentItemChanged,确保目 标页面加载完成后再设置焦点 2. 添加 pendingFocusIndex 属性来跟踪切换页面时所需的焦点位置 3. 增强 resetGridFocus 函数,通过 Qt.callLater 处理焦点索引计算和延迟 执行 4. 为两种网格视图模式(图标和列表)添加左右键导航功能,支持跨页面导航 5. 实现页面内和页面间的循环导航 6. 改进模型数量检测,处理不同类型的模型(count 属性 vs rowCount 方法) Log: 改进文件夹导航,支持键盘方向键导航,修复切换页面时的焦点问题 Influence: 1. 测试文件夹页面内的左右方向键导航 2. 验证使用方向键在页面间导航时焦点是否正确转移 3. 测试到达页面边界时的循环导航 4. 验证切换页面时焦点位置是否正确保持 5. 测试空文件夹和单页文件夹的情况 6. 验证图标视图和列表视图模式都能正常工作 7. 测试快速切换页面时的焦点行为 PMS: BUG-333261 BUG-333255
1 parent 44f422c commit a4d25d7

1 file changed

Lines changed: 140 additions & 8 deletions

File tree

qml/FolderGridViewPopup.qml

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ Popup {
279279

280280
currentIndex: folderPageIndicator.currentIndex
281281
activeFocusOnTab: false
282-
283-
// 处理页面切换时的焦点传递
284-
onCurrentIndexChanged: {
282+
//达到起始和末尾应用按下左右键时进行标志,-1往左翻页(标志前一页的最后一个应用),0代表往右翻页(标志后一页的第一个应用)
283+
property int pendingFocusIndex: 0
284+
//这里不能使用onCurrentIndexChanged
285+
//由于如果目标页的 Loader/GridViewContainer 还没加载完成,这次设置焦点会被跳过 则默认焦点给到的页面本身而不是应用
286+
onCurrentItemChanged: {
285287
if (currentItem)
286-
currentItem.resetCurrentIndex()
288+
currentItem.resetCurrentIndex(pendingFocusIndex)
287289
}
288290

289291
Connections {
@@ -303,19 +305,41 @@ Popup {
303305
id: folderGridViewLoader
304306
objectName: "Folder GridView Loader"
305307

306-
function resetCurrentIndex() {
308+
function resetCurrentIndex(focusIndex) {
307309
if (item && item.resetGridFocus)
308-
item.resetGridFocus()
310+
item.resetGridFocus(focusIndex)
309311
}
310312

311313
sourceComponent: Rectangle {
312314
anchors.fill: parent
313315
color: "transparent"
314316

315-
function resetGridFocus() {
317+
function resetGridFocus(focusIndex) {
316318
if (gridViewContainerLoader && gridViewContainerLoader.item) {
317-
gridViewContainerLoader.item.currentIndex = 0
318319
gridViewContainerLoader.item.forceActiveFocus()
320+
Qt.callLater(function() {
321+
if (!gridViewContainerLoader || !gridViewContainerLoader.item)
322+
return
323+
324+
let count = 0
325+
if (gridViewContainerLoader.item.model) {
326+
if (gridViewContainerLoader.item.model.count !== undefined) {
327+
count = gridViewContainerLoader.item.model.count
328+
} else if (gridViewContainerLoader.item.model.rowCount) {
329+
count = gridViewContainerLoader.item.model.rowCount()
330+
}
331+
}
332+
let targetIndex = 0
333+
if (count > 0) {
334+
if (focusIndex < 0) {
335+
targetIndex = count - 1
336+
} else {
337+
targetIndex = Math.min(focusIndex, count - 1)
338+
}
339+
}
340+
gridViewContainerLoader.item.currentIndex = targetIndex
341+
folderPagesView.pendingFocusIndex = 0
342+
})
319343
}
320344
}
321345

@@ -372,6 +396,60 @@ Popup {
372396
currentIndex = 0
373397
}
374398
}
399+
Keys.onLeftPressed: function(event) {
400+
event.accepted = true
401+
402+
let count = sortProxyModel.count !== undefined ? sortProxyModel.count : (sortProxyModel.rowCount ? sortProxyModel.rowCount() : 0)
403+
if (count === 0) {
404+
return
405+
}
406+
407+
let current = folderGridViewContainer.currentIndex
408+
if (current > 0) {
409+
folderGridViewContainer.currentIndex = current - 1
410+
return
411+
}
412+
413+
let pageCount = folderPagesView.count
414+
if (pageCount <= 1) {
415+
folderGridViewContainer.currentIndex = count - 1
416+
return
417+
}
418+
419+
folderPagesView.pendingFocusIndex = -1
420+
if (folderPagesView.currentIndex === 0) {
421+
folderPagesView.setCurrentIndex(pageCount - 1)
422+
} else {
423+
folderPagesView.setCurrentIndex(folderPagesView.currentIndex - 1)
424+
}
425+
}
426+
Keys.onRightPressed: function(event) {
427+
event.accepted = true
428+
429+
let count = sortProxyModel.count !== undefined ? sortProxyModel.count : (sortProxyModel.rowCount ? sortProxyModel.rowCount() : 0)
430+
if (count === 0) {
431+
return
432+
}
433+
434+
let current = folderGridViewContainer.currentIndex
435+
if (current < count - 1) {
436+
folderGridViewContainer.currentIndex = current + 1
437+
return
438+
}
439+
440+
let pageCount = folderPagesView.count
441+
if (pageCount <= 1) {
442+
folderGridViewContainer.currentIndex = 0
443+
return
444+
}
445+
446+
folderPagesView.pendingFocusIndex = 0
447+
if (folderPagesView.currentIndex === (pageCount - 1)) {
448+
folderPagesView.setCurrentIndex(0)
449+
} else {
450+
folderPagesView.setCurrentIndex(folderPagesView.currentIndex + 1)
451+
}
452+
}
375453
delegate: DelegateDropArea {
376454
width: folderGridViewContainer.cellWidth
377455
height: folderGridViewContainer.cellHeight
@@ -401,6 +479,60 @@ Popup {
401479
currentIndex = 0
402480
}
403481
}
482+
Keys.onLeftPressed: function(event) {
483+
event.accepted = true
484+
485+
let count = sortProxyModel.count !== undefined ? sortProxyModel.count : (sortProxyModel.rowCount ? sortProxyModel.rowCount() : 0)
486+
if (count === 0) {
487+
return
488+
}
489+
490+
let current = folderGridViewContainer.currentIndex
491+
if (current > 0) {
492+
folderGridViewContainer.currentIndex = current - 1
493+
return
494+
}
495+
496+
let pageCount = folderPagesView.count
497+
if (pageCount <= 1) {
498+
folderGridViewContainer.currentIndex = count - 1
499+
return
500+
}
501+
502+
folderPagesView.pendingFocusIndex = -1
503+
if (folderPagesView.currentIndex === 0) {
504+
folderPagesView.setCurrentIndex(pageCount - 1)
505+
} else {
506+
folderPagesView.setCurrentIndex(folderPagesView.currentIndex - 1)
507+
}
508+
}
509+
Keys.onRightPressed: function(event) {
510+
event.accepted = true
511+
512+
let count = sortProxyModel.count !== undefined ? sortProxyModel.count : (sortProxyModel.rowCount ? sortProxyModel.rowCount() : 0)
513+
if (count === 0) {
514+
return
515+
}
516+
517+
let current = folderGridViewContainer.currentIndex
518+
if (current < count - 1) {
519+
folderGridViewContainer.currentIndex = current + 1
520+
return
521+
}
522+
523+
let pageCount = folderPagesView.count
524+
if (pageCount <= 1) {
525+
folderGridViewContainer.currentIndex = 0
526+
return
527+
}
528+
529+
folderPagesView.pendingFocusIndex = 0
530+
if (folderPagesView.currentIndex === (pageCount - 1)) {
531+
folderPagesView.setCurrentIndex(0)
532+
} else {
533+
folderPagesView.setCurrentIndex(folderPagesView.currentIndex + 1)
534+
}
535+
}
404536
delegate: DelegateDropArea {
405537
width: folderGridViewContainer.cellWidth
406538
height: folderGridViewContainer.cellHeight

0 commit comments

Comments
 (0)