-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathball.cpp
55 lines (46 loc) · 1.18 KB
/
ball.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
#include "ball.h"
#include "controller.h"
Ball* Ball::clicked;
QPoint Ball::startDragPos;
QPoint Ball::mouseDownOffset;
Ball::Ball(int n, QPoint p, QWidget* pr, QPair<int,int> i)
{
setParent(pr);
number = n;
pos = p;
index = i;
}
void Ball::setImage(){
if(number == 30){
QPixmap image = QPixmap::fromImage(QImage(":/images/trans.jpg"));
setPixmap(image);
}else{
QPixmap image = QPixmap::fromImage(QImage(":/images/ball"+QString::number(number)+".png"));
setPixmap(image);
}
this->move(pos);
raise();
show();
}
void Ball::mousePressEvent(QMouseEvent* ev){
if(ev->button() == Qt::LeftButton){
startDragPos = pos;
mouseDownOffset = pos - ev->globalPos();
}
}
void Ball::mouseMoveEvent(QMouseEvent* ev){
if(number!=30){
clicked = this;
QPoint point = ev->globalPos() + mouseDownOffset;
clicked->move(point);
clicked->raise();
}
}
void Ball::mouseReleaseEvent(QMouseEvent* ev){
if(ev->buttons()) return;
if(ev->x() >=10 || ev->y() >= 10){
Controller::dragMove(ev);
}else {
clicked = NULL;
}
}