-
Notifications
You must be signed in to change notification settings - Fork 5
/
transform.cpp
122 lines (98 loc) · 2.6 KB
/
transform.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "transform.h"
Transform::Transform(QWidget* parent):
AbstractSelection(QIcon(":/tools/select.svg"),"Transform Tool (V)",
QCursor(QIcon(":/tools/select.svg").pixmap(QSize(15,15)),0,0),
Tool::SELECTION, Tool::TRANSFORM, parent)
{
setShortcut(Qt::Key_V);
_rect = new BoundingRectItem();
_boundsDrawn = false;
}
Transform::~Transform()
{
}
void Transform::press(QGraphicsSceneMouseEvent *event)
{
if(!_autoSelect){
return;
}
QGraphicsItem* itm = _scene->itemAt(event->pos(),QTransform());
itm->setSelected(true);
emit _scene->selectionChanged();
}
void Transform::release(QGraphicsSceneMouseEvent *event)
{
}
void Transform::move(QGraphicsSceneMouseEvent *event)
{
if(_boundsDrawn){
drawBoundingRect();
}
}
void Transform::drawBounds(bool draw)
{
if(draw){
drawBoundingRect();
}else{
_rect->setVisible(false);
}
_boundsDrawn = draw;
}
void Transform::setTransformMode(bool set)
{
_rect->transformMode(set);
}
void Transform::drawBoundingRect()
{
if(_scene == NULL){
return;
}
QList<QGraphicsItem*> selected = _scene->selectedItems();
QList<QGraphicsItem*>::iterator itr = selected.begin();
QPointF max(INT_MIN,INT_MIN),min(INT_MAX,INT_MAX);
for(;itr != selected.end();++itr){
QGraphicsItem* temp = *itr;
QPointF itmTopLeft = temp->boundingRect().topLeft();
QPointF itmBottomRight = temp->boundingRect().bottomRight();
itmTopLeft = temp->mapToScene(itmTopLeft);
itmBottomRight = temp->mapToScene(itmBottomRight);
if(itmTopLeft.x() < min.x()){
min.setX(itmTopLeft.x());
}
if(itmTopLeft.y() < min.y()){
min.setY(itmTopLeft.y());
}
if(itmBottomRight.x() > max.x()){
max.setX(itmBottomRight.x());
}
if(itmBottomRight.y() > max.y()){
max.setY(itmBottomRight.y());
}
}
_rect->setPoints(min,max);
if(_scene->items().contains(_rect)){
_rect->setVisible(true);
}else{
_scene->addItem(_rect);
}
}
void Transform::removeBoundingRect()
{
delete _rect;
}
QWidget* Transform::getToolMenu()
{
if (_menuExists) {
return _menu;
}
_menuExists = true;
TransformMenu *transformMenu = new TransformMenu();
_menu = transformMenu;
connectMenu(transformMenu);
return _menu;
}
void Transform::connectMenu(TransformMenu *menu)
{
connect(menu, SIGNAL(showTransform(bool)), this, SLOT(drawBounds(bool)));
connect(menu, SIGNAL(autoSelect(bool)),this,SLOT(setAutoSelect(bool)));
}