Skip to content

Commit

Permalink
fix: gridView tab switched too quickly
Browse files Browse the repository at this point in the history
Limit the interval between repeated clicks

Issue: linuxdeepin/developer-center#10481
  • Loading branch information
mhduiy committed Aug 27, 2024
1 parent d1e03a9 commit 7397779
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
20 changes: 19 additions & 1 deletion qml/GridViewContainer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ FocusScope {
clip: true
highlightFollowsCurrentItem: true
keyNavigationEnabled: true
highlightMoveDuration: 150
highlightMoveDuration: 100
activeFocusOnTab: focus ? root.activeGridViewFocusOnTab : false
focus: count > 0
onActiveFocusChanged: {
Expand Down Expand Up @@ -128,6 +128,24 @@ FocusScope {
// not wroking
move: root.itemMove
moveDisplaced: root.itemMove

Keys.onPressed: function (event) {
if (event.key === Qt.Key_Left ||
event.key === Qt.Key_Right ||
event.key === Qt.Key_Up ||
event.key === Qt.Key_Down) {

if (!keyTimer.running) {
keyTimer.start()
} else {
event.accepted = true
}
}
}
Timer {
id: keyTimer
interval: 100
}
}
}

Expand Down
21 changes: 15 additions & 6 deletions qml/windowed/GridViewContainer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ FocusScope {

interactive: false
highlightFollowsCurrentItem: true
highlightMoveDuration: 100
keyNavigationEnabled: true
activeFocusOnTab: focus ? root.activeGridViewFocusOnTab : false
focus: count > 0
Expand Down Expand Up @@ -96,14 +97,22 @@ FocusScope {
}

Keys.onPressed: function (event) {
if (event.key === Qt.Key_Right && currentIndex === gridView.count - 1) {
gridView.currentIndex = 0;
event.accepted = true;
} else if (event.key === Qt.Key_Left && currentIndex === 0) {
currentIndex = gridView.count - 1;
event.accepted = true;
if (event.key === Qt.Key_Left ||
event.key === Qt.Key_Right ||
event.key === Qt.Key_Up ||
event.key === Qt.Key_Down) {

if (!keyTimer.running) {
keyTimer.start()
} else {
event.accepted = true
}
}
}
Timer {
id: keyTimer
interval: 100
}
}
}
}

0 comments on commit 7397779

Please sign in to comment.