-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasepicker.cpp
60 lines (48 loc) · 1.78 KB
/
basepicker.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
#include <QGraphicsScene>
#include "basepicker.h"
#include "baseelement.h"
#include "basespace.h"
BasePicker::BasePicker(BaseElement *element)
{
m_element = element;
m_space = element->space();
this->hide();
element->scene()->addItem(this);
this->setFlag(QGraphicsItem::ItemIsSelectable,false);
this->setFlag(QGraphicsItem::ItemIsMovable,false);
this->setFlag(QGraphicsItem::ItemIsFocusable,false);
this->setFlag(QGraphicsItem::ItemAcceptsInputMethod,false);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges,false);
this->setFlag(QGraphicsItem::ItemSendsScenePositionChanges,false);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true);
this->setAcceptHoverEvents(true);
connect(element->space(),&BaseSpace::scaled,this,&BasePicker::sceneScaled);
element->stackBefore(this);
}
void BasePicker::sceneScaled()
{
this->setByElement();
}
QVariant BasePicker::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if (change==QGraphicsItem::ItemVisibleChange){
if (value.toBool()){
this->setByElement();
}
}
return QGraphicsObject::itemChange(change,value);
}
QPointF BasePicker::elementToPicker(const QPointF &p) const
{
BaseSpace * space = this->space();
return this->deviceTransform(space->viewportTransform()).inverted().map(
m_element->deviceTransform(space->viewportTransform()).map(p)
);
}
QPointF BasePicker::pickerToElement(const QPointF &p) const
{
BaseSpace * space = this->space();
return m_element->deviceTransform(space->viewportTransform()).inverted().map(
this->deviceTransform(space->viewportTransform()).map(p)
);
}