-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyGraphicsScene.cpp
33 lines (30 loc) · 980 Bytes
/
MyGraphicsScene.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
#include "MyGraphicsScene.h"
#include <iostream>
#include "qgraphicsscene.h"
#include "qgraphicsitem.h"
#include "qlist.h"
#include "qmath.h"
#include "bot.h"
MyGraphicsScene::MyGraphicsScene(): QGraphicsScene(){
selected = NULL;
}
void MyGraphicsScene::mousePressEvent( QGraphicsSceneMouseEvent* mouseEvent ){
QPointF mousePos = mouseEvent->scenePos();
QList<QGraphicsItem*> sceneItems = this->items();
QList<QGraphicsItem*>::iterator it;
for( it = sceneItems.begin(); it != sceneItems.end(); it++ ){
QPointF itemPos = (*it)->pos();
if( (int)abs(mousePos.rx() - itemPos.rx()) < 10 && (int)abs(mousePos.ry() - itemPos.ry()) < 10){
selected = (Bot*)(*it);
}
}
}
void MyGraphicsScene::mouseMoveEvent( QGraphicsSceneMouseEvent* mouseEvent ){
if(selected != NULL){
selected->_setPos(QPointF(mouseEvent->scenePos().rx(),mouseEvent->scenePos().ry()));
}
}
void MyGraphicsScene::mouseReleaseEvent( QGraphicsSceneMouseEvent* mouseEvent ){
if(selected != NULL){
}
}