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 | | ||||
24 | | ||||
25 | import QtQuick 2.1 | ||||
26 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
27 | | ||||
28 | | ||||
29 | // Ignores the theme's listItem margins, and uses custom highlight(pressed) area. | ||||
30 | // This could break compatibility with some themes but the majority look fine. | ||||
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 | height: separator ? separatorLine.height + units.smallSpacing * 3 : parent.height | ||||
43 | | ||||
44 | PlasmaCore.Svg { | ||||
45 | id: lineSvg | ||||
46 | imagePath: "widgets/line" | ||||
47 | } | ||||
48 | PlasmaCore.SvgItem { | ||||
49 | id: separatorLine | ||||
50 | anchors { | ||||
51 | horizontalCenter: parent.horizontalCenter | ||||
52 | top: parent.top | ||||
53 | topMargin: units.smallSpacing | ||||
54 | } | ||||
55 | elementId: "horizontal-line" | ||||
56 | width: parent.width - units.gridUnit * 2 | ||||
57 | svg: lineSvg | ||||
58 | visible: separator | ||||
59 | } | ||||
60 | | ||||
61 | PlasmaCore.FrameSvgItem { | ||||
62 | id : background | ||||
63 | imagePath: "widgets/listitem" | ||||
64 | prefix: "normal" | ||||
65 | anchors.fill: parent | ||||
66 | visible: separator ? false : true | ||||
67 | } | ||||
68 | | ||||
69 | PlasmaCore.FrameSvgItem { | ||||
70 | id : pressed | ||||
71 | imagePath: "widgets/listitem" | ||||
72 | prefix: "pressed" | ||||
73 | opacity: checked ? 1 : 0 | ||||
74 | Behavior on opacity { NumberAnimation { duration: units.shortDuration } } | ||||
75 | | ||||
76 | x: highlightRect.x | ||||
77 | y: highlightRect.y | ||||
78 | height: highlightRect.height | ||||
79 | width: highlightRect.width | ||||
80 | } | ||||
81 | | ||||
82 | MouseArea { | ||||
83 | id: itemMouse | ||||
84 | anchors.fill: parent | ||||
85 | hoverEnabled: true | ||||
86 | onClicked: listItem.clicked() | ||||
87 | } | ||||
88 | } |