-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
166 lines (147 loc) · 3.76 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import QtQuick 2.2
import Painter 1.0
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import Qt.labs.platform 1.1
import AlgWidgets 2.0
import AlgWidgets.Style 2.0
import "Krita.js" as Krita
PainterPlugin {
Component.onCompleted: {
// default value settings
if (!alg.settings.contains("launchKrita")) {
if (Qt.platform.os == "windows" || Qt.platform.os == "osx") {
alg.settings.setValue("launchKrita", true);
} else {
alg.settings.setValue("launchKrita", false);
}
alg.settings.setValue("padding", false);
}
var sendtoAction = alg.ui.addAction(alg.ui.AppMenu.SendTo, qsTr("Export to Krita"), qsTr("Export to Krita"), Qt.resolvedUrl("icons/Krita_idle.png"), Qt.resolvedUrl("icons/Krita_idle.png"));
sendtoAction.triggered.connect(internal.sendToTriggered);
//check if kritarunner folder exists
var appdata = StandardPaths.standardLocations(StandardPaths.HomeLocation)[0];
//remove file:///
appdata = appdata.substring(8);
var kritarunnerFolder = appdata + "/AppData/Roaming/kritarunner";
if (!alg.fileIO.exists(kritarunnerFolder)) {
alg.log.info("Running Kritarunner for the first time");
alg.subprocess.startDetached(["\"" + alg.settings.value("kritaPath") + "\"", "-s", "runner"]);
}
}
onConfigure: {
// open the configuration panel
configurePanel.open()
}
ConfigurePanel {
id: configurePanel
}
QtObject {
property bool loading: false
id: internal
function updateProgressWindow(text) {
progressText.text = text
}
function updateProgressBar(value, max) {
//print all properties of the object
/*
for (var property in progressBar) {
alg.log.info(property + ": " + progressBar[property]);
}
*/
progressBar.indeterminate = false
progressBar.from = 0
progressBar.to = max
progressBar.value = value
}
function launchExportDialog() {
exportDialog.open()
}
function launchExport() {
try {
loading = true;
progressWindow.open()
Krita.importPainterDocument(updateProgressWindow, updateProgressBar);
}
catch (e) {
alg.log.warn(e.message)
}
finally {
progressWindow.close()
loading = false;
}
}
function sendToTriggered() {
if (!internal.loading) {
if (!alg.settings.contains("KritaPath") && alg.settings.value("launchKrita", false)) {
fileDialog.open();
} else {
internal.launchExportDialog()
}
}
}
}
ExportDialog {
id: exportDialog
onAccepted: {
close()
internal.launchExport()
}
}
AlgWindow {
id: progressWindow
minimumWidth: 400
minimumHeight: 125
maximumWidth: 400
maximumHeight: 125
title: qsTr("Export to Krita")
flags: Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
function reload() {
progressText.text = qsTr("Export in progress...")
}
Rectangle {
id: content
color: "transparent"
anchors.fill: parent
anchors.margins: 12
ColumnLayout {
spacing: 18
anchors.fill: parent
Rectangle {
color: "transparent"
Layout.fillWidth: true
AlgTextEdit {
id: progressText
anchors.centerIn: parent
width: parent.width
wrapMode: TextEdit.Wrap
clip: true
readOnly: true
}
}
Rectangle {
color: "transparent"
Layout.fillWidth: true
AlgProgressBar {
id: progressBar
anchors.centerIn: parent
width: parent.width
indeterminate: true
}
}
}
}
}
FileDialog {
id: fileDialog
title: qsTr("Please locate KritaRunner...")
nameFilters: [ "Krita files (*.exe *.app)", "All files (*)" ]
//selectedNameFilter: "Executable files (*)"
onAccepted: {
alg.settings.setValue("KritaPath", alg.fileIO.urlToLocalFile(fileUrl.toString()));
internal.launchExportDialog()
}
}
}