-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstickyline.cpp
144 lines (112 loc) · 3.24 KB
/
stickyline.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "stickyline.h"
#include <QPainter>
#include <QGraphicsScene>
#include <QWidget>
#include <QDebug>
StickyLine::StickyLine()
{
QPoint topLeft(10, 10);
QPoint bottomRight(staffLayout::blackLineHeight, staffLayout::blackLineHeight);
m_rec = QRectF(topLeft, bottomRight);
m_defaultColour = QColor(Qt::black);
m_collisionMode = Qt::IntersectsItemShape;
}
StickyLine::StickyLine(QPoint topLeft, QPoint bottomRight)
{
m_rec = QRectF(topLeft, bottomRight);
}
StickyLine::StickyLine(QRectF rec)
{
m_rec = rec;
}
StickyLine::StickyLine(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
{
m_rec = QRectF(topLeftX, topLeftY, bottomRightX, bottomRightY);
}
void StickyLine::setColour(QColor colour)
{
m_defaultColour = colour;
// this->update(boundingRect());
}
void StickyLine::setHighlight(QColor color)
{
m_highlightColour = color;
}
void StickyLine::setCollisionMode(Qt::ItemSelectionMode mode)
{
m_collisionMode = mode;
}
void StickyLine::addSignalHandler(StickyLineSignalHandler* handler)
{
m_signalHandler = handler;
m_signalHandler->setLine(this);
}
QRectF StickyLine::boundingRect() const
{
return m_rec;
}
void StickyLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QPen pen(Qt::black);
QBrush brush(Qt::black);
//QLineF staff(m_rec.topLeft(), m_rec.topRight());
QRectF staff = boundingRect();
//pen.setWidth(staffLayout::lineHeight);
if( scene()->collidingItems(this).isEmpty() ){
pen.setColor(m_defaultColour);
brush.setColor(m_defaultColour);
}
else{
pen.setColor(m_highlightColour);
brush.setColor(m_highlightColour);
}
//painter->setPen(pen);
painter->setBrush(brush);
painter->setPen(pen);
painter->fillRect(staff, brush);
painter->drawRect(staff);
widget->update();
//painter->drawLine(staff);
}
void StickyLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
}
void StickyLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
}
bool StickyLine::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
QVariant otherType = other->data(objectPropertyKeys::type);
QString otherStr = otherType.toString();
if(otherStr == "note"){
QVariant type = this->data(objectPropertyKeys::type);
QString typeStr = type.toString();
// map other rect to this coord system
QRectF recOther = other->boundingRect();
recOther = this->mapRectFromItem(other, recOther);
recOther.setLeft(0);
QRectF recThis = this->boundingRect();
if( typeStr.contains("white") ){
if(recThis.contains(recOther)){
return true;
}
else{
return false;
}
}
if( typeStr.contains("line") ){
if(recThis.intersects(recOther)){
return true;
}
else{
return false;
}
}
// return QGraphicsItem::collidesWithItem(other, Qt::IntersectsItemBoundingRect);
}
else{
return false;
}
}