Skip to content

Commit

Permalink
Inline key event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
trin94 committed Feb 1, 2024
1 parent 982afb9 commit 7ae149b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 415 deletions.
24 changes: 24 additions & 0 deletions qml/table/MpvqcCommentTable.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick
import QtQuick.Controls

import pyobjects
import shared


FocusScope {
Expand Down Expand Up @@ -49,4 +51,26 @@ FocusScope {
}

}

Shortcut {
sequence: 'e'
autoRepeat: false

onActivated: root.newCommentMenu.popupMenu()
}

Shortcut {
sequence: 'f'
autoRepeat: false

onActivated: root.mpvqcApplication.toggleFullScreen()
}

Shortcut {
sequence: 'Esc'
autoRepeat: false
enabled: root.mpvqcApplication.fullscreen

onActivated: root.mpvqcApplication.disableFullScreen()
}
}
52 changes: 45 additions & 7 deletions qml/table/MpvqcTable.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ListView {
readonly property var mpvqcClipboardPyObject: mpvqcApplication.mpvqcClipboardPyObject
readonly property var mpvqcKeyCommandGenerator: mpvqcApplication.mpvqcKeyCommandGenerator

property bool haveComments: root.mpvqcApplication.mpvqcCommentTable.count > 0
property bool currentlyEditing: root.mpvqcApplication.mpvqcCommentTable.editMode
property bool currentlyFullscreen: root.mpvqcApplication.fullscreen

property bool editMode: false

property var deleteCommentMessageBox: null
Expand Down Expand Up @@ -140,6 +144,19 @@ ListView {
root.model.import_comments(comments)
}

function _ignore(event: KeyEvent): bool {
const key = event.key
const modifiers = event.modifiers
return key === Qt.Key_Up
|| key === Qt.Key_Down
|| ( key === Qt.Key_Return && modifiers === Qt.NoModifier )
|| ( key === Qt.Key_Escape && modifiers === Qt.NoModifier )
|| ( key === Qt.Key_Delete && modifiers === Qt.NoModifier )
|| ( key === Qt.Key_Backspace && modifiers === Qt.NoModifier )
|| ( key === Qt.Key_F && modifiers === Qt.ControlModifier )
|| ( key === Qt.Key_C && modifiers === Qt.ControlModifier )
}

Connections {
target: root.model

Expand All @@ -161,19 +178,40 @@ ListView {
}
}

MpvqcTableEventHandler {
id: _handler
Shortcut {
sequence: 'return'
autoRepeat: false
enabled: !currentlyFullscreen && haveComments && !currentlyEditing

mpvqcCommentTable: root
mpvqcApplication: root.mpvqcApplication
onActivated: root.startEditing()
}

Shortcut {
sequence: 'delete'
autoRepeat: false
enabled: !currentlyFullscreen && haveComments

onActivated: root._requestDeleteRow(root.currentIndex)
}

Shortcut {
sequence: 'backspace'
autoRepeat: false
enabled: !currentlyFullscreen && haveComments

onActivated: root._requestDeleteRow(root.currentIndex)
}

onDeleteCommentPressed: root._requestDeleteRow(root.currentIndex)
Shortcut {
sequence: 'ctrl+c'
autoRepeat: false
enabled: !currentlyFullscreen && haveComments && !currentlyEditing

onCopyToClipboardPressed: root._copyCurrentCommentToClipboard()
onActivated: root._copyCurrentCommentToClipboard()
}

Keys.onPressed: (event) => {
if (_handler.ignore(event)) {
if (root._ignore(event)) {
return
}
const command = root.mpvqcKeyCommandGenerator.generateFrom(event)
Expand Down
117 changes: 0 additions & 117 deletions qml/table/MpvqcTableEventHandler.qml

This file was deleted.

Loading

0 comments on commit 7ae149b

Please sign in to comment.