Skip to content

Commit e7c8a96

Browse files
committed
disable rtti for viewer, modify some programming details
1 parent 26620d6 commit e7c8a96

File tree

7 files changed

+92
-61
lines changed

7 files changed

+92
-61
lines changed

viewer/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ if (NOT CMAKE_BUILD_TYPE)
1111
endif ()
1212

1313
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
14-
add_definitions(-Werror -Wall -Wextra -Weffc++ -pedantic -Werror=return-type)
14+
add_definitions(-Werror -Wall -Wextra -Weffc++ -pedantic -Werror=return-type -fno-rtti)
1515
endif ()
1616

1717
if (MSVC)
1818
add_compile_options("/utf-8")
19+
add_compile_options(/GR-)
1920
endif (MSVC)
2021

2122
# Sets flags

viewer/qml/components/PAGWindow.qml

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -274,53 +274,71 @@ Window {
274274
anchors.bottomMargin: window.isWindows ? 1 : 0
275275
clip: true
276276
}
277-
MouseArea {
278-
enabled: window.isWindows && window.canResize
279-
anchors.fill: parent
280-
hoverEnabled: true
281-
cursorShape: {
282-
const pos = Qt.point(mouseX, mouseY);
283-
const offset = resizeHandleSize;
284-
if ((pos.x < offset) && (pos.y >= (height - offset))) {
285-
return Qt.SizeBDiagCursor;
286-
}
287-
if ((pos.x < offset) && (pos.y < offset)) {
288-
return Qt.SizeFDiagCursor;
289-
}
290-
if ((pos.x >= (width - offset)) && (pos.y >= (height - offset))) {
291-
return Qt.SizeFDiagCursor;
292-
}
293-
if ((pos.x < offset) || ((pos.x >= (width - offset)) && (pos.y > titleBarHeight))) {
294-
return Qt.SizeHorCursor;
295-
}
296-
if ((pos.y > (height - offset)) || ((pos.y < offset) && (pos.x < (width - 120)))) {
297-
return Qt.SizeVerCursor;
277+
278+
Loader {
279+
active: window.isWindows && window.canResize
280+
sourceComponent: Component {
281+
MouseArea {
282+
enabled: window.isWindows && window.canResize
283+
anchors.fill: parent
284+
hoverEnabled: window.isWindows && window.canResize
285+
cursorShape: {
286+
console.log("MouseArea::cursorShape")
287+
console.log("window.isWindows && window.canResize: " + (window.isWindows && window.canResize))
288+
const pos = Qt.point(mouseX, mouseY);
289+
const offset = resizeHandleSize;
290+
if ((pos.x < offset) && (pos.y >= (height - offset))) {
291+
return Qt.SizeBDiagCursor;
292+
}
293+
if ((pos.x < offset) && (pos.y < offset)) {
294+
return Qt.SizeFDiagCursor;
295+
}
296+
if ((pos.x >= (width - offset)) && (pos.y >= (height - offset))) {
297+
return Qt.SizeFDiagCursor;
298+
}
299+
if ((pos.x < offset) || ((pos.x >= (width - offset)) && (pos.y > titleBarHeight))) {
300+
return Qt.SizeHorCursor;
301+
}
302+
if ((pos.y > (height - offset)) || ((pos.y < offset) && (pos.x < (width - 120)))) {
303+
return Qt.SizeVerCursor;
304+
}
305+
}
306+
onClicked: {
307+
console.log("width: " + width + " height: " + height)
308+
}
309+
acceptedButtons: Qt.NoButton
298310
}
299311
}
300-
acceptedButtons: Qt.NoButton
301312
}
302-
DragHandler {
303-
id: resizeHandler
304-
enabled: window.isWindows && window.canResize
305-
target: null
306-
grabPermissions: TapHandler.TakeOverForbidden
307-
onActiveChanged: if (active) {
308-
const pos = resizeHandler.centroid.position;
309-
const offset = resizeHandleSize + 10;
310-
let edges = 0;
311-
if (pos.x < offset) {
312-
edges |= Qt.LeftEdge;
313-
}
314-
if (pos.x >= (width - offset)) {
315-
edges += Qt.RightEdge;
316-
}
317-
if (pos.y < offset) {
318-
edges |= Qt.TopEdge;
319-
}
320-
if (pos.y >= (height - offset)) {
321-
edges |= Qt.BottomEdge;
313+
Loader {
314+
active: window.isWindows && window.canResize
315+
sourceComponent: Component {
316+
DragHandler {
317+
id: resizeHandler
318+
enabled: window.isWindows && window.canResize
319+
target: null
320+
grabPermissions: TapHandler.TakeOverForbidden
321+
onActiveChanged: {
322+
if (active) {
323+
const pos = resizeHandler.centroid.position;
324+
const offset = resizeHandleSize + 10;
325+
let edges = 0;
326+
if (pos.x < offset) {
327+
edges |= Qt.LeftEdge;
328+
}
329+
if (pos.x >= (width - offset)) {
330+
edges += Qt.RightEdge;
331+
}
332+
if (pos.y < offset) {
333+
edges |= Qt.TopEdge;
334+
}
335+
if (pos.y >= (height - offset)) {
336+
edges |= Qt.BottomEdge;
337+
}
338+
window.startSystemResize(edges);
339+
}
340+
}
322341
}
323-
window.startSystemResize(edges);
324342
}
325343
}
326344

viewer/src/PAGViewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PAGViewer::PAGViewer(int& argc, char** argv) : QApplication(argc, argv) {
2626

2727
auto PAGViewer::event(QEvent* event) -> bool {
2828
if (event->type() == QEvent::FileOpen) {
29-
auto openEvent = dynamic_cast<QFileOpenEvent*>(event);
29+
auto openEvent = static_cast<QFileOpenEvent*>(event);
3030
auto path = openEvent->file();
3131
openFile(path);
3232
}

viewer/src/PAGViewer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#pragma once
2020

2121
#include <QApplication>
22-
23-
class PAGWindow;
22+
#include "rendering/PAGWindow.h"
2423

2524
class PAGViewer : public QApplication {
2625
Q_OBJECT

viewer/src/main.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
#include "rendering/PAGView.h"
2525

2626
int main(int argc, char* argv[]) {
27+
bool cpuMode = false;
28+
std::string filePath;
29+
30+
for (int i = 0; i < argc; i++) {
31+
auto arg = std::string(argv[i]);
32+
if (arg == "-cpu") {
33+
cpuMode = true;
34+
} else if (argc > 1) {
35+
filePath = arg;
36+
}
37+
}
38+
39+
if (cpuMode) {
40+
QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
41+
}
42+
2743
QApplication::setApplicationName("PAGViewer");
2844
QApplication::setOrganizationName("Tencent");
2945
QSurfaceFormat defaultFormat = QSurfaceFormat();
@@ -42,8 +58,7 @@ int main(int argc, char* argv[]) {
4258
PAGViewer app(argc, argv);
4359
QApplication::setWindowIcon(QIcon(":/images/window-icon.png"));
4460
qmlRegisterType<pag::PAGView>("PAG", 1, 0, "PAGView");
45-
auto rootPath = QApplication::applicationDirPath();
46-
rootPath = QFileInfo(rootPath + "/../../").absolutePath();
47-
app.openFile(rootPath + "/assets/test2.pag");
61+
app.openFile(filePath.data());
62+
4863
return QApplication::exec();
4964
}

viewer/src/rendering/PAGView.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
/////////////////////////////////////////////////////////////////////////////////////////////////
1818

1919
#include "PAGView.h"
20-
#include <QGuiApplication>
21-
#include <QQuickWindow>
2220
#include <QSGImageNode>
2321
#include "pag/file.h"
2422
#include "rendering/PAGRenderThread.h"
@@ -46,14 +44,14 @@ PAGView::~PAGView() {
4644

4745
auto PAGView::getPAGWidth() const -> int {
4846
if (pagFile == nullptr) {
49-
return 100;
47+
return -1;
5048
}
5149
return pagFile->width();
5250
}
5351

5452
auto PAGView::getPAGHeight() const -> int {
5553
if (pagFile == nullptr) {
56-
return 100;
54+
return -1;
5755
}
5856
return pagFile->height();
5957
}
@@ -62,7 +60,7 @@ auto PAGView::getTotalFrame() const -> int {
6260
if (pagFile == nullptr) {
6361
return 0;
6462
}
65-
int totalFrames = static_cast<int>((getDuration() * pagFile->frameRate() + 500) / 1000);
63+
int totalFrames = static_cast<int>(std::round(getDuration() * pagFile->frameRate() / 1000.0));
6664
if (totalFrames < 1) {
6765
totalFrames = 1;
6866
}
@@ -102,7 +100,7 @@ auto PAGView::getFilePath() const -> QString {
102100

103101
auto PAGView::getBackgroundColor() const -> QColor {
104102
if (pagFile == nullptr) {
105-
return QColor::fromRgb(0, 0, 0);
103+
return QColorConstants::Black;
106104
}
107105

108106
auto color = pagFile->getFile()->getRootLayer()->composition->backgroundColor;
@@ -111,7 +109,7 @@ auto PAGView::getBackgroundColor() const -> QColor {
111109

112110
auto PAGView::getPreferredSize() const -> QSizeF {
113111
if (pagFile == nullptr) {
114-
return {200, 200};
112+
return {0, 0};
115113
}
116114

117115
auto quickWindow = window();
@@ -209,7 +207,7 @@ auto PAGView::nextFrame() -> void {
209207
setIsPlaying(false);
210208
auto progress = this->progress + progressPerFrame;
211209
if (progress > 1) {
212-
progress = 0;
210+
progress = 0.0;
213211
}
214212
setProgress(progress);
215213
}
@@ -221,7 +219,7 @@ auto PAGView::previousFrame() -> void {
221219
setIsPlaying(false);
222220
auto progress = this->progress - progressPerFrame;
223221
if (progress < 0) {
224-
progress = 1;
222+
progress = 1.0;
225223
}
226224
setProgress(progress);
227225
}
@@ -242,7 +240,7 @@ QSGNode* PAGView::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) {
242240
}
243241
}
244242

245-
auto node = dynamic_cast<QSGImageNode*>(oldNode);
243+
auto node = static_cast<QSGImageNode*>(oldNode);
246244
auto texture = drawable->getTexture();
247245
if (texture) {
248246
if (node == nullptr) {

viewer/src/rendering/PAGView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class PAGView : public QQuickItem {
7979
qreal lastPixelRatio = 1;
8080
double progress = 0.0;
8181
double progressPerFrame = 0.0;
82-
QString filePath;
82+
QString filePath = "";
8383
PAGPlayer* pagPlayer = nullptr;
8484
PAGRenderThread* renderThread = nullptr;
8585
std::shared_ptr<PAGFile> pagFile = nullptr;

0 commit comments

Comments
 (0)