@@ -2,7 +2,9 @@ import PAG
22import QtCore
33import QtQuick
44import QtQuick.Dialogs
5+ import QtQuick.Controls
56import Qt.labs.settings
7+ import Qt.labs.platform as Platform
68import "components"
79import "utils"
810
@@ -127,18 +129,6 @@ PAGWindow {
127129 }
128130 }
129131
130- FileDialog {
131- id: openPAGFileDialog
132- visible: false
133- title: qsTr (" Open PAG File" )
134- fileMode: FileDialog .OpenFile
135- nameFilters: [" PAG files(*.pag)" ]
136- onAccepted: {
137- let filePath = openPAGFileDialog .selectedFile ;
138- mainForm .pagView .setFile (filePath);
139- }
140- }
141-
142132 SettingsWindow {
143133 id: settingsWindow
144134 visible: false
@@ -163,6 +153,120 @@ PAGWindow {
163153 aboutMessage: " <b>PAGViewer</b> " + Qt .application .version + " <br><br>Copyright © 2017-present Tencent. All rights reserved."
164154 }
165155
156+ PAGTaskFactory {
157+ id: taskFactory
158+ objectName: " taskFactory"
159+ }
160+
161+ FileDialog {
162+ id: openFileDialog
163+
164+ property var currentAcceptHandler: null
165+
166+ visible: false
167+ title: " "
168+ fileMode: FileDialog .OpenFile
169+ nameFilters: []
170+ }
171+
172+ Platform .FolderDialog {
173+ id: openFolderDialog
174+
175+ property var currentAcceptHandler: null
176+
177+ visible: false
178+ title: qsTr (" Select Save Path" )
179+ }
180+
181+ PAGWindow {
182+ id: progressWindow
183+
184+ property var task
185+ property alias progressBar: progressBar
186+
187+ width: 300
188+ height: 64
189+ minimumWidth: width
190+ maximumWidth: width
191+ minimumHeight: height
192+ maximumHeight: height
193+ hasMenu: false
194+ canResize: false
195+ titleBarHeight: windowTitleBarHeight
196+ visible: false
197+
198+ PAGRectangle {
199+ id: rectangle
200+
201+ color: " #2D2D37"
202+ anchors .fill : parent
203+ leftTopRadius: false
204+ rightTopRadius: false
205+ radius: 5
206+
207+ ProgressBar {
208+ id: progressBar
209+ width: parent .width - 24
210+ height: 30
211+ anchors .verticalCenter : parent .verticalCenter
212+ anchors .horizontalCenter : parent .horizontalCenter
213+ value: 0
214+
215+ contentItem: Item {
216+ Rectangle {
217+ width: parent .width
218+ height: 15
219+ radius: 5
220+ color: " #DDDDDD"
221+ anchors .verticalCenter : parent .verticalCenter
222+ }
223+
224+ Rectangle {
225+ width: progressBar .visualPosition * parent .width
226+ height: 15
227+ radius: 5
228+ color: " #448EF9"
229+ anchors .verticalCenter : parent .verticalCenter
230+ }
231+
232+ Text {
233+ anchors .centerIn : parent
234+ text: Math .round (progressBar .value * 100 ) + " %"
235+ color: progressBar .value > 0.5 ? " white" : " black"
236+ font .pixelSize : 12
237+ }
238+ }
239+ }
240+ }
241+
242+ onClosing: {
243+ if (task) {
244+ task .stop ();
245+ }
246+ }
247+ }
248+
249+ Connections {
250+ id: taskConnections
251+ onProgressChanged : function (progress ) {
252+ progressWindow .progressBar .value = progress;
253+ }
254+
255+ onVisibleChanged : function (visible ) {
256+ progressWindow .visible = visible;
257+ }
258+
259+ onTaskFinished : function (filePath , result ) {
260+ if (result !== 0 ) {
261+ let errStr = qsTr (" Export failed, error code: " );
262+ alert (errStr + result);
263+ }
264+ progressWindow .task = null ;
265+ progressWindow .progressBar .value = 0 ;
266+ progressWindow .visible = false ;
267+ }
268+ }
269+
166270 Component .onCompleted : {
167271 viewWindow .title = " PAGViewer" ;
168272
@@ -217,11 +321,19 @@ PAGWindow {
217321 case " open-pag-file" :
218322 if (mainForm .hasPAGFile ) {
219323 let filePath = mainForm .pagView .filePath ;
220- openPAGFileDialog .currentFolder = Utils .getFileDir (filePath);
324+ openFileDialog .currentFolder = Utils .getFileDir (filePath);
221325 } else {
222- openPAGFileDialog .currentFolder = StandardPaths .writableLocation (StandardPaths .DocumentsLocation );
326+ openFileDialog .currentFolder = StandardPaths .writableLocation (StandardPaths .DocumentsLocation );
223327 }
224- openPAGFileDialog .open ();
328+ openFileDialog .accepted .disconnect ();
329+ openFileDialog .fileMode = FileDialog .OpenFile ;
330+ openFileDialog .title = qsTr (" Open PAG File" );
331+ openFileDialog .nameFilters = [" PAG files(*.pag)" ];
332+ openFileDialog .accepted .connect (function () {
333+ let filePath = openFileDialog .selectedFile ;
334+ mainForm .pagView .setFile (filePath);
335+ });
336+ openFileDialog .open ();
225337 break ;
226338 case " close-window" :
227339 viewWindow .close ();
@@ -273,6 +385,79 @@ PAGWindow {
273385 case " fullscreen-window" :
274386 viewWindow .visibility = viewWindow .visibility !== Window .Maximized ? Window .Maximized : Window .AutomaticVisibility ;
275387 break ;
388+ case " export-frame-as-png" :
389+ if (openFileDialog .currentAcceptHandler ) {
390+ openFileDialog .accepted .disconnect (openFileDialog .currentAcceptHandler );
391+ }
392+ openFileDialog .fileMode = FileDialog .SaveFile ;
393+ openFileDialog .title = qsTr (" Select save path" );
394+ openFileDialog .nameFilters = [" PNG files(*.png)" ];
395+ openFileDialog .defaultSuffix = " png" ;
396+ openFileDialog .currentFolder = Utils .getFileDir (mainForm .pagView .filePath );
397+ openFileDialog .currentAcceptHandler = function () {
398+ let filePath = openFileDialog .selectedFile ;
399+ let task = taskFactory .createTask (PAGTaskFactory .PAGTaskType_ExportPNG , filePath, {
400+ " exportFrame" : mainForm .pagView .currentFrame
401+ });
402+ if (task) {
403+ taskConnections .target = task;
404+ progressWindow .title = qsTr (" Exporting" );
405+ progressWindow .task = task;
406+ progressWindow .visible = true ;
407+ progressWindow .raise ();
408+ task .start ();
409+ }
410+ };
411+ openFileDialog .accepted .connect (openFileDialog .currentAcceptHandler );
412+ openFileDialog .open ();
413+ break ;
414+ case " export-as-png-sequence" :
415+ if (openFolderDialog .currentAcceptHandler ) {
416+ openFolderDialog .accepted .disconnect (openFolderDialog .currentAcceptHandler );
417+ }
418+ openFolderDialog .title = qsTr (" Select save path" );
419+ openFolderDialog .currentFolder = Utils .getFileDir (mainForm .pagView .filePath );
420+ openFolderDialog .currentAcceptHandler = function () {
421+ let filePath = openFolderDialog .folder ;
422+ let task = taskFactory .createTask (PAGTaskFactory .PAGTaskType_ExportPNG , filePath, {});
423+ if (task) {
424+ taskConnections .target = task;
425+ progressWindow .title = qsTr (" Exporting" );
426+ progressWindow .progressBar .value = 0 ;
427+ progressWindow .task = task;
428+ progressWindow .visible = true ;
429+ progressWindow .raise ();
430+ task .start ();
431+ }
432+ };
433+ openFolderDialog .accepted .connect (openFolderDialog .currentAcceptHandler );
434+ openFolderDialog .open ();
435+ break ;
436+ case " export-as-apng" :
437+ if (openFileDialog .currentAcceptHandler ) {
438+ openFileDialog .accepted .disconnect (openFileDialog .currentAcceptHandler );
439+ }
440+ openFileDialog .fileMode = FileDialog .SaveFile ;
441+ openFileDialog .title = qsTr (" Select save path" );
442+ openFileDialog .nameFilters = [" APNG files(*.png)" ];
443+ openFileDialog .defaultSuffix = " png" ;
444+ openFileDialog .currentFolder = Utils .getFileDir (mainForm .pagView .filePath );
445+ openFileDialog .currentAcceptHandler = function () {
446+ let filePath = openFileDialog .selectedFile ;
447+ let task = taskFactory .createTask (PAGTaskFactory .PAGTaskType_ExportAPNG , filePath, {});
448+ if (task) {
449+ taskConnections .target = task;
450+ progressWindow .title = qsTr (" Exporting" );
451+ progressWindow .progressBar .value = 0 ;
452+ progressWindow .task = task;
453+ progressWindow .visible = true ;
454+ progressWindow .raise ();
455+ task .start ();
456+ }
457+ };
458+ openFileDialog .accepted .connect (openFileDialog .currentAcceptHandler );
459+ openFileDialog .open ();
460+ break ;
276461 default :
277462 console .log (` Undefined command: [${ command} ]` );
278463 break ;
0 commit comments