-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteHandler.cpp
47 lines (38 loc) · 1.25 KB
/
DeleteHandler.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
#include "DeleteHandler.h"
#include "SignalerGraphicsView.h"
sgv::DeleteHandler::DeleteHandler(SignalerGraphicsView& a_view)
: m_view(a_view)
{
setParent(&m_view);
}
void sgv::DeleteHandler::mousePressEvent(const QMouseEvent* a_event)
{
// Disable rubber band selection for RMB to use RMB for deleting only
if (a_event->button() == Qt::LeftButton)
m_view.setDragMode(QGraphicsView::DragMode::RubberBandDrag);
else
m_view.setDragMode(QGraphicsView::DragMode::NoDrag);
}
void sgv::DeleteHandler::mouseMoveEvent(const QMouseEvent* a_event)
{
// Delete items while RMB is pressed
if (!a_event->buttons().testFlag(Qt::RightButton))
return;
QPointF pos = m_view.scenePosition(a_event);
QGraphicsItem* item = nullptr;
if (m_view.scene() != nullptr)
item = m_view.scene()->itemAt(pos, m_view.transform());
if (item != nullptr)
emit m_view.deleteItem(item);
}
void sgv::DeleteHandler::mouseReleaseEvent(const QMouseEvent* a_event)
{
if (a_event->button() != Qt::RightButton)
return;
QPointF pos = m_view.scenePosition(a_event);
QList<QGraphicsItem*> items;
if (m_view.scene() != nullptr)
items = m_view.scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, m_view.transform());
for (auto item: items)
emit m_view.deleteItem(item);
}