diff --git a/ui/qml/xstudio/application/panels/media/XsMediaPanel.qml b/ui/qml/xstudio/application/panels/media/XsMediaPanel.qml index 3e25159c8..d65e2e329 100644 --- a/ui/qml/xstudio/application/panels/media/XsMediaPanel.qml +++ b/ui/qml/xstudio/application/panels/media/XsMediaPanel.qml @@ -49,6 +49,13 @@ Item{ propertyNames: ["is_list_view", "cellSize"] } + signal frameSelectedMedia() + + // object in which to store container scroll positions + property var scrollKeeper + Component.onCompleted: scrollKeeper = new Object() + + /************************************************************** HotKeys ****************************************************************/ diff --git a/ui/qml/xstudio/application/panels/media/grid_view/XsMediaGrid.qml b/ui/qml/xstudio/application/panels/media/grid_view/XsMediaGrid.qml index 3e73aa535..ab45c5e60 100644 --- a/ui/qml/xstudio/application/panels/media/grid_view/XsMediaGrid.qml +++ b/ui/qml/xstudio/application/panels/media/grid_view/XsMediaGrid.qml @@ -55,6 +55,18 @@ XsGridView { // what row is the on-screen media? var row = mediaListModelData.getRowWithMatchingRoleData(onScreenMediaUuid, "actorUuidRole") + + return autoScrollToRow(row) + } + + function autoScrollToSelectedMedia() { + if (visible && mediaSelectionModel.selectedIndexes.length) { + var row = mediaSelectionModel.selectedIndexes[0].row + return autoScrollToRow(row) + } + } + + function autoScrollToRow(row) { if (row == -1) return var num_cols = Math.floor(width/cellWidth) > 0 ? Math.floor(width/cellWidth) : 1 @@ -66,7 +78,14 @@ XsGridView { autoScrollAnimator.to = Math.max(originY, Math.min(mid - mediaList.height/2, mediaList.contentHeight - mediaList.height)) autoScrollAnimator.running = true + } + Connections { + target: panel + enabled: visible + function onFrameSelectedMedia() { + autoScrollToSelectedMedia() + } } XsLabel { @@ -301,4 +320,8 @@ XsGridView { if (!running && mediaList.contentY > originY) start() } } -} \ No newline at end of file + + XsMediaScrollKeeper { + prefix: "G" + } +} diff --git a/ui/qml/xstudio/application/panels/media/list_view/XsMediaList.qml b/ui/qml/xstudio/application/panels/media/list_view/XsMediaList.qml index 7629e4303..0eec19e4d 100644 --- a/ui/qml/xstudio/application/panels/media/list_view/XsMediaList.qml +++ b/ui/qml/xstudio/application/panels/media/list_view/XsMediaList.qml @@ -89,6 +89,18 @@ XsListView { // what row is the on-screen media? var row = mediaListModelData.getRowWithMatchingRoleData(onScreenMediaUuid, "actorUuidRole") + + return autoScrollToRow(row) + } + + function autoScrollToSelectedMedia() { + if (visible && mediaSelectionModel.selectedIndexes.length) { + var row = mediaSelectionModel.selectedIndexes[0].row + return autoScrollToRow(row) + } + } + + function autoScrollToRow(row) { if (row == -1) return // what is the Y coordinate of the media item within the media list? @@ -100,7 +112,14 @@ XsListView { autoScrollAnimator.to = Math.max(originY, Math.min(mid - mediaList.height/2, mediaList.contentHeight - mediaList.height)) autoScrollAnimator.running = true + } + Connections { + target: panel + enabled: visible + function onFrameSelectedMedia() { + autoScrollToSelectedMedia() + } } XsMediaListMouseArea { @@ -337,4 +356,7 @@ XsListView { } } + XsMediaScrollKeeper { + prefix: "L" + } } diff --git a/ui/qml/xstudio/application/panels/media/widgets/XsMediaHotKeys.qml b/ui/qml/xstudio/application/panels/media/widgets/XsMediaHotKeys.qml index b506e5f2b..75e66106a 100644 --- a/ui/qml/xstudio/application/panels/media/widgets/XsMediaHotKeys.qml +++ b/ui/qml/xstudio/application/panels/media/widgets/XsMediaHotKeys.qml @@ -313,6 +313,16 @@ XsHotkeyArea { componentName: "Media List" } + XsHotkey { + id: frame_hotkey + sequence: "F" + name: "Frame Selected" + description: "Frame Selected" + context: hotkey_area.context + onActivated: frameSelectedMedia() + componentName: "Media List" + } + // add hotkeys for setting flag colours Repeater { model: flagColours.length diff --git a/ui/qml/xstudio/application/panels/media/widgets/XsMediaScrollKeeper.qml b/ui/qml/xstudio/application/panels/media/widgets/XsMediaScrollKeeper.qml new file mode 100644 index 000000000..8bcdaf5d9 --- /dev/null +++ b/ui/qml/xstudio/application/panels/media/widgets/XsMediaScrollKeeper.qml @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: Apache-2.0 +import QtQuick + +import xStudio 1.0 + +Item { + id: widget + property string prefix: "" + + // + // Here is the logic to remember the scrolled position per container. + // This assumes that somewhere in the parent hierarchy is a dictionary + // property named scrollKeeper into which the scroll data is kept. + // + + // machanism to stash the contentY before it gets erased + // when a new container is selected + property real storeContentY: 0 + Connections { + target: mediaListModelData + enabled: visible + function onModelAboutToBeReset() { + storeContentY = contentY + } + } + + // machanism to store and restore the scroll position + // whenever the current container changes + Connections { + target: sessionSelectionModel + enabled: visible + function onCurrentChanged(cur_idx, prev_idx) { + if (prev_idx.valid && storeContentY) { + let key = prefix + theSessionData.get(prev_idx, "idRole") + scrollKeeper[key] = storeContentY + storeContentY = 0 + } + + let key = prefix + inspectedMediaSetProperties.values.idRole + if (typeof scrollKeeper == "object" && scrollKeeper.hasOwnProperty(key)) { + contentY = scrollKeeper[key] + } + } + } + + // machanisms to store and restore the scroll position + // whenever the mode is changed between grid and list + Component.onDestruction: { + let id_ = inspectedMediaSetProperties.values.idRole + if (id_ && typeof scrollKeeper == "object" ) { + let key = prefix + id_ + scrollKeeper[key] = contentY + } + } + Component.onCompleted: { + let id_ = inspectedMediaSetProperties.values.idRole + if (id_) { + let key = prefix + id_ + if (typeof scrollKeeper == "object" && scrollKeeper.hasOwnProperty(key)) + contentY = scrollKeeper[key] + } + } +} diff --git a/ui/qml/xstudio/qml.qrc b/ui/qml/xstudio/qml.qrc index dd8fc79a5..13d3481da 100644 --- a/ui/qml/xstudio/qml.qrc +++ b/ui/qml/xstudio/qml.qrc @@ -66,6 +66,7 @@ application/panels/media/widgets/XsMediaListContextMenu.qml application/panels/media/widgets/XsMediaListSwitchSourceMenu.qml application/panels/media/widgets/XsMediaHotKeys.qml + application/panels/media/widgets/XsMediaScrollKeeper.qml application/panels/media/delegates/XsMediaThumbnailHighlight.qml application/panels/media/delegates/XsMediaThumbnailImage.qml