Skip to content

Commit beda077

Browse files
authored
Implement the menu for viewer (#2752)
1 parent 9696b0c commit beda077

22 files changed

+950
-17
lines changed

viewer/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ endif ()
8383
# collects pag include directories.
8484
set(PAG_VIEWER_INCLUDES ./ src ../ ../include ../src ../third_party/tgfx/include)
8585
file(GLOB_RECURSE PAG_VIEWER_SOURCE_FILES src/*.*)
86+
list(FILTER PAG_VIEWER_SOURCE_FILES EXCLUDE REGEX src/platform/*.*)
87+
if (APPLE)
88+
list(APPEND PAG_VIEWER_INCLUDES src/platform/mac)
89+
file(GLOB_RECURSE PLATFORM_SOURCE_FILES src/platform/mac/*.*)
90+
elseif (WIN32)
91+
list(APPEND PAG_VIEWER_INCLUDES src/platform/win)
92+
file(GLOB_RECURSE PLATFORM_SOURCE_FILES src/platform/win/*.*)
93+
endif ()
94+
list(APPEND PAG_VIEWER_SOURCE_FILES ${PLATFORM_SOURCE_FILES})
8695

8796
set(PAG_USE_QT ON)
8897
set(PAG_USE_RTTR ON)

viewer/qml/AboutWindow.qml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import QtQuick
2+
import QtQuick.Controls
3+
import "components"
4+
5+
PAGWindow {
6+
id: aboutWindow
7+
8+
property string aboutMessage: ""
9+
property string licenseMessage: ""
10+
property string privacyMessage: ""
11+
property string licenseUrl: ""
12+
property string privacyUrl: ""
13+
14+
minimumWidth: width
15+
maximumWidth: width
16+
minimumHeight: height
17+
maximumHeight: height
18+
hasMenu: false
19+
canResize: false
20+
titleBarHeight: isWindows ? 32 : 22
21+
22+
PAGRectangle {
23+
id: rectangle
24+
25+
color: "#2D2D37"
26+
anchors.fill: parent
27+
leftTopRadius: false
28+
rightTopRadius: false
29+
radius: 5
30+
31+
Row {
32+
anchors.fill: parent
33+
Item {
34+
width: 30
35+
height: 1
36+
}
37+
38+
Image {
39+
id: image
40+
width: 80
41+
height: 80
42+
sourceSize.width: 160
43+
sourceSize.height: 160
44+
anchors.verticalCenterOffset: 0
45+
anchors.verticalCenter: parent.verticalCenter
46+
fillMode: Image.PreserveAspectFit
47+
source: "qrc:/images/window-icon.png"
48+
}
49+
50+
Item {
51+
width: 20
52+
height: 1
53+
}
54+
55+
Column {
56+
spacing: 10
57+
Item {
58+
width: 1
59+
height: 20
60+
}
61+
Text {
62+
id: aboutText
63+
color: "#ffffff"
64+
text: aboutMessage
65+
verticalAlignment: Text.AlignVCenter
66+
font.pixelSize: 12
67+
}
68+
Row {
69+
visible: licenseMessage !== "" || privacyMessage !== ""
70+
height: 25
71+
spacing: 15
72+
73+
Text {
74+
id: licenseText
75+
visible: licenseUrl !== ""
76+
text: licenseMessage
77+
color: "#008EFF"
78+
verticalAlignment: Text.AlignVCenter
79+
anchors.verticalCenter: parent.verticalCenter
80+
font.pixelSize: 13
81+
MouseArea {
82+
anchors.fill: parent
83+
cursorShape: Qt.PointingHandCursor
84+
onClicked: {
85+
Qt.openUrlExternally(licenseUrl);
86+
}
87+
}
88+
}
89+
90+
Text {
91+
id: privacyText
92+
visible: privacyUrl !== ""
93+
text: privacyMessage
94+
color: "#008EFF"
95+
verticalAlignment: Text.AlignVCenter
96+
anchors.topMargin: 10
97+
anchors.bottomMargin: 10
98+
anchors.verticalCenter: parent.verticalCenter
99+
font.pixelSize: 13
100+
MouseArea {
101+
anchors.fill: parent
102+
cursorShape: Qt.PointingHandCursor
103+
onClicked: {
104+
Qt.openUrlExternally(privacyUrl);
105+
}
106+
}
107+
}
108+
}
109+
110+
Row {
111+
spacing: 0
112+
Item {
113+
width: aboutWindow.width - 75 - 70 - 100
114+
height: 1
115+
}
116+
Button {
117+
id: btnOk
118+
width: 75
119+
height: 25
120+
font.pixelSize: 12
121+
text: qsTr("Confirm")
122+
onClicked: {
123+
aboutWindow.close();
124+
}
125+
126+
background: Rectangle {
127+
radius: 3
128+
color: "#3485F6"
129+
}
130+
contentItem: Text {
131+
text: btnOk.text
132+
font: btnOk.font
133+
color: "#FFFFFF"
134+
anchors.fill: parent
135+
horizontalAlignment: Text.AlignHCenter
136+
verticalAlignment: Text.AlignVCenter
137+
}
138+
}
139+
}
140+
}
141+
}
142+
}
143+
}

viewer/qml/Main.qml

Lines changed: 132 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import PAG
22
import QtCore
33
import QtQuick
4-
import QtQuick.Window
5-
import Qt.labs.platform as Lab11
4+
import QtQuick.Dialogs
5+
import Qt.labs.settings
66
import "components"
7+
import "utils"
78

89
PAGWindow {
910
id: viewWindow
@@ -12,6 +13,7 @@ PAGWindow {
1213
height: 360
1314
minimumWidth: 400 + windowPadding
1415
minimumHeight: 320 + windowTitleBarHeight
16+
hasMenu: true
1517
resizeHandleSize: 5
1618
titleBarHeight: windowTitleBarHeight
1719

@@ -30,6 +32,8 @@ PAGWindow {
3032

3133
property bool isShowVideoFrames: true
3234

35+
property bool isUseEnglish: true
36+
3337
property double lastX: 0
3438

3539
property double lastY: 0
@@ -123,24 +127,71 @@ PAGWindow {
123127
}
124128
}
125129

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+
142+
SettingsWindow {
143+
id: settingsWindow
144+
visible: false
145+
width: 500
146+
height: 160 + windowTitleBarHeight
147+
title: qsTr("Settings")
148+
useEnglish: settings.isUseEnglish
149+
onUseEnglishChanged: {
150+
if (!settingsWindow.visible || settingsWindow.useEnglish === settings.isUseEnglish) {
151+
return;
152+
}
153+
settings.isUseEnglish = settingsWindow.useEnglish;
154+
}
155+
}
156+
157+
AboutWindow {
158+
id: aboutWindow
159+
visible: false
160+
width: settings.isUseEnglish ? 600 : 500
161+
height: 160 + windowTitleBarHeight
162+
title: qsTr("About PAGViewer")
163+
aboutMessage: "<b>PAGViewer</b> " + Qt.application.version + "<br><br>Copyright © 2017-present Tencent. All rights reserved."
164+
}
165+
126166
Component.onCompleted: {
127167
viewWindow.title = "PAGViewer";
168+
169+
let component = Qt.createComponent("Menu.qml");
170+
let menuBar = component.createObject(viewWindow, {
171+
hasPAGFile: Qt.binding(function () {
172+
return mainForm.hasPAGFile;
173+
}),
174+
windowActive: Qt.binding(function () {
175+
return viewWindow.active;
176+
}),
177+
isUseEnglish: Qt.binding(function () {
178+
return settings.isUseEnglish;
179+
}),
180+
isFullScreen: Qt.binding(function () {
181+
return viewWindow.visibility === Window.FullScreen;
182+
})
183+
});
184+
menuBar.command.connect(onCommand);
128185
}
129186

130187
function updateProgress() {
131188
let duration = mainForm.pagView.duration;
132189
let displayedTime = duration * mainForm.pagView.progress;
133-
mainForm.controlForm.timeDisplayedText.text = msToTime(displayedTime);
190+
mainForm.controlForm.timeDisplayedText.text = Utils.msToTime(displayedTime);
134191
mainForm.controlForm.currentFrameText.text = mainForm.pagView.currentFrame;
135192
mainForm.controlForm.totalFrameText.text = mainForm.pagView.totalFrame;
136193
}
137-
function msToTime(duration) {
138-
let seconds = parseInt((duration / 1000) % 60);
139-
let minutes = parseInt((duration / (1000 * 60)) % 60);
140-
minutes = (minutes < 10) ? "0" + minutes : minutes;
141-
seconds = (seconds < 10) ? "0" + seconds : seconds;
142-
return minutes + ":" + seconds;
143-
}
194+
144195
function toggleBackground(checked) {
145196
if (checked === undefined) {
146197
checked = !mainForm.isBackgroundOn;
@@ -149,12 +200,82 @@ PAGWindow {
149200
mainForm.isBackgroundOn = checked;
150201
}
151202
}
203+
152204
function toggleEditPanel(willOpen) {
153205
if (willOpen === undefined) {
154-
willOpen = !mainForm.isEditPanelOpen;
206+
willOpen = !settings.isEditPanelOpen;
155207
}
156208
if (mainForm.controlForm.panelsButton.checked !== willOpen) {
157209
mainForm.controlForm.panelsButton.checked = willOpen;
158210
}
211+
settings.isEditPanelOpen = willOpen;
212+
}
213+
214+
function onCommand(command) {
215+
console.log(`Get command: [${command}]`);
216+
switch (command) {
217+
case "open-pag-file":
218+
if (mainForm.hasPAGFile) {
219+
let filePath = mainForm.pagView.filePath;
220+
openPAGFileDialog.currentFolder = Utils.getFileDir(filePath);
221+
} else {
222+
openPAGFileDialog.currentFolder = StandardPaths.writableLocation(StandardPaths.DocumentsLocation);
223+
}
224+
openPAGFileDialog.open();
225+
break;
226+
case "close-window":
227+
viewWindow.close();
228+
break;
229+
case "open-preferences":
230+
settingsWindow.visible = true;
231+
settingsWindow.raise();
232+
break;
233+
case "first-frame":
234+
mainForm.pagView.firstFrame();
235+
break;
236+
case "last-frame":
237+
mainForm.pagView.lastFrame();
238+
break;
239+
case "previous-frame":
240+
mainForm.pagView.previousFrame();
241+
break;
242+
case "next-frame":
243+
mainForm.pagView.nextFrame();
244+
break;
245+
case "pause-or-play":
246+
mainForm.pagView.isPlaying = !mainForm.pagView.isPlaying;
247+
break;
248+
case "toggle-background":
249+
toggleBackground();
250+
break;
251+
case "toggle-edit-panel":
252+
toggleEditPanel();
253+
break;
254+
case "open-help":
255+
Qt.openUrlExternally("https://pag.art/#pag-player");
256+
break;
257+
case "open-about":
258+
aboutWindow.visible = true;
259+
aboutWindow.raise();
260+
break;
261+
case "open-feedback":
262+
Qt.openUrlExternally("https://github.com/Tencent/libpag/discussions");
263+
break;
264+
case "open-commerce-page":
265+
Qt.openUrlExternally("https://pag.io/product.html#pag-enterprise-edition");
266+
break;
267+
case "minimize-window":
268+
viewWindow.showMinimized();
269+
break;
270+
case "zoom-window":
271+
viewWindow.visibility = viewWindow.visibility !== Window.Maximized ? Window.Maximized : Window.AutomaticVisibility;
272+
break;
273+
case "fullscreen-window":
274+
viewWindow.visibility = viewWindow.visibility !== Window.Maximized ? Window.Maximized : Window.AutomaticVisibility;
275+
break;
276+
default:
277+
console.log(`Undefined command: [${command}]`);
278+
break;
279+
}
159280
}
160281
}

0 commit comments

Comments
 (0)