Debian Codegraph @

rc/qml/Components/CheckerboardDelegate.qml

raw
1 /*
2 * Copyright (C) 2012-2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Charles Lindsay <[email protected]>
18 */
19
20 import QtQuick 2.9
21 import "../../js/GalleryUtility.js" as GalleryUtility
22
23 // A child delegate for a Checkerboard. Tightly coupled to Checkerboard due to
24 // some required interactions (e.g. selection). This is a separate component
25 // so you can define your own.
26 Item {
27 id: checkerboardDelegate
28 // This name is checked for in Checkerboard.getDelegateInstanceAt(). Please
29 // don't modify it.
30 objectName: "checkerboardDelegate"
31
32 /*!
33 */
34 signal swipeStarted(bool leftToRight, int start)
35 /*!
36 */
37 signal swiping(bool leftToRight, int start, int distance)
38 /*!
39 */
40 signal swiped(bool leftToRight)
41 /*!
42 */
43 signal longPressed(variant object)
44
45 /*!
46 */
47 property variant checkerboard // The owning Checkerboard.
48 // This delegate encompasses the content + the gutter. content is the item
49 // (sized checkerboard.itemWidth/Height) inside the gutter. It will be
50 // reparented internally so it's positioned correctly.
51 property Item content
52 /*!
53 */
54 property bool contentIsSwipable: false
55 // Whether to apply the default selection highlighting internally.
56 property bool useInternalSelectionHighlight: true
57 /*!
58 */
59 property bool isEnabled: true
60
61 // readonly
62 /*!
63 */
64 property variant modelData: model
65 // Also needed for Checkerboard.getDelegateInstanceAt().
66 property int index: modelData.index
67 /*!
68 */
69 property bool isSelected: modelData.isSelected
70
71 width: checkerboard.delegateWidth
72 height: checkerboard.delegateHeight
73
74 Component.onCompleted: {
75 if (content)
76 content.parent = contentArea;
77 }
78
79 Item {
80 id: contentArea
81
82 width: checkerboard.itemWidth
83 height: checkerboard.itemHeight
84 anchors.centerIn: parent
85
86 // Long press/right click.
87 function alternativePressed() {
88 checkerboard.selection.toggleSelection(modelData.object);
89 longPressed(modelData.object);
90 }
91
92 // Normal press/click.
93 function pressed() {
94 var rect = GalleryUtility.getRectRelativeTo(contentArea, checkerboard);
95 checkerboard.activated(modelData.object, modelData, rect, checkerboardDelegate);
96 }
97
98 MouseArea {
99 id: mouseArea
100
101 anchors.fill: parent
102
103 visible: !contentIsSwipable && checkerboardDelegate.isEnabled
104
105 acceptedButtons: Qt.LeftButton | Qt.RightButton
106
107 onPressAndHold: contentArea.alternativePressed()
108 onClicked: {
109 if (mouse.button == Qt.RightButton || checkerboard.selection.inSelectionMode)
110 contentArea.alternativePressed();
111 else
112 contentArea.pressed();
113 }
114 }
115
116 SwipeArea {
117 id: swipeArea
118
119 anchors.fill: parent
120
121 visible: contentIsSwipable && checkerboardDelegate.isEnabled
122
123 onLongPressed: contentArea.alternativePressed()
124 onTapped: {
125 if (rightButton || checkerboard.selection.inSelectionMode)
126 contentArea.alternativePressed();
127 else
128 contentArea.pressed();
129 }
130 onStartSwipe: checkerboardDelegate.swipeStarted(leftToRight, start)
131 onSwiping: checkerboardDelegate.swiping(leftToRight, start, distance)
132 onSwiped: checkerboardDelegate.swiped(leftToRight)
133 }
134 }
135 }