-
Notifications
You must be signed in to change notification settings - Fork 0
/
veshapeitem.cpp
80 lines (67 loc) · 2.64 KB
/
veshapeitem.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
#include "veshapeitem.h"
VeShapeItem::VeShapeItem(QObject *parent)
: QObject(parent)
, applied_pattern_(NO_PATTERN)
{
connect(parent, SIGNAL(itemSelected(const VeShapeItem *)), this, SLOT(itemSelectionEvent(const VeShapeItem *)));
connect(parent, SIGNAL(itemUnderCursorChanged(const QGraphicsItem *)), this, SLOT(itemUnderCursorEvent(const QGraphicsItem *)));
}
void VeShapeItem::itemSelectionEvent(const VeShapeItem *p_item)
{
for (int i = 0; i < grabbers_.count(); i++) {
grabbers_[i]->setVisible(this == p_item);
}
}
void VeShapeItem::itemUnderCursorEvent(const QGraphicsItem *p_item)
{
applied_pattern_ = (dynamic_cast<QGraphicsItem *>(this) == p_item)? UNDER_CURSOR : NO_PATTERN;
}
void VeShapeItem::addGrabber(int p_index, bool p_visible, bool p_active, bool p_highlight)
{
VeGrabberDot *new_grabber = new VeGrabberDot(this, dynamic_cast<QGraphicsItem *>(this), p_visible, p_active, p_highlight);
connect(new_grabber, SIGNAL(itemMoved(VeGrabberDot *, const QPointF &, Qt::MouseButtons)),
this, SLOT(doOnGrabberMoved(VeGrabberDot *, const QPointF &, Qt::MouseButtons)));
connect(new_grabber, SIGNAL(itemRelease(VeGrabberDot *)),
this, SLOT(doOnGrabberRelease(VeGrabberDot *)));
connect(parent(), SIGNAL(itemUnderCursorChanged(const QGraphicsItem *)),
new_grabber, SLOT(itemUnderCursorEvent(const QGraphicsItem *)));
if (p_index < 0 || p_index >= grabbers_.count() ) {
grabbers_.append(new_grabber);
} else {
grabbers_.insert(p_index, new_grabber);
}
}
void VeShapeItem::initializeGrabbers()
{
int delta_count_grabbers = grabbersCount() - grabbers_.count();
if (delta_count_grabbers < 0) {
for(int i = 0; i < delta_count_grabbers ; i++) {
delete grabbers_.last();
grabbers_.removeLast();
}
} else if (delta_count_grabbers > 0) {
for (int i = 0; i < delta_count_grabbers; i++) {
addGrabber();
}
}
setGrabbersPositions();
}
void VeShapeItem::drawPattern(QPainter *p_painter)
{
switch (applied_pattern_) {
case UNDER_CURSOR: {
QPen pattern_pen(Qt::red);
QColor pattern_brush_color(Qt::red);
pattern_brush_color.setAlpha((brush().color().alpha() > 0)? 255: 0);
QBrush pattern_brush(pattern_brush_color);
pattern_brush.setStyle(Qt::Dense6Pattern);
p_painter->setPen(pattern_pen);
p_painter->setBrush(pattern_brush);
p_painter->drawPath(shape());
break;
}
default: {
break;
}
}
}