From 41eea44fffd631b9d92a2d2a8fb932cef10b5e94 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 20 Jul 2019 18:08:58 -0400 Subject: [PATCH] Add keyboard shortcuts to flick the events list --- TODO.md | 2 ++ src/qml/Chat/Timeline/EventList.qml | 1 + src/qml/Shortcuts.qml | 37 +++++++++++++++++++++++++++++ src/qml/UI.qml | 2 -- src/qml/Window.qml | 6 ++--- 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src/qml/Shortcuts.qml diff --git a/TODO.md b/TODO.md index 73a99d44..3642faec 100644 --- a/TODO.md +++ b/TODO.md @@ -12,12 +12,14 @@ - When qml syntax highlighting supports string interpolation, use them - Fixes + - Don't strip user spacing in html - Past events loading (limit 100) freezes the GUI - need to move upsert func to a WorkerScript - `MessageDelegate.qml:63: TypeError: 'reloadPreviousItem' not a function` - Horrible performance for big rooms - UI + - Adapt shortcuts flicking speed to font size and DPI - Show error box if uploading avatar fails - EditAccount page: - Device settings diff --git a/src/qml/Chat/Timeline/EventList.qml b/src/qml/Chat/Timeline/EventList.qml index b525e836..8ce9688d 100644 --- a/src/qml/Chat/Timeline/EventList.qml +++ b/src/qml/Chat/Timeline/EventList.qml @@ -14,6 +14,7 @@ HRectangle { HListView { id: eventList clip: true + Component.onCompleted: shortcuts.flickTarget = eventList function canCombine(item, itemAfter) { if (! item || ! itemAfter) { return false } diff --git a/src/qml/Shortcuts.qml b/src/qml/Shortcuts.qml new file mode 100644 index 00000000..18d74056 --- /dev/null +++ b/src/qml/Shortcuts.qml @@ -0,0 +1,37 @@ +// Copyright 2019 miruka +// This file is part of harmonyqml, licensed under LGPLv3. + +import QtQuick 2.12 + +Item { + property Item flickTarget: Item {} + + function smartVerticalFlick(baseVelocity, fastMultiply=3) { + let vel = flickTarget.verticalVelocity + + if (flickTarget.verticalLayoutDirection == ListView.BottomToTop) { + baseVelocity = -baseVelocity + vel = -vel + } + + let fast = (baseVelocity < 0 && vel < baseVelocity / 2) || + (baseVelocity > 0 && vel > baseVelocity / 2) + + flickTarget.flick(0, baseVelocity * (fast ? fastMultiply : 1)) + } + + Shortcut { + sequences: ["Alt+Up", "Alt+K"] + onActivated: smartVerticalFlick(-335) + } + + Shortcut { + sequences: ["Alt+Down", "Alt+J"] + onActivated: smartVerticalFlick(335) + } + + Shortcut { + sequence: "Alt+Shift+D" + onActivated: if (window.debug) { py.call("APP.pdb") } + } +} diff --git a/src/qml/UI.qml b/src/qml/UI.qml index b1b52dc0..2ccc69bb 100644 --- a/src/qml/UI.qml +++ b/src/qml/UI.qml @@ -98,7 +98,5 @@ Item { popExit: null pushExit: null } - - Keys.onEscapePressed: if (window.debug) { py.call("APP.pdb") } } } diff --git a/src/qml/Window.qml b/src/qml/Window.qml index 174ae870..3faf07ed 100644 --- a/src/qml/Window.qml +++ b/src/qml/Window.qml @@ -31,9 +31,9 @@ ApplicationWindow { property var settings: ({}) onSettingsChanged: py.saveSettings() - Theme { id: theme } - - Python { id: py } + Theme { id: theme } + Shortcuts { id: shortcuts} + Python { id: py } // Models Accounts { id: accounts }