-
Notifications
You must be signed in to change notification settings - Fork 1
/
sceneanimation.cpp
62 lines (55 loc) · 1.75 KB
/
sceneanimation.cpp
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
#include "sceneanimation.h"
#include <iostream>
#include "window.h"
SceneAnimation::SceneAnimation(QWidget *parent)
:Scene (parent)
{
// setThickness(3);
setItemIndexMethod(QGraphicsScene::ItemIndexMethod::NoIndex);
parser = new FrameParser(this);
connect(&timer, SIGNAL(timeout()), this, SLOT(doAnimation()));
}
void SceneAnimation::open(const QString &fileName)
{
if (fileName.isEmpty()) return;
if (!parser->setInputFile(fileName)){
QMessageBox(QMessageBox::Icon::Critical, "ERROR", "BUG BUG BUG").exec();
return;
}
window->setOpenFileName(fileName.split("/").back());
}
void SceneAnimation::play()
{
parser->reset();
this->clear();
timer.start(window->getDelay());
}
void SceneAnimation::doAnimation()
{
if (!parser->nextFrame(window->isStopAtEachFrame())) {
timer.stop();
if (!window->isPauseAtEnd()) clear();
parser->reset();
return;
}
}
void SceneAnimation::drawBackground(QPainter *painter, const QRectF &rect)
{
if (window->isRulerOn()){
Scene::drawBackground(painter, rect);
}
// else {
// int halfHeight = static_cast<int>(this->height()) / 2;
// int halfWidth = static_cast<int>(this->width()) / 2;
// const int halfThick = thickness / 2; //make it center
// // Draw ox and oy
// painter->setPen(QPen(QBrush(Qt::black), 1));
// painter->setOpacity(0.6);
// painter->drawLine(0, halfHeight + halfThick, static_cast<int>(this->width()), halfHeight + halfThick);
// painter->drawLine(halfWidth + halfThick, 0, halfWidth + halfThick, static_cast<int>(this->height()));
// }
}
void SceneAnimation::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
{
QGraphicsScene::wheelEvent(wheelEvent);
}