Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qml/EntryScreenshots.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> | ||||
3 | * Copyright (C) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or modify | ||||
6 | * it under the terms of the GNU Library/Lesser General Public License | ||||
7 | * version 2, or (at your option) any later version, as published by the | ||||
8 | * Free Software Foundation | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library/Lesser General Public | ||||
16 | * License along with this program; if not, write to the | ||||
17 | * Free Software Foundation, Inc., | ||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | import QtQuick 2.1 | ||||
22 | import QtQuick.Layouts 1.1 | ||||
23 | import QtQuick.Controls 2.1 | ||||
24 | import QtGraphicalEffects 1.0 | ||||
25 | import org.kde.kirigami 2.5 as Kirigami | ||||
26 | | ||||
27 | Flickable { | ||||
28 | id: root | ||||
29 | property alias screenshotsModel: screenshotsRep.model | ||||
30 | readonly property alias count: screenshotsRep.count | ||||
31 | property int currentIndex: -1 | ||||
32 | property Item currentItem: screenshotsRep.itemAt(currentIndex) | ||||
33 | Layout.preferredHeight: Kirigami.Units.gridUnit * 13 | ||||
34 | contentHeight: height | ||||
35 | contentWidth: screenshotsLayout.width | ||||
36 | | ||||
37 | Popup { | ||||
38 | id: overlay | ||||
39 | parent: applicationWindow().overlay | ||||
40 | modal: true | ||||
41 | clip: false | ||||
42 | | ||||
43 | x: (parent.width - width)/2 | ||||
44 | y: (parent.height - height)/2 | ||||
45 | readonly property real proportion: overlayImage.sourceSize.width>1 ? overlayImage.sourceSize.height/overlayImage.sourceSize.width : 1 | ||||
46 | height: overlayImage.status == Image.Loading ? Kirigami.Units.gridUnit * 5 : Math.min(parent.height * 0.9, (parent.width * 0.9) * proportion, overlayImage.sourceSize.height) | ||||
47 | width: height/proportion | ||||
48 | | ||||
49 | BusyIndicator { | ||||
50 | id: indicator | ||||
51 | visible: running | ||||
52 | running: overlayImage.status == Image.Loading | ||||
53 | anchors.fill: parent | ||||
54 | } | ||||
55 | | ||||
56 | Image { | ||||
57 | id: overlayImage | ||||
58 | anchors.fill: parent | ||||
59 | source: root.currentItem ? root.currentItem.imageSource : "" | ||||
60 | fillMode: Image.PreserveAspectFit | ||||
61 | smooth: true | ||||
62 | } | ||||
63 | | ||||
64 | Button { | ||||
65 | anchors { | ||||
66 | right: parent.left | ||||
67 | verticalCenter: parent.verticalCenter | ||||
68 | } | ||||
69 | visible: leftAction.visible | ||||
70 | icon.name: leftAction.iconName | ||||
71 | onClicked: leftAction.triggered(null) | ||||
72 | } | ||||
73 | | ||||
74 | Button { | ||||
75 | anchors { | ||||
76 | left: parent.right | ||||
77 | verticalCenter: parent.verticalCenter | ||||
78 | } | ||||
79 | visible: rightAction.visible | ||||
80 | icon.name: rightAction.iconName | ||||
81 | onClicked: rightAction.triggered(null) | ||||
82 | } | ||||
83 | | ||||
84 | Kirigami.Action { | ||||
85 | id: leftAction | ||||
86 | icon.name: "arrow-left" | ||||
87 | enabled: overlay.visible && visible | ||||
88 | visible: root.currentIndex >= 1 && !indicator.running | ||||
89 | onTriggered: root.currentIndex = (root.currentIndex - 1) % root.count | ||||
90 | } | ||||
91 | | ||||
92 | Kirigami.Action { | ||||
93 | id: rightAction | ||||
94 | icon.name: "arrow-right" | ||||
95 | enabled: overlay.visible && visible | ||||
96 | visible: root.currentIndex < (root.count - 1) && !indicator.running | ||||
97 | onTriggered: root.currentIndex = (root.currentIndex + 1) % root.count | ||||
98 | } | ||||
99 | } | ||||
100 | | ||||
101 | Row { | ||||
102 | id: screenshotsLayout | ||||
103 | height: root.contentHeight | ||||
104 | spacing: Kirigami.Units.largeSpacing | ||||
105 | focus: overlay.visible | ||||
106 | | ||||
107 | Keys.onLeftPressed: if (leftAction.visible) leftAction.trigger() | ||||
108 | Keys.onRightPressed: if (rightAction.visible) rightAction.trigger() | ||||
109 | | ||||
110 | Repeater { | ||||
111 | id: screenshotsRep | ||||
112 | | ||||
113 | delegate: MouseArea { | ||||
114 | readonly property url imageSource: modelData | ||||
115 | readonly property real proportion: thumbnail.sourceSize.width>1 ? thumbnail.sourceSize.height/thumbnail.sourceSize.width : 1 | ||||
116 | width: Math.max(50, height/proportion) | ||||
117 | height: screenshotsLayout.height | ||||
118 | | ||||
119 | hoverEnabled: true | ||||
120 | cursorShape: Qt.PointingHandCursor | ||||
121 | | ||||
122 | onClicked: { | ||||
123 | root.currentIndex = index | ||||
124 | overlay.open() | ||||
125 | } | ||||
126 | | ||||
127 | DropShadow { | ||||
128 | source: thumbnail | ||||
129 | anchors.fill: thumbnail | ||||
130 | verticalOffset: Kirigami.Units.largeSpacing | ||||
131 | horizontalOffset: 0 | ||||
132 | radius: 12.0 | ||||
133 | samples: 25 | ||||
134 | color: Kirigami.Theme.disabledTextColor | ||||
135 | cached: true | ||||
136 | } | ||||
137 | | ||||
138 | BusyIndicator { | ||||
139 | visible: running | ||||
140 | running: thumbnail.status == Image.Loading | ||||
141 | anchors.centerIn: parent | ||||
142 | } | ||||
143 | | ||||
144 | Image { | ||||
145 | id: thumbnail | ||||
146 | source: modelData | ||||
147 | height: parent.height | ||||
148 | fillMode: Image.PreserveAspectFit | ||||
149 | smooth: true | ||||
150 | } | ||||
151 | } | ||||
152 | } | ||||
153 | } | ||||
154 | clip: true | ||||
155 | readonly property var leftShadow: Shadow { | ||||
156 | parent: root | ||||
157 | anchors { | ||||
158 | left: parent.left | ||||
159 | top: parent.top | ||||
160 | bottom: parent.bottom | ||||
161 | } | ||||
162 | edge: Qt.LeftEdge | ||||
163 | width: Math.max(0, Math.min(root.width/5, root.contentX)) | ||||
164 | } | ||||
165 | | ||||
166 | readonly property var rightShadow: Shadow { | ||||
167 | parent: root | ||||
168 | anchors { | ||||
169 | right: parent.right | ||||
170 | top: parent.top | ||||
171 | bottom: parent.bottom | ||||
172 | } | ||||
173 | edge: Qt.RightEdge | ||||
174 | width: Math.max(0, Math.min(root.contentWidth - root.contentX - root.width)/5) | ||||
175 | } | ||||
176 | } |