KNewStuff

NewStuffItem.qml
1 /*
2  * Copyright (C) 2015 Dan Leinir Turthra Jensen <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) version 3, or any
8  * later version accepted by the membership of KDE e.V. (or its
9  * successor approved by the membership of KDE e.V.), which shall
10  * act as a proxy defined in Section 6 of version 3 of the license.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 import QtQuick 2.11
23 import QtQuick.Controls 2.11 as QtControls
24 import QtQuick.Layouts 1.11 as QtLayouts
25 
26 import org.kde.kirigami 2.1 as Kirigami
27 
28 import org.kde.newstuff 1.62 as NewStuff
29 
30 Kirigami.SwipeListItem {
31  id: listItem;
32  height: Math.max(Kirigami.Units.iconSizes.huge + Kirigami.Units.smallSpacing * 2, nameText.height + descriptionText.height + Kirigami.Units.smallSpacing * 5);
33  property QtObject listModel;
34  enabled: true;
35  actions: [
36  Kirigami.Action {
37  text: i18ndc("knewstuff5", "Request installation of this item", "Install");
38  iconName: "list-add"
39  onTriggered: { listModel.installItem(model.index, NewStuff.ItemsModel.FirstLinkId); }
40  enabled: model.status == NewStuff.ItemsModel.DownloadableStatus || model.status == NewStuff.ItemsModel.DeletedStatus;
41  visible: enabled;
42  },
43  Kirigami.Action {
44  text: i18ndc("knewstuff5", "Request updating of this item", "Update");
45  iconName: "refresh"
46  onTriggered: { listModel.updateItem(model.index); }
47  enabled: model.status == NewStuff.ItemsModel.UpdateableStatus;
48  visible: enabled;
49  },
50  Kirigami.Action {
51  text: i18ndc("knewstuff5", "Request uninstallation of this item", "Uninstall");
52  iconName: "list-remove"
53  onTriggered: { listModel.uninstallItem(model.index); }
54  enabled: model.status == NewStuff.ItemsModel.InstalledStatus || model.status == NewStuff.ItemsModel.UpdateableStatus
55  visible: enabled;
56  }
57  ]
58  QtLayouts.RowLayout {
59  Item {
60  id: previewContainer;
61  QtLayouts.Layout.preferredHeight: listItem.height - Kirigami.Units.smallSpacing * 2;
62  QtLayouts.Layout.minimumWidth: Kirigami.Units.iconSizes.huge;
63  QtLayouts.Layout.maximumWidth: Kirigami.Units.iconSizes.huge;
64  Image {
65  id: previewImage;
66  anchors {
67  fill: parent;
68  margins: Kirigami.Units.smallSpacing;
69  leftMargin: -Kirigami.Units.smallSpacing;
70  }
71  asynchronous: true;
72  fillMode: Image.PreserveAspectFit;
73  source: model.previewsSmall.length > 0 ? model.previewsSmall[0] : "";
74  Kirigami.Icon {
75  id: updateAvailableBadge;
76  opacity: (model.status == NewStuff.ItemsModel.UpdateableStatus) ? 1 : 0;
77  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
78  anchors {
79  bottom: parent.bottom;
80  right: parent.right;
81  margins: -Kirigami.Units.smallSpacing;
82  }
83  height: Kirigami.Units.iconSizes.smallMedium;
84  width: height;
85  source: "vcs-update-required";
86  }
87  Kirigami.Icon {
88  id: installedBadge;
89  opacity: (model.status == NewStuff.ItemsModel.InstalledStatus) ? 1 : 0;
90  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
91  anchors {
92  bottom: parent.bottom;
93  right: parent.right;
94  margins: -Kirigami.Units.smallSpacing;
95  }
96  height: Kirigami.Units.iconSizes.smallMedium;
97  width: height;
98  source: "vcs-normal";
99  }
100  }
101  Rectangle {
102  anchors.fill: parent
103  opacity: installIndicator.opacity > 0 ? 0.7 : 0
104  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
105  visible: opacity > 0
106  }
107  QtControls.BusyIndicator {
108  id: installIndicator
109  anchors.centerIn: parent;
110  opacity: (model.status == NewStuff.ItemsModel.InstallingStatus || model.status == NewStuff.ItemsModel.UpdatingStatus) ? 1 : 0;
111  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
112  running: opacity > 0;
113  QtControls.Label {
114  anchors {
115  horizontalCenter: parent.horizontalCenter;
116  bottom: parent.bottom;
117  margins: Kirigami.Units.smallSpacing;
118  }
119  text: (model.status == NewStuff.ItemsModel.InstallingStatus) ? "Installing" : ((model.status == NewStuff.ItemsModel.UpdatingStatus) ? "Updating" : "");
120  width: paintedWidth;
121  }
122  }
123  }
124  QtLayouts.ColumnLayout {
125  QtLayouts.Layout.fillWidth: true
126  QtLayouts.Layout.fillHeight: true
127  Kirigami.Heading {
128  id: nameText
129  QtLayouts.Layout.fillWidth: true
130  level: 3
131  text: model.name
132  opacity: 1 - installIndicator.opacity
133  }
134  QtControls.Label {
135  id: descriptionText
136  QtLayouts.Layout.fillWidth: true
137  text: model.summary.split("\n")[0];
138  elide: Text.ElideRight
139  maximumLineCount: 2
140  wrapMode: Text.Wrap
141  opacity: 1 - installIndicator.opacity
142  }
143  Item {
144  QtLayouts.Layout.fillWidth: true
145  QtLayouts.Layout.fillHeight: true
146  }
147  }
148  }
149 }
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.