Lomiri
Loading...
Searching...
No Matches
ScreenshotEditor.qml
1/*
2 * Copyright (C) 2025 UBports Foundation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.15
18import Lomiri.Components 1.3
19import Lomiri.Components.Extras 0.2 as Extras
20import Lomiri.Content 1.1
21import Utils 0.1
22
23Item {
24 id: root
25
26 property var screenshotEditor : null
27
28 signal shown();
29 signal hidden();
30
31 Component {
32 id: editorComponent
33 Extras.PhotoEditor {
34 anchors.fill: parent
35 }
36 }
37
38 function show(path) {
39 if (!root.enabled)
40 return;
41
42 screenshotEditor =
43 editorComponent.createObject(
44 screenshotEditorRoot);
45
46 screenshotSharePicker.filePath = path;
47 root.shown();
48 screenshotEditor.open(path);
49 }
50
51 function hide() {
52 screenshotSharePicker.visible = false;
53 screenshotSharePicker.filePath = "";
54 root.hidden();
55 screenshotEditor.destroy();
56 screenshotEditor = null;
57 }
58
59 Item {
60 id: screenshotEditorRoot
61 y: screenshotEditorHeader.height
62 anchors.left: parent.left
63 anchors.right: parent.right
64 anchors.top: screenshotEditorHeader.bottom
65 anchors.bottom: parent.bottom
66 }
67
68 // Place the PageHeader below the editor for proper z-level layering,
69 // otherwise pictures would overlay and peek out over the header.
70 PageHeader {
71 id: screenshotEditorHeader
72 anchors.left: parent.left
73 anchors.right: parent.right
74 anchors.top: parent.top
75 height: implicitHeight
76 leadingActionBar {
77 actions: [
78 Action {
79 iconName: "edit-delete"
80 text: i18n.tr("Delete")
81 onTriggered: {
82 FileIo.remove(screenshotSharePicker.filePath);
83 root.hide();
84 }
85 }
86 ]
87 }
88 trailingActionBar {
89 actions: [
90 Action {
91 iconName: "document-save"
92 text: i18n.tr("Save")
93 onTriggered: {
94 screenshotEditor.close(true);
95 root.hide();
96 }
97 },
98 Action {
99 iconName: "share"
100 text: i18n.tr("Share")
101 onTriggered: {
102 screenshotEditor.close(true);
103 screenshotSharePicker.visible = true;
104 }
105 }
106 ]
107 }
108 }
109
110 ContentPeerPicker {
111 id: screenshotSharePicker
112 anchors {
113 fill: parent
114 }
115 visible: false
116 showTitle: true
117 contentType: ContentType.Pictures
118 handler: ContentHandler.Share
119
120 property string filePath : ""
121
122 Component {
123 id: resultComponent
124 ContentItem {}
125 }
126
127 onPeerSelected: {
128 const activeTransfer = peer.request();
129 activeTransfer.stateChanged.connect(function() {
130 if (activeTransfer.state === ContentTransfer.InProgress) {
131 const url = "file://" + screenshotSharePicker.filePath
132 console.log("File transfer in progress: " + url);
133 activeTransfer.items = [
134 resultComponent.createObject(parent, {"url": url})
135 ];
136 activeTransfer.state = ContentTransfer.Charged;
137 root.hide();
138 }
139 })
140 }
141
142 onCancelPressed: {
143 root.hide();
144 }
145 }
146}