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
|
// $Id$
#include "RootPanel.h"
#include <QtGui/qmenubar.h>
#include <QtGui/qapplication.h>
#include <QtGui/qsplitter.h>
#include <stdlib.h>
#include "NodeItem.h"
#include "Command.h"
RootPanel::RootPanel(QGraphicsScene &c, QWidget *parent)
: QMainWindow(parent), canvas(c)
{
QSplitter *s1 = new QSplitter( Qt::Vertical, parent );
navview = new MapView(canvas, s1);
details = new DetailView(s1);
QMenu *filemenu = menuBar()->addMenu(tr("&File"));
QAction *exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcut(Qt::CTRL + Qt::Key_Q);
connect(exitAct, SIGNAL(triggered()), qApp, SLOT(quit()));
filemenu->addAction(exitAct);
setCentralWidget(s1);
}
RootPanel::~RootPanel()
{
clear();
}
void
RootPanel::addUnit(NavUnit *unit)
{
NodeItem *el = new NodeItem(&canvas, *unit);
nodeMap.bind(unit->getID(), el);
// only for first GPS write details.
if(unit->getID() == 1)
{
this->details->currentNode(unit);
}
}
void
RootPanel::updateUnit(NavUnit *unit)
{
NodeItem *el = 0;
nodeMap.find(unit->getID(), el);
UnitLocation loc = unit->getLocation();
//width is incl. borders and text, so correct for this .
loc.x_ = (long)loc.x_ % (navview->width() - 40);
loc.y_ = (long)loc.y_ % (navview->height() - 80);
el->moveBy(loc.x_ - el->pos().x() , loc.y_ - el->pos().y());
el->show();
canvas.update();
if(unit->getID() == 1)
{
this->details->updateLocation(loc);
}
}
void
RootPanel::clear()
{
navview->clear();
}
int NavEvent::registered_type_ = (-1);
NavEvent::NavEvent(CommandBase* cmd)
: QEvent (static_cast<QEvent::Type> (NavEvent::registered_type_)),
cmd_ (cmd)
{
}
NavEvent::~NavEvent ()
{
}
CommandBase* NavEvent::cmd () const
{
return this->cmd_;
}
void NavEvent::set_type (int type)
{
NavEvent::registered_type_ = type;
}
QEvent::Type NavEvent::get_type ()
{
return static_cast<QEvent::Type> (NavEvent::registered_type_);
}
void
RootPanel::customEvent(QEvent *e)
{
if (e->type () == NavEvent::get_type ())
{
NavEvent* ne = dynamic_cast<NavEvent*> (e);
CommandBase* cmd = ne->cmd ();
cmd->execute();
delete cmd;
}
}
|