Debian Codegraph @

plugins/ubuntu-plugin/imports/components/private/ContextDelegate.qml

raw
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 import QtQuick 2.4
19 import QtQuick.Controls.Suru 2.2
20
21 import Lomiri.Components 1.3
22 import Dekko.Components 1.0
23 import Dekko.Lomiri.Components 1.0
24
25 ListItem {
26 id: root
27 height: ctxtLayout.height
28 divider.visible: false
29 color: Suru.secondaryBackgroundColor
30 property string description
31 property alias actionIcon: leadingImage.name
32 property alias actionIconColor: leadingImage.color
33 property alias selectedIcon: trailingImage.name
34 property alias selectedIconColor: trailingImage.color
35 property alias selected: trailingImage.visible
36
37 // So aparently trying to show a highlight on mouse over is
38 // a partcularly annoying thing! Just binding to MouseArea::containsMouse
39 // results in all delegates being highlighted on the context menu's completion
40 // So instead we have to late bind containsMouse using a short timer binding
41 // containsMouse to the highlight rectangle.
42 Rectangle {
43 id: h
44 property bool canShow: false
45 anchors.fill: parent
46 visible: false
47 color: Suru.neutralColor
48 }
49 MouseArea {
50 id: ma
51 anchors.fill: h
52 onClicked: root.clicked()
53 }
54 Binding {
55 target: h
56 property: "visible"
57 value: (ma.containsMouse || ma.pressed)
58 when: h.canShow
59 }
60 Timer {
61 id: bindTimer
62 interval: 250
63 repeat: false
64 onTriggered: {
65 h.canShow = true
66 ma.hoverEnabled = true
67 }
68 }
69
70 ListItemLayout {
71 id: ctxtLayout
72 height: units.gu(5)
73 title.text: description
74 CachedImage {
75 id: leadingImage
76 height: units.gu(3); width: height
77 SlotsLayout.position: SlotsLayout.Leading
78 }
79 CachedImage {
80 id: trailingImage
81 height: units.gu(3); width: height
82 }
83 }
84
85
86
87 Component.onCompleted: bindTimer.start()
88 }