-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmygraphicsscene.h
46 lines (39 loc) · 1.27 KB
/
mygraphicsscene.h
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
#ifndef MYGRAPHICSSCENE_H
#define MYGRAPHICSSCENE_H
#include <QtCore>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneDragDropEvent>
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QObject>
#include <QList>
#include <QMap>
class MyGraphicsScene : public QGraphicsScene
{
Q_OBJECT //使用信号和槽类所必须加上的宏定义
public:
MyGraphicsScene(QObject *parent);
void selectedItem(QGraphicsItem *item);
signals:
void itemClicked(QGraphicsItem *item);
void itemsMoving(QGraphicsItem *item);
void itemsMoved(QMap<QGraphicsItem*, QPointF> itemsnewpos,
QMap<QGraphicsItem*, QPointF> itemsoldpos);
void itemStopMoving(bool released);
public slots:
void firstSelectedItem(QGraphicsItem *item);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
private:
QList<QGraphicsItem*> itemlist;
QMap<QGraphicsItem*, QPointF> itemsOldPos;
QMap<QGraphicsItem*, QPointF> itemsNewPos;
QGraphicsItem *moving;
QPointF moving_start;
bool isPressing;
QPointF oldPos;
};
#endif // MYGRAPHICSSCENE_H