-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointmarker.cpp
More file actions
51 lines (46 loc) · 1.22 KB
/
pointmarker.cpp
File metadata and controls
51 lines (46 loc) · 1.22 KB
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
#include "pointmarker.h"
#include <QDebug>
PointMarker::PointMarker(QWidget *parent) :
QWidget(parent),
m_selected(false),
m_dragging(false)
{
m_marker.load(QCoreApplication::applicationDirPath() + "/img/marker.png");
m_markerSelected.load(QCoreApplication::applicationDirPath() + "/img/marker_selected.png");
setCursor(Qt::PointingHandCursor);
setMaximumSize(m_marker.size());
setMinimumSize(m_marker.size());
}
void PointMarker::paintEvent(QPaintEvent *event)
{
QPainter p;
p.begin(this);
p.drawPixmap(0, 0, m_selected ? m_markerSelected : m_marker);
p.end();
}
void PointMarker::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
m_selected = !m_selected;
repaint();
emit selectionChanged(m_selected);
}
else if (event->button() == Qt::RightButton) {
m_pressPos = event->pos();
m_dragging = true;
emit dragStarted();
}
}
void PointMarker::mouseMoveEvent(QMouseEvent *event)
{
if (m_dragging) {
emit dragMove(event->pos() - m_pressPos);
}
}
void PointMarker::mouseReleaseEvent(QMouseEvent *event)
{
if (m_dragging) {
m_dragging = false;
emit dragFinished();
}
}