~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to src/Interaction/Interaction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Interaction.h"
 
2
 
 
3
#include "MapView.h"
 
4
#include "Maps/MapDocument.h"
 
5
#include "Maps/Projection.h"
 
6
#include "Maps/TrackPoint.h"
 
7
 
 
8
#include <QtGui/QMouseEvent>
 
9
#include <QtGui/QPainter>
 
10
 
 
11
#include <math.h>
 
12
 
 
13
Interaction::Interaction(MapView* aView)
 
14
: theView(aView), Panning(false), Dragging(false), StartDrag(0,0), EndDrag(0,0)
 
15
{
 
16
        connect(this, SIGNAL(requestCustomContextMenu(const QPoint &)), theView, SLOT(on_customContextMenuRequested(const QPoint &)));
 
17
}
 
18
 
 
19
Interaction::~Interaction()
 
20
{
 
21
}
 
22
 
 
23
bool Interaction::panning() const
 
24
{
 
25
        return (Panning && (LastPan != FirstPan));
 
26
}
 
27
 
 
28
MainWindow* Interaction::main()
 
29
{
 
30
        return theView->main();
 
31
}
 
32
 
 
33
MapView* Interaction::view()
 
34
{
 
35
        return theView;
 
36
}
 
37
 
 
38
MapDocument* Interaction::document()
 
39
{
 
40
        return theView->document();
 
41
}
 
42
 
 
43
const Projection& Interaction::projection() const
 
44
{
 
45
        return theView->projection();
 
46
}
 
47
 
 
48
const QTransform& Interaction::transform() const
 
49
{
 
50
        return theView->transform();
 
51
}
 
52
 
 
53
void Interaction::mousePressEvent(QMouseEvent * anEvent)
 
54
{
 
55
#if defined(Q_OS_MAC)
 
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))
 
60
                )
 
61
#else
 
62
        if (
 
63
                (M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::LeftButton)) ||
 
64
                (!M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::RightButton))
 
65
                )
 
66
#endif // Q_OS_MAC
 
67
        {
 
68
                if (anEvent->modifiers() & Qt::ControlModifier) {
 
69
                        EndDrag = StartDrag = XY_TO_COORD(anEvent->pos());
 
70
                        Dragging = true;
 
71
                } else 
 
72
                if (anEvent->modifiers() & Qt::ShiftModifier) {
 
73
                } else {
 
74
                        Panning = true;
 
75
                        FirstPan = LastPan = anEvent->pos();
 
76
                }
 
77
        }
 
78
}
 
79
 
 
80
void Interaction::mouseReleaseEvent(QMouseEvent * anEvent)
 
81
{
 
82
        if (Panning) {
 
83
                if (FirstPan != LastPan)
 
84
                        view()->invalidate(true, true);
 
85
#ifndef _MOBILE
 
86
                else
 
87
                        if (anEvent->button() == Qt::RightButton)
 
88
                                emit(requestCustomContextMenu(anEvent->pos()));
 
89
#endif
 
90
                Panning = false;
 
91
        } else
 
92
        if (Dragging)
 
93
        {
 
94
                CoordBox DragBox(StartDrag,XY_TO_COORD(anEvent->pos()));
 
95
                if (!DragBox.isEmpty()) {
 
96
                        view()->setViewport(DragBox,view()->rect());
 
97
                        view()->invalidate(true, true);
 
98
                        view()->launch(0);
 
99
                }
 
100
                Dragging = false;
 
101
        } else
 
102
                if (anEvent->button() == Qt::RightButton)
 
103
                        emit(requestCustomContextMenu(anEvent->pos()));
 
104
}
 
105
 
 
106
void Interaction::mouseMoveEvent(QMouseEvent* anEvent)
 
107
{
 
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))
 
113
                )
 
114
#else
 
115
        if (
 
116
                (M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::LeftButton)) ||
 
117
                (!M_PREFS->getMouseSingleButton() && (anEvent->buttons() & Qt::RightButton))
 
118
                )
 
119
#endif // Q_OS_MAC
 
120
        {
 
121
                if (Panning)
 
122
                {
 
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
 
130
                } else
 
131
                if (Dragging)
 
132
                {
 
133
                        EndDrag = XY_TO_COORD(anEvent->pos());
 
134
                        view()->update();
 
135
                }
 
136
        }
 
137
}
 
138
 
 
139
void Interaction::paintEvent(QPaintEvent*, QPainter& thePainter)
 
140
{
 
141
        if (Dragging)
 
142
        {
 
143
                thePainter.setPen(QPen(QColor(0,0,255),1,Qt::DotLine));
 
144
                thePainter.drawRect(QRectF(COORD_TO_XY(StartDrag),COORD_TO_XY(EndDrag)));
 
145
        }
 
146
}
 
147
 
 
148
#ifndef Q_OS_SYMBIAN
 
149
QCursor Interaction::cursor() const
 
150
{
 
151
        return QCursor(Qt::ArrowCursor);
 
152
}
 
153
#endif