1/*
2    SPDX-FileCopyrightText: 2013 Antonis Tsiapaliokas <kok3rs@gmail.com>
3    SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
4
5    SPDX-License-Identifier: GPL-2.0-or-later
6
7*/
8
9import QtQuick 2.5
10import QtQuick.Controls 2.5 as QQC2
11import QtQuick.Layouts 1.1
12
13import org.kde.kirigami 2.5 as Kirigami
14import org.kde.kcm 1.5 as KCM
15
16Kirigami.SwipeListItem {
17    id: listItem
18    hoverEnabled: true
19    onClicked: {
20        if (view.currentIndex == index) {
21            // Collapse list item
22            view.currentIndex = -1;
23        } else {
24            // Expand list item
25            view.currentIndex = index;
26        }
27    }
28    contentItem: RowLayout {
29        id: row
30        QQC2.RadioButton {
31            property bool _exclusive: model.ExclusiveRole != ""
32            property bool _toggled: false
33
34            checked: model.StatusRole
35            visible: _exclusive
36            QQC2.ButtonGroup.group: _exclusive ? effectsList.findButtonGroup(model.ExclusiveRole) : null
37
38            onToggled: {
39                model.StatusRole = checked ? Qt.Checked : Qt.Unchecked;
40                _toggled = true;
41            }
42            onClicked: {
43                // Uncheck the radio button if it's clicked.
44                if (checked && !_toggled) {
45                    model.StatusRole = Qt.Unchecked;
46                }
47                _toggled = false;
48            }
49
50            KCM.SettingHighlighter {
51                highlight: model.EnabledByDefaultFunctionRole ? parent.checkState !== Qt.PartiallyChecked : parent.checked !== model.EnabledByDefaultRole
52            }
53        }
54
55        QQC2.CheckBox {
56            checkState: model.StatusRole
57            visible: model.ExclusiveRole == ""
58
59            onToggled: model.StatusRole = checkState
60
61            KCM.SettingHighlighter {
62                highlight: model.EnabledByDefaultFunctionRole ? parent.checkState !== Qt.PartiallyChecked : parent.checked !== model.EnabledByDefaultRole
63            }
64        }
65
66        ColumnLayout {
67            Layout.topMargin: Kirigami.Units.smallSpacing
68            Layout.bottomMargin: Kirigami.Units.smallSpacing
69            spacing: 0
70
71            Kirigami.Heading {
72                Layout.fillWidth: true
73
74                level: 5
75                text: model.NameRole
76                wrapMode: Text.Wrap
77            }
78
79            QQC2.Label {
80                Layout.fillWidth: true
81
82                text: model.DescriptionRole
83                opacity: listItem.hovered ? 0.8 : 0.6
84                wrapMode: Text.Wrap
85            }
86
87            QQC2.Label {
88                id: aboutItem
89
90                Layout.fillWidth: true
91
92                text: i18n("Author: %1\nLicense: %2", model.AuthorNameRole, model.LicenseRole)
93                opacity: listItem.hovered ? 0.8 : 0.6
94                visible: view.currentIndex === index
95                wrapMode: Text.Wrap
96            }
97
98            Loader {
99                id: videoItem
100
101                active: false
102                source: "Video.qml"
103                visible: false
104
105                function showHide() {
106                    if (!videoItem.active) {
107                        videoItem.active = true;
108                        videoItem.visible = true;
109                    } else {
110                        videoItem.active = false;
111                        videoItem.visible = false;
112                    }
113                }
114            }
115        }
116    }
117    actions: [
118        Kirigami.Action {
119            visible: model.VideoRole.toString() !== ""
120            icon.name: "videoclip-amarok"
121            tooltip: i18nc("@info:tooltip", "Show/Hide Video")
122            onTriggered: videoItem.showHide()
123        },
124        Kirigami.Action {
125            visible: model.ConfigurableRole
126            enabled: model.StatusRole != Qt.Unchecked
127            icon.name: "configure"
128            tooltip: i18nc("@info:tooltip", "Configure...")
129            onTriggered: kcm.configure(model.ServiceNameRole, this)
130        }
131    ]
132}
133