Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/ListItem.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2010 Marco Martin <notmart@gmail.com> | ||||
3 | Copyright 2016 Jan Grulich <jgrulich@redhat.com> | ||||
4 | Copyright 2020 George Vogiatzis <gvgeo@protonmail.com> | ||||
5 | | ||||
6 | This library is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU Lesser General Public | ||||
8 | License as published by the Free Software Foundation; either | ||||
9 | version 2.1 of the License, or (at your option) version 3, or any | ||||
10 | later version accepted by the membership of KDE e.V. (or its | ||||
11 | successor approved by the membership of KDE e.V.), which shall | ||||
12 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
13 | | ||||
14 | This library is distributed in the hope that it will be useful, | ||||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
17 | Lesser General Public License for more details. | ||||
18 | | ||||
19 | You should have received a copy of the GNU Lesser General Public | ||||
20 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
21 | */ | ||||
22 | | ||||
23 | import QtQuick 2.1 | ||||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
25 | | ||||
26 | /** | ||||
27 | * Ignores the theme's listItem margins, and uses custom highlight(pressed) area. | ||||
28 | * Could break some themes but the majority look fine. | ||||
29 | * Also includes a separator to be used in sections. | ||||
30 | */ | ||||
31 | Item { | ||||
32 | id: listItem | ||||
33 | | ||||
34 | signal clicked | ||||
35 | | ||||
36 | property alias containsMouse: itemMouse.containsMouse | ||||
37 | property bool checked: false | ||||
38 | property bool separator: false | ||||
39 | property rect highlightRect: Qt.rect(0, 0, width, height) | ||||
40 | | ||||
41 | width: parent.width | ||||
42 | | ||||
43 | // Sections have spacing above but not below. Will use 2 of them below. | ||||
44 | height: separator ? separatorLine.height + units.smallSpacing * 3 : parent.height | ||||
45 | | ||||
46 | PlasmaCore.Svg { | ||||
47 | id: lineSvg | ||||
48 | imagePath: "widgets/line" | ||||
49 | } | ||||
50 | PlasmaCore.SvgItem { | ||||
51 | id: separatorLine | ||||
52 | anchors { | ||||
53 | horizontalCenter: parent.horizontalCenter | ||||
54 | top: parent.top | ||||
55 | topMargin: units.smallSpacing | ||||
56 | } | ||||
57 | elementId: "horizontal-line" | ||||
58 | width: parent.width - units.gridUnit * 2 | ||||
59 | svg: lineSvg | ||||
60 | visible: separator | ||||
61 | } | ||||
62 | | ||||
63 | PlasmaCore.FrameSvgItem { | ||||
64 | id : background | ||||
65 | imagePath: "widgets/listitem" | ||||
66 | prefix: "normal" | ||||
67 | anchors.fill: parent | ||||
68 | visible: separator ? false : true | ||||
69 | } | ||||
70 | | ||||
71 | PlasmaCore.FrameSvgItem { | ||||
72 | id : pressed | ||||
73 | imagePath: "widgets/listitem" | ||||
74 | prefix: "pressed" | ||||
75 | opacity: checked ? 1 : 0 | ||||
76 | Behavior on opacity { NumberAnimation { duration: units.shortDuration } } | ||||
77 | | ||||
78 | x: highlightRect.x | ||||
79 | y: highlightRect.y | ||||
80 | height: highlightRect.height | ||||
81 | width: highlightRect.width | ||||
82 | } | ||||
83 | | ||||
84 | MouseArea { | ||||
85 | id: itemMouse | ||||
86 | anchors.fill: parent | ||||
87 | hoverEnabled: true | ||||
88 | onClicked: listItem.clicked() | ||||
89 | } | ||||
90 | } |