This repository has been archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.cpp
103 lines (91 loc) · 2.01 KB
/
sprite.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
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
#include "sprite.h"
#include <QPainter>
#include <QKeyEvent>
#include <QGraphicsSceneHoverEvent>
#include <QDebug>
Sprite::Sprite(QGraphicsItem *parent) :
QGraphicsItem(parent)
{
this->_pixmap = 0;
}
Sprite::~Sprite()
{
}
void Sprite::setPixmap(QPixmap *pixmap)
{
this->width = pixmap->width();
this->height = pixmap->height();
this->_pixmap = pixmap;
this->update();
}
QPixmap* Sprite::getPixmap(void)
{
return this->_pixmap;
}
qreal Sprite::getWidth()
{
return this->width;
}
qreal Sprite::getHeight()
{
return this->height;
}
void Sprite::setHeight(qreal height)
{
this->height = height;
}
void Sprite::setWidth(qreal width)
{
this->width = width;
}
void Sprite::resize(qreal width, qreal height)
{
this->width = width;
this->height = height;
this->update();
}
QRectF Sprite::boundingRect() const
{
//if (this->_pixmap)return QRectF();
qreal pw = 1.0;
return QRectF(QPoint(0,0),QSizeF(this->width,this->height)).adjusted(-pw/2, -pw/2, pw/2, pw/2);
}
void Sprite::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if(this->_pixmap)
painter->drawPixmap(0,0,this->width,this->height,*this->_pixmap);
}
void Sprite::keyPressEvent(QKeyEvent *event)
{
emit onKeyPress(event->key());
}
void Sprite::keyReleaseEvent(QKeyEvent *event)
{
emit onKeyRelease(event->key());
}
void Sprite::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit onMousePress(event->pos().x(),event->pos().y(),event->buttons());
}
void Sprite::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
emit onMouseRelease(event->pos().x(),event->pos().y(),event->buttons());
}
void Sprite::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
emit onHover(event);
}
void Sprite::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
}
void Sprite::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
}
void Sprite::foucsInEvent(QFocusEvent *event)
{
emit onFoucs(true);
}
void Sprite::foucsOutEvent(QFocusEvent *event)
{
emit onFoucs(false);
}