KNewStuff

NewStuffItem.qml
1 /*
2  SPDX-FileCopyrightText: 2015 Dan Leinir Turthra Jensen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 import QtQuick 2.11
8 import QtQuick.Controls 2.11 as QtControls
9 import QtQuick.Layouts 1.11 as QtLayouts
10 
11 import org.kde.kirigami 2.1 as Kirigami
12 
13 import org.kde.newstuff 1.62 as NewStuff
14 
15 Kirigami.SwipeListItem {
16  id: listItem;
17  height: Math.max(Kirigami.Units.iconSizes.huge + Kirigami.Units.smallSpacing * 2, nameText.height + descriptionText.height + Kirigami.Units.smallSpacing * 5);
18  property QtObject listModel;
19  enabled: true;
20  actions: [
21  Kirigami.Action {
22  text: i18ndc("knewstuff5", "Request installation of this item", "Install");
23  iconName: "list-add"
24  onTriggered: { listModel.installItem(model.index, NewStuff.ItemsModel.FirstLinkId); }
25  enabled: model.status == NewStuff.ItemsModel.DownloadableStatus || model.status == NewStuff.ItemsModel.DeletedStatus;
26  visible: enabled;
27  },
28  Kirigami.Action {
29  text: i18ndc("knewstuff5", "Request updating of this item", "Update");
30  iconName: "refresh"
31  onTriggered: { listModel.updateItem(model.index); }
32  enabled: model.status == NewStuff.ItemsModel.UpdateableStatus;
33  visible: enabled;
34  },
35  Kirigami.Action {
36  text: i18ndc("knewstuff5", "Request uninstallation of this item", "Uninstall");
37  iconName: "list-remove"
38  onTriggered: { listModel.uninstallItem(model.index); }
39  enabled: model.status == NewStuff.ItemsModel.InstalledStatus || model.status == NewStuff.ItemsModel.UpdateableStatus
40  visible: enabled;
41  }
42  ]
43  QtLayouts.RowLayout {
44  Item {
45  id: previewContainer;
46  QtLayouts.Layout.preferredHeight: listItem.height - Kirigami.Units.smallSpacing * 2;
47  QtLayouts.Layout.minimumWidth: Kirigami.Units.iconSizes.huge;
48  QtLayouts.Layout.maximumWidth: Kirigami.Units.iconSizes.huge;
49  Image {
50  id: previewImage;
51  anchors {
52  fill: parent;
53  margins: Kirigami.Units.smallSpacing;
54  leftMargin: -Kirigami.Units.smallSpacing;
55  }
56  asynchronous: true;
57  fillMode: Image.PreserveAspectFit;
58  source: model.previewsSmall.length > 0 ? model.previewsSmall[0] : "";
59  Kirigami.Icon {
60  id: updateAvailableBadge;
61  opacity: (model.status == NewStuff.ItemsModel.UpdateableStatus) ? 1 : 0;
62  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
63  anchors {
64  bottom: parent.bottom;
65  right: parent.right;
66  margins: -Kirigami.Units.smallSpacing;
67  }
68  height: Kirigami.Units.iconSizes.smallMedium;
69  width: height;
70  source: "vcs-update-required";
71  }
72  Kirigami.Icon {
73  id: installedBadge;
74  opacity: (model.status == NewStuff.ItemsModel.InstalledStatus) ? 1 : 0;
75  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
76  anchors {
77  bottom: parent.bottom;
78  right: parent.right;
79  margins: -Kirigami.Units.smallSpacing;
80  }
81  height: Kirigami.Units.iconSizes.smallMedium;
82  width: height;
83  source: "vcs-normal";
84  }
85  }
86  Rectangle {
87  anchors.fill: parent
88  opacity: installIndicator.opacity > 0 ? 0.7 : 0
89  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
90  visible: opacity > 0
91  }
92  QtControls.BusyIndicator {
93  id: installIndicator
94  anchors.centerIn: parent;
95  opacity: (model.status == NewStuff.ItemsModel.InstallingStatus || model.status == NewStuff.ItemsModel.UpdatingStatus) ? 1 : 0;
96  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
97  running: opacity > 0;
98  QtControls.Label {
99  anchors {
100  horizontalCenter: parent.horizontalCenter;
101  bottom: parent.bottom;
102  margins: Kirigami.Units.smallSpacing;
103  }
104  text: (model.status == NewStuff.ItemsModel.InstallingStatus) ? "Installing" : ((model.status == NewStuff.ItemsModel.UpdatingStatus) ? "Updating" : "");
105  width: paintedWidth;
106  }
107  }
108  }
109  QtLayouts.ColumnLayout {
110  QtLayouts.Layout.fillWidth: true
111  QtLayouts.Layout.fillHeight: true
112  Kirigami.Heading {
113  id: nameText
114  QtLayouts.Layout.fillWidth: true
115  level: 3
116  text: model.name
117  opacity: 1 - installIndicator.opacity
118  }
119  QtControls.Label {
120  id: descriptionText
121  QtLayouts.Layout.fillWidth: true
122  text: model.summary.split("\n")[0];
123  elide: Text.ElideRight
124  maximumLineCount: 2
125  wrapMode: Text.Wrap
126  opacity: 1 - installIndicator.opacity
127  }
128  Item {
129  QtLayouts.Layout.fillWidth: true
130  QtLayouts.Layout.fillHeight: true
131  }
132  }
133  }
134 }
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-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.