[vlc-commits] [Git][videolan/vlc][master] 10 commits: qml: properly forward signals in TableViewDelegate
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Thu Jul 14 10:29:17 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
c688b880 by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: properly forward signals in TableViewDelegate
- - - - -
94eaf0f5 by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: move component customisation outside of TableViewDelegate
- - - - -
90d0d210 by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: move default TableViewDelegate column inside component
- - - - -
f21e1e59 by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: inject dragTarget dependency into TableViewDelegate
- - - - -
1255a4a5 by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: don't reference selection model from TableViewDelegate
- - - - -
4363b4ae by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: fix unqualified access in TableColumns
- - - - -
51e1173a by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: take rowModel and sortModel as parametter in TableViewDelegate
- - - - -
a8d67b9a by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: Component can't be set as undefined
- - - - -
a815e743 by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: factorize DragNDrop code in KeyNavigableView
drag N drop feature may be usefull outside playlist management, it remains
disabled by default. this also reduce the amount of duplicated code between generic
views and playlist views
- - - - -
e3730eae by Pierre Lamot at 2022-07-14T10:17:21+00:00
qml: remove obsolete PlaylistMediaDelegate file
- - - - -
10 changed files:
- modules/gui/qt/Makefile.am
- modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
- − modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml
- modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoAll.qml
- modules/gui/qt/vlc.qrc
- modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
- modules/gui/qt/widgets/qml/TableColumns.qml
- modules/gui/qt/widgets/qml/TableViewDelegate.qml
- po/POTFILES.in
Changes:
=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -790,7 +790,6 @@ libqt_plugin_la_QML = \
gui/qt/medialibrary/qml/VideoAllSubDisplay.qml \
gui/qt/medialibrary/qml/PlaylistMediaList.qml \
gui/qt/medialibrary/qml/PlaylistMedia.qml \
- gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml \
gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml \
gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml \
gui/qt/medialibrary/qml/VideoDisplayRecentVideos.qml \
=====================================
modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
=====================================
@@ -50,10 +50,10 @@ MainInterface.MainTableView {
rowHeight: VLCStyle.tableCoverRow_height
- delegate: PlaylistMediaDelegate {}
-
headerColor: VLCStyle.colors.bg
+ acceptDrop: true
+
sortModel: [{
criteria: "thumbnail",
@@ -89,6 +89,15 @@ MainInterface.MainTableView {
onActionForSelection: MediaLib.addAndPlay(model.getIdsForIndexes(selection))
onItemDoubleClicked: MediaLib.addAndPlay(model.id)
+
+ onDropEntered: root._dropUpdatePosition(drag, index, delegate, before)
+
+ onDropUpdatePosition: root._dropUpdatePosition(drag, index, delegate, before)
+
+ onDropExited: root.hideLine(delegate)
+
+ onDropEvent: root.applyDrop(drop, index, delegate, before)
+
//---------------------------------------------------------------------------------------------
// Connections
//---------------------------------------------------------------------------------------------
@@ -105,28 +114,44 @@ MainInterface.MainTableView {
//---------------------------------------------------------------------------------------------
// Drop interface
- function isDroppable(drop, index) {
+ function isDroppable(drop) {
// NOTE: Internal drop (intra-playlist).
return Helpers.isValidInstanceOf(drop.source, Widgets.DragItem);
}
- function applyDrop(drop, index) {
+ function applyDrop(drop, index, delegate, before) {
+ if (root.isDroppable(drop) === false) {
+ root.hideLine(delegate)
+ return
+ }
+
var item = drop.source;
+ var destinationIndex = before ? index : (index + 1)
+
// NOTE: Move implementation.
if (dragItem === item) {
- model.move(modelSelect.selectedIndexes, index);
+ model.move(modelSelect.selectedIndexes, destinationIndex)
// NOTE: Dropping medialibrary content into the playlist.
} else if (Helpers.isValidInstanceOf(item, Widgets.DragItem)) {
item.getSelectedInputItem(function(inputItems) {
- model.insert(inputItems, index);
+ model.insert(inputItems, destinationIndex)
})
}
- forceActiveFocus();
+ root.forceActiveFocus()
+
+ root.hideLine(delegate)
+ }
+
+ function _dropUpdatePosition(drag, index, delegate, before) {
+ if (root.isDroppable(drag) === false) {
+ root.hideLine(delegate)
+ return
+ }
- root.hideLine(_item);
+ root.showLine(delegate, before)
}
//---------------------------------------------------------------------------------------------
@@ -145,8 +170,6 @@ MainInterface.MainTableView {
line.y = view.mapFromItem(item, 0, 0).y;
else
line.y = view.mapFromItem(item, 0, item.height).y;
-
- line.visible = true;
}
function hideLine(item)
@@ -156,8 +179,6 @@ MainInterface.MainTableView {
return;
_item = null;
-
- line.visible = false;
}
//---------------------------------------------------------------------------------------------
@@ -192,7 +213,7 @@ MainInterface.MainTableView {
height: VLCStyle.dp(1)
- visible: false
+ visible: root._item !== null
color: VLCStyle.colors.accent
}
=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml deleted
=====================================
@@ -1,81 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2021 VLC authors and VideoLAN
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * ( at your option ) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-import QtQuick 2.11
-
-import "qrc:///widgets/" as Widgets
-
-Widgets.TableViewDelegate {
- id: delegate
-
- //---------------------------------------------------------------------------------------------
- // Functions
- //---------------------------------------------------------------------------------------------
-
- function _applyPosition(drag)
- {
- if (root.isDroppable(drag, index) === false) {
-
- root.hideLine(delegate);
-
- return;
- }
-
- if (index === _getDropIndex(drag.y))
- root.showLine(delegate, true);
- else
- root.showLine(delegate, false);
- }
-
- //---------------------------------------------------------------------------------------------
-
- function _getDropIndex(y)
- {
- var size = Math.round(height / 2);
-
- if (y < size)
- return index;
- else
- return index + 1;
- }
-
- //---------------------------------------------------------------------------------------------
- // Childs
- //---------------------------------------------------------------------------------------------
-
- // NOTE: We are using a single DropArea and a single line Rectangle in PlaylistMedia.
- DropArea {
- anchors.fill: parent
-
- onEntered: _applyPosition(drag)
-
- onPositionChanged: _applyPosition(drag)
-
- onExited: root.hideLine(delegate)
-
- onDropped: {
- if (isDroppable(drop, index) === false) {
- root.hideLine(delegate);
-
- return;
- }
-
- root.applyDrop(drop, _getDropIndex(drag.y));
- }
- }
-}
=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
=====================================
@@ -44,7 +44,7 @@ FocusScope {
property string initialName
// NOTE: Specify an optional header for the view.
- property Component header: undefined
+ property Component header: null
property Item headerItem: view.headerItem
=====================================
modules/gui/qt/medialibrary/qml/VideoAll.qml
=====================================
@@ -39,9 +39,9 @@ FocusScope {
: 0
// NOTE: Specify an optional header for the view.
- property Component header: undefined
+ property Component header: null
- property Item headerItem: (_currentView) ? _currentView.headerItem : undefined
+ property Item headerItem: (_currentView) ? _currentView.headerItem : null
readonly property int currentIndex: _currentView.currentIndex
=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -302,7 +302,6 @@
<file alias="VideoAllSubDisplay.qml">medialibrary/qml/VideoAllSubDisplay.qml</file>
<file alias="PlaylistMediaList.qml">medialibrary/qml/PlaylistMediaList.qml</file>
<file alias="PlaylistMedia.qml">medialibrary/qml/PlaylistMedia.qml</file>
- <file alias="PlaylistMediaDelegate.qml">medialibrary/qml/PlaylistMediaDelegate.qml</file>
<file alias="PlaylistMediaDisplay.qml">medialibrary/qml/PlaylistMediaDisplay.qml</file>
<file alias="VideoPlaylistsDisplay.qml">medialibrary/qml/VideoPlaylistsDisplay.qml</file>
<file alias="MusicAlbumsDisplay.qml">medialibrary/qml/MusicAlbumsDisplay.qml</file>
=====================================
modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
=====================================
@@ -34,27 +34,6 @@ FocusScope {
property var sortModel: []
- property Component colDelegate: Widgets.ScrollingText {
- id: textRect
-
- property var rowModel: parent.rowModel
- property var model: parent.colModel
- property color foregroundColor: parent.foregroundColor
-
- label: text
- forceScroll: parent.currentlyFocused
- width: parent.width
- clip: scrolling
-
- Widgets.ListLabel {
- id: text
-
- anchors.verticalCenter: parent.verticalCenter
- text: !rowModel ? "" : (rowModel[model.criteria] || "")
- color: textRect.foregroundColor
- }
- }
-
property Component tableHeaderDelegate: Widgets.CaptionLabel {
text: model.text || ""
}
@@ -86,6 +65,7 @@ FocusScope {
- (VLCStyle.margin_xxxsmall * 2)
property Item dragItem
+ property bool acceptDrop: false
// Aliases
@@ -136,6 +116,11 @@ FocusScope {
signal rightClick(Item menuParent, var menuModel, point globalMousePos)
signal itemDoubleClicked(var index, var model)
+ signal dropUpdatePosition(Item delegate, int index, var drag, bool before)
+ signal dropEntered(Item delegate, int index, var drag, bool before)
+ signal dropExited(Item delegate, int index, var drag, bool before)
+ signal dropEvent(Item delegate, int index, var drag, var drop, bool before)
+
// Settings
Accessible.role: Accessible.Table
@@ -331,7 +316,7 @@ FocusScope {
Item {
// placeholder for context button
- width: root._contextButtonHorizontalSpace
+ width: VLCStyle.icon_normal
height: 1
}
@@ -348,7 +333,52 @@ FocusScope {
color: VLCStyle.colors.accent
}
- delegate: TableViewDelegate {}
+ delegate: TableViewDelegate {
+ id: tableDelegate
+
+ width: view.width
+ height: root.rowHeight
+
+ horizontalSpacing: root.horizontalSpacing
+ leftPadding: Math.max(0, view.width - root.usedRowSpace) / 2 + root.sectionWidth
+
+ dragItem: root.dragItem
+
+ rowModel: model
+ sortModel: root.sortModel
+
+ selected: selectionDelegateModel.isSelected(root.model.index(index, 0))
+
+ acceptDrop: root.acceptDrop
+
+ onContextMenuButtonClicked: root.contextMenuButtonClicked(menuParent, menuModel, globalMousePos)
+ onRightClick: root.rightClick(menuParent, menuModel, globalMousePos)
+ onItemDoubleClicked: root.itemDoubleClicked(index, model)
+
+ onDropEntered: root.dropEntered(tableDelegate, index, drag, before)
+ onDropUpdatePosition: root.dropUpdatePosition(tableDelegate, index, drag, before)
+ onDropExited: root.dropExited(tableDelegate, index, drag, before)
+ onDropEvent: root.dropEvent(tableDelegate, index, drag, drop, before)
+
+ onSelectAndFocus: {
+ selectionDelegateModel.updateSelection(modifiers, view.currentIndex, index)
+
+ view.currentIndex = index
+ view.positionViewAtIndex(index, ListView.Contain)
+
+ tableDelegate.forceActiveFocus(focusReason)
+ }
+
+ Connections {
+ target: selectionDelegateModel
+
+ onSelectionChanged: {
+ tableDelegate.selected = Qt.binding(function() {
+ return selectionDelegateModel.isSelected(root.model.index(index, 0))
+ })
+ }
+ }
+ }
flickableDirection: Flickable.AutoFlickDirection
contentWidth: root.usedRowSpace + root.sectionWidth
=====================================
modules/gui/qt/widgets/qml/TableColumns.qml
=====================================
@@ -40,10 +40,13 @@ Item {
}
property Component titleDelegate: RowLayout {
+ id: titleDel
+
property var rowModel: parent.rowModel
property var model: parent.colModel
readonly property bool containsMouse: parent.containsMouse
readonly property bool currentlyFocused: parent.currentlyFocused
+ readonly property color foregroundColor: parent.foregroundColor
anchors.fill: parent
spacing: VLCStyle.margin_normal
@@ -63,17 +66,17 @@ Item {
source: {
var cover = null
- if (!!rowModel) {
+ if (!!titleDel.rowModel) {
if (root.showTitleText)
- cover = rowModel.cover
+ cover = titleDel.rowModel.cover
else
- cover = rowModel[model.criteria]
+ cover = titleDel.rowModel[titleDel.model.criteria]
}
- return cover || model.placeHolder || VLCStyle.noArtAlbumCover
+ return cover || titleDel.model.placeHolder || VLCStyle.noArtAlbumCover
}
- playCoverVisible: (currentlyFocused || containsMouse)
+ playCoverVisible: (titleDel.currentlyFocused || titleDel.containsMouse)
playIconSize: VLCStyle.play_cover_small
- onPlayIconClicked: g_mainDisplay.play(MediaLib, rowModel.id)
+ onPlayIconClicked: g_mainDisplay.play(MediaLib, titleDel.rowModel.id)
radius: root.titleCover_radius
imageOverlay: Item {
@@ -89,7 +92,7 @@ Item {
rightMargin: VLCStyle.margin_xxsmall
}
- labels: root.titlecoverLabels(rowModel)
+ labels: root.titlecoverLabels(titleDel.rowModel)
}
}
}
@@ -110,13 +113,18 @@ Item {
id: text
anchors.verticalCenter: parent.verticalCenter
- text: (!rowModel || !root.showTitleText) ? "" : (rowModel[model.criteria] || I18n.qtr("Unknown Title"))
- color: foregroundColor
+ text: (titleDel.rowModel && root.showTitleText)
+ ? (titleDel.rowModel[titleDel.model.criteria] || I18n.qtr("Unknown Title"))
+ : ""
+ color: titleDel.foregroundColor
}
}
}
property Component titleHeaderDelegate: Row {
+ id: titleHeadDel
+ property var model: parent.colModel
+
spacing: VLCStyle.margin_normal
Widgets.IconLabel {
@@ -127,7 +135,9 @@ Item {
}
Widgets.CaptionLabel {
- text: model.text || ""
+ text: titleHeadDel.model
+ ? titleHeadDel.model.text || ""
+ : ""
visible: root.showTitleText
}
}
@@ -140,15 +150,20 @@ Item {
}
property Component timeColDelegate: Item {
+ id: timeDel
+
property var rowModel: parent.rowModel
property var model: parent.colModel
+ property color foregroundColor: parent.foregroundColor
Widgets.ListLabel {
width: timeTextMetric.width
height: parent.height
horizontalAlignment: Text.AlignHCenter
- text: !rowModel || !rowModel[model.criteria] ? "" : Helpers.msToString(rowModel[model.criteria], true)
- color: foregroundColor
+ text: (!timeDel.rowModel || !timeDel.rowModel[timeDel.model.criteria])
+ ? ""
+ : Helpers.msToString(timeDel.rowModel[timeDel.model.criteria], true)
+ color: timeDel.foregroundColor
}
}
=====================================
modules/gui/qt/widgets/qml/TableViewDelegate.qml
=====================================
@@ -28,9 +28,10 @@ T.Control {
// Properties
- property var rowModel: model
+ property var rowModel
+ property var sortModel
- property bool selected: selectionDelegateModel.isSelected(root.model.index(index, 0))
+ property bool selected: false
readonly property int _index: index
@@ -38,38 +39,51 @@ T.Control {
readonly property bool dragActive: hoverArea.drag.active
- // Settings
-
- width: Math.max(view.width, content.implicitWidth) + root.sectionWidth
+ property int horizontalSpacing: 0
- height: root.rowHeight
+ property var dragItem
- leftPadding: Math.max(0, view.width - root.usedRowSpace) / 2 + root.sectionWidth
+ property bool acceptDrop: false
- hoverEnabled: true
-
- ListView.delayRemove: dragActive
+ signal contextMenuButtonClicked(Item menuParent, var menuModel, point globalMousePos)
+ signal rightClick(Item menuParent, var menuModel, point globalMousePos)
+ signal itemDoubleClicked(var index, var model)
- function selectAndFocus(modifiers, focusReason) {
- selectionDelegateModel.updateSelection(modifiers, view.currentIndex, index)
+ signal selectAndFocus(int modifiers, int focusReason)
- view.currentIndex = index
- view.positionViewAtIndex(index, ListView.Contain)
+ signal dropEntered(var drag, bool before)
+ signal dropUpdatePosition(var drag, bool before)
+ signal dropExited(var drag, bool before)
+ signal dropEvent(var drag, var drop, bool before)
- delegate.forceActiveFocus(focusReason)
- }
+ property Component defaultDelegate: Widgets.ScrollingText {
+ id: defaultDelId
+ property var rowModel: parent.rowModel
+ property var colModel: parent.colModel
+ property color foregroundColor: parent.foregroundColor
- // Connections
+ label: text
+ forceScroll: parent.currentlyFocused
+ width: parent.width
+ clip: scrolling
- Connections {
- target: selectionDelegateModel
+ Widgets.ListLabel {
+ id: text
- onSelectionChanged: {
- delegate.selected = Qt.binding(function() {
- return selectionDelegateModel.isSelected(root.model.index(index, 0))
- })
+ anchors.verticalCenter: parent.verticalCenter
+ text: defaultDelId.rowModel
+ ? (defaultDelId.rowModel[defaultDelId.colModel.criteria] || "")
+ : ""
+ color: defaultDelId.foregroundColor
}
}
+ // Settings
+
+ hoverEnabled: true
+
+ ListView.delayRemove: dragActive
+
+
// Childs
@@ -98,11 +112,11 @@ T.Control {
hoverEnabled: false
- Keys.onMenuPressed: root.contextMenuButtonClicked(contextButton,rowModel)
+ Keys.onMenuPressed: delegate.contextMenuButtonClicked(contextButton, delegate.rowModel)
acceptedButtons: Qt.RightButton | Qt.LeftButton
- drag.target: root.dragItem
+ drag.target: delegate.dragItem
drag.axis: Drag.XAndYAxis
@@ -116,7 +130,7 @@ T.Control {
}
if (mouse.button === Qt.RightButton)
- root.rightClick(delegate, rowModel, hoverArea.mapToGlobal(mouse.x, mouse.y))
+ delegate.rightClick(delegate, delegate.rowModel, hoverArea.mapToGlobal(mouse.x, mouse.y))
}
onPositionChanged: {
@@ -131,21 +145,19 @@ T.Control {
onDoubleClicked: {
if (mouse.button === Qt.LeftButton)
- root.itemDoubleClicked(delegate._index, rowModel)
+ delegate.itemDoubleClicked(delegate._index, delegate.rowModel)
}
drag.onActiveChanged: {
// NOTE: Perform the "click" action because the click action is only executed on mouse
// release (we are in the pressed state) but we will need the updated list on drop.
if (drag.active && !delegate.selected) {
- selectionDelegateModel.updateSelection(_modifiersOnLastPress
- , view.currentIndex
- , index)
- } else if (root.dragItem) {
- root.dragItem.Drag.drop()
+ delegate.selectAndFocus(_modifiersOnLastPress, index)
+ } else if (delegate.dragItem) {
+ delegate.dragItem.Drag.drop()
}
- root.dragItem.Drag.active = drag.active
+ delegate.dragItem.Drag.active = drag.active
}
}
}
@@ -156,10 +168,10 @@ T.Control {
leftPadding: VLCStyle.margin_xxxsmall
rightPadding: VLCStyle.margin_xxxsmall
- spacing: root.horizontalSpacing
+ spacing: delegate.horizontalSpacing
Repeater {
- model: sortModel
+ model: delegate.sortModel
Loader{
property var rowModel: delegate.rowModel
@@ -179,12 +191,12 @@ T.Control {
height: parent.height
sourceComponent: (colModel.colDelegate) ? colModel.colDelegate
- : root.colDelegate
+ : delegate.defaultDelegate
}
}
Item {
- width: root._contextButtonHorizontalSpace
+ width: VLCStyle.icon_normal
height: parent.height
@@ -195,7 +207,7 @@ T.Control {
iconText: VLCIcons.ellipsis
- size: root._contextButtonHorizontalSpace
+ size: VLCStyle.icon_normal
visible: delegate.hovered
@@ -204,9 +216,28 @@ T.Control {
delegate.selectAndFocus(Qt.NoModifier, Qt.MouseFocusReason)
var pos = contextButton.mapToGlobal(VLCStyle.margin_xsmall, contextButton.height / 2 + VLCStyle.fontHeight_normal)
- root.contextMenuButtonClicked(this, delegate.rowModel, pos)
+ delegate.contextMenuButtonClicked(this, delegate.rowModel, pos)
}
}
}
}
+
+ DropArea {
+ enabled: delegate.acceptDrop
+
+ anchors.fill: parent
+
+ function isBefore(drag) {
+ return drag.y < height/2
+ }
+
+ onEntered: delegate.dropEntered(drag, isBefore(drag))
+
+ onPositionChanged: delegate.dropUpdatePosition(drag, isBefore(drag))
+
+ onExited:delegate.dropExited(drag, isBefore(drag))
+
+ onDropped: delegate.dropEvent(drag, drop, isBefore(drag))
+
+ }
}
=====================================
po/POTFILES.in
=====================================
@@ -812,7 +812,6 @@ modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml
modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
-modules/gui/qt/medialibrary/qml/PlaylistMediaDelegate.qml
modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
modules/gui/qt/medialibrary/qml/UrlListDisplay.qml
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/75b0d4458d5e2185d0df93ffee7fc708704a0dc5...e3730eaef8f40efb04a131fce1f4b5acd42f607a
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/75b0d4458d5e2185d0df93ffee7fc708704a0dc5...e3730eaef8f40efb04a131fce1f4b5acd42f607a
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list