1
#include "Interaction.h"
4
#include "Maps/MapDocument.h"
5
#include "Maps/Projection.h"
6
#include "Maps/TrackPoint.h"
8
#include <QtGui/QMouseEvent>
9
#include <QtGui/QPainter>
13
Interaction::Interaction(MapView* aView)
14
: theView(aView), Panning(false), Dragging(false), StartDrag(0,0), EndDrag(0,0)
16
connect(this, SIGNAL(requestCustomContextMenu(const QPoint &)), theView, SLOT(on_customContextMenuRequested(const QPoint &)));
19
Interaction::~Interaction()
23
bool Interaction::panning() const
25
return (Panning && (LastPan != FirstPan));
28
MainWindow* Interaction::main()
30
return theView->main();
33
MapView* Interaction::view()
38
MapDocument* Interaction::document()
40
return theView->document();
43
const Projection& Interaction::projection() const
45
return theView->projection();
48
const QTransform& Interaction::transform() const
50
return theView->transform();
53
void Interaction::mousePressEvent(QMouseEvent * anEvent)
56
// In the name of beautifull code, Steve, add a right mouse button
57
if ( (anEvent->modifiers() & Qt::MetaModifier) ||
58
(M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::LeftButton)) ||
59
(!M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::RightButton))
63
(M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::LeftButton)) ||
64
(!M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::RightButton))
68
if (anEvent->modifiers() & Qt::ControlModifier) {
69
EndDrag = StartDrag = XY_TO_COORD(anEvent->pos());
72
if (anEvent->modifiers() & Qt::ShiftModifier) {
75
FirstPan = LastPan = anEvent->pos();
80
void Interaction::mouseReleaseEvent(QMouseEvent * anEvent)
83
if (FirstPan != LastPan)
84
view()->invalidate(true, true);
87
if (anEvent->button() == Qt::RightButton)
88
emit(requestCustomContextMenu(anEvent->pos()));
94
CoordBox DragBox(StartDrag,XY_TO_COORD(anEvent->pos()));
95
if (!DragBox.isEmpty()) {
96
view()->setViewport(DragBox,view()->rect());
97
view()->invalidate(true, true);
102
if (anEvent->button() == Qt::RightButton)
103
emit(requestCustomContextMenu(anEvent->pos()));
106
void Interaction::mouseMoveEvent(QMouseEvent* anEvent)
108
#if defined(Q_OS_MAC)
109
// In the name of beautifull code, Steve, add a right mouse button
110
if ( (anEvent->modifiers() & Qt::MetaModifier) ||
111
(M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::LeftButton)) ||
112
(!M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::RightButton))
116
(M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::LeftButton)) ||
117
(!M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::RightButton))
123
QPoint Delta = LastPan;
124
Delta -= anEvent->pos();
125
view()->panScreen(-Delta);
126
LastPan = anEvent->pos();
127
#if defined(ENABLE_NVIDIA_HACK)
128
view()->invalidate(true, false);
129
#endif // ENABLE_NVIDIA_HACK
133
EndDrag = XY_TO_COORD(anEvent->pos());
139
void Interaction::paintEvent(QPaintEvent*, QPainter& thePainter)
143
thePainter.setPen(QPen(QColor(0,0,255),1,Qt::DotLine));
144
thePainter.drawRect(QRectF(COORD_TO_XY(StartDrag),COORD_TO_XY(EndDrag)));
149
QCursor Interaction::cursor() const
151
return QCursor(Qt::ArrowCursor);