1 /*****************************************************************************
2 * Copyright (C) 2021 VLC authors and VideoLAN
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * ( at your option ) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17 *****************************************************************************/
20 import QtQuick.Layouts 1.3
22 import "qrc:///widgets/" as Widgets
23 import "qrc:///style/"
28 //---------------------------------------------------------------------------------------------
30 //---------------------------------------------------------------------------------------------
32 property var rowModel: model
34 property bool selected: selectionDelegateModel.isSelected(root.model.index(index, 0))
36 readonly property bool highlighted: (selected || hoverArea.containsMouse || activeFocus)
38 readonly property int _index: index
40 property int _modifiersOnLastPress: Qt.NoModifier
42 readonly property color foregroundColor: (highlighted) ? VLCStyle.colors.bgHoverText
43 : VLCStyle.colors.text
45 //---------------------------------------------------------------------------------------------
47 //---------------------------------------------------------------------------------------------
51 height: root.rowHeight
53 color: (highlighted) ? VLCStyle.colors.bgHover
56 //---------------------------------------------------------------------------------------------
58 //---------------------------------------------------------------------------------------------
61 target: selectionDelegateModel
64 delegate.selected = selectionDelegateModel.isSelected(root.model.index(index, 0));
68 //---------------------------------------------------------------------------------------------
70 //---------------------------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------------------
82 Keys.onMenuPressed: root.contextMenuButtonClicked(contextButton,rowModel)
84 acceptedButtons: Qt.RightButton | Qt.LeftButton
86 drag.target: root.dragItem
88 drag.axis: Drag.XAndYAxis
90 //-----------------------------------------------------------------------------------------
93 onPressed: _modifiersOnLastPress = mouse.modifiers
96 if (mouse.button === Qt.LeftButton
98 selectionDelegateModel.isSelected(root.model.index(index, 0)) == false) {
100 selectionDelegateModel.updateSelection(mouse.modifiers, view.currentIndex, index);
102 view.currentIndex = index;
104 delegate.forceActiveFocus();
107 if (mouse.button === Qt.RightButton)
108 root.rightClick(delegate, rowModel, hoverArea.mapToGlobal(mouse.x, mouse.y));
112 if (drag.active == false)
115 var pos = drag.target.parent.mapFromItem(hoverArea, mouseX, mouseY);
117 // FIXME: Shouldn't this be specified in VLCStyle ?
118 var delta = VLCStyle.dp(12);
120 drag.target.x = pos.x + delta;
121 drag.target.y = pos.y + delta;
125 if (mouse.button === Qt.LeftButton)
126 root.itemDoubleClicked(delegate._index, rowModel)
129 drag.onActiveChanged: {
130 // NOTE: Perform the "click" action because the click action is only executed on mouse
131 // release (we are in the pressed state) but we will need the updated list on drop.
134 selectionDelegateModel.isSelected(root.model.index(index, 0)) == false) {
136 selectionDelegateModel.updateSelection(_modifiersOnLastPress, view.currentIndex,
138 } else if (root.dragItem) {
139 root.dragItem.Drag.drop();
142 root.dragItem.Drag.active = drag.active;
145 //-----------------------------------------------------------------------------------------
151 anchors.top : parent.top
152 anchors.bottom: parent.bottom
154 anchors.leftMargin : VLCStyle.margin_xxxsmall
155 anchors.rightMargin : VLCStyle.margin_xxxsmall
156 anchors.topMargin : VLCStyle.margin_xxsmall
157 anchors.bottomMargin: VLCStyle.margin_xxsmall
159 anchors.horizontalCenter: parent.horizontalCenter
161 anchors.horizontalCenterOffset: Math.round(-(root._contextButtonHorizontalSpace) / 2)
163 spacing: root.horizontalSpacing
169 height: parent.height
171 width: (modelData.width) ? modelData.width
174 Layout.alignment: Qt.AlignVCenter
176 SmoothedAnimation on width {
179 easing.type: Easing.OutCubic
183 property var rowModel: delegate.rowModel
184 property var colModel: modelData
186 readonly property int index: delegate._index
188 readonly property bool currentlyFocused: delegate.activeFocus
190 readonly property bool containsMouse: hoverArea.containsMouse
192 readonly property color foregroundColor: delegate.foregroundColor
196 sourceComponent: (colModel.colDelegate) ? colModel.colDelegate
203 Widgets.ContextButton {
204 anchors.left: content.right
206 anchors.leftMargin: VLCStyle.margin_xxsmall
208 anchors.verticalCenter: content.verticalCenter
210 color: delegate.foregroundColor
212 backgroundColor: (hovered || activeFocus)
213 ? VLCStyle.colors.getBgColor(delegate.selected, hovered, activeFocus)
216 visible: hoverArea.containsMouse
218 onClicked: root.contextMenuButtonClicked(this, delegate.rowModel)