]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robomon/MainWindow.cpp
ed0ba94f0e6974e3400e4493e5ae7eff10a7526c
[eurobot/public.git] / src / robomon / MainWindow.cpp
1 /*
2  * MainWindow.cpp                       07/10/31
3  *
4  * Top window layer. All tabs will be added to this main window.
5  *
6  * Copyright: (c) 2007 CTU Dragons
7  *            CTU FEE - Department of Control Engineering
8  * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
9  * License: GNU GPL v.2
10  */
11
12 #include <QtGui>
13
14 #include "MainWindow.h"
15 #include "RobomonTuning.h"
16 #include "RobomonAtlantis.h"
17
18 MainWindow::MainWindow()
19 {
20         QFont font;
21         font.setPointSize(8);
22         setFont(font);
23
24         createTabs();
25         createActions();
26         createMenus();
27         createStatusBar();
28
29         setCentralWidget(tabWidget);
30         
31         addRobomonAtlantisTab();
32 }
33
34 void MainWindow::closeEvent(QCloseEvent *event)
35 {
36         while (closeCurrentTab() != -1) ;
37         event->accept();
38 }
39
40 void MainWindow::addRobomonTuningTab()
41 {
42         RobomonTuning *robomonTuning = new RobomonTuning();
43         tabWidget->addTab(robomonTuning, tr("Robomon Tuning"));
44         tabWidget->setCurrentWidget(robomonTuning);
45 }
46
47 void MainWindow::addRobomonAtlantisTab()
48 {
49         RobomonAtlantis *robomonAtlantis = new RobomonAtlantis();
50         tabWidget->addTab(robomonAtlantis, tr("Robomon - Temples of Atlantis"));
51         tabWidget->setCurrentWidget(robomonAtlantis);
52         connect(showMap, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(showMap(bool)));
53         connect(showTrails, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(showTrails(bool)));
54         connect(resetTrails, SIGNAL(triggered()), robomonAtlantis, SLOT(resetTrails()));
55         connect(useOpenGL, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(useOpenGL(bool)));
56
57         connect(showRobotRef, SIGNAL(toggled(bool)), robomonAtlantis->robotRefPos, SLOT(mySetVisible(bool)));
58         connect(showRobotEst, SIGNAL(toggled(bool)), robomonAtlantis->robotEstPosBest, SLOT(mySetVisible(bool)));
59         connect(showRobotEstOdo, SIGNAL(toggled(bool)), robomonAtlantis->robotEstPosOdo, SLOT(mySetVisible(bool)));
60         connect(showRobotEstIndepOdo, SIGNAL(toggled(bool)), robomonAtlantis->robotEstPosIndepOdo, SLOT(mySetVisible(bool)));
61         connect(robomonAtlantis->playgroundScene, SIGNAL(mouseMoved(QPointF)), this, SLOT(showCoordinates(QPointF)));
62
63         showRobotRef->setChecked(true);
64         showRobotEst->setChecked(true);
65         showRobotEstOdo->setChecked(false);
66         showRobotEstIndepOdo->setChecked(false);
67 }
68
69 void MainWindow::showCoordinates(QPointF pos)
70 {
71         QString s = QString("X=%1 m, Y=%2 m").arg(pos.x(), 0, 'f', 3).arg(pos.y(), 0, 'f', 3);
72         coordinates->setText(s);
73 }
74
75 void MainWindow::about()
76 {
77         QMessageBox::about(this, tr("About Robomon"),
78                 tr(
79                 "<center>"
80                 "<h1>Robomon 2.0</h1><br /><br />"
81                 "<b>Robomon</b> is an application for graphic "
82                 "visualization and control of the robot.<br /><br />"
83                 "<b>Authors:</b> "
84                 "Martin &#381;&#205;DEK, "
85                 "Michal SOJKA, "
86                 "TRAN Duy Khanh"
87                 "<br />"
88                 "<br />"
89                 "<a href=\"http://rtime.felk.cvut.cz/dragons\">CTU Dragons</a>"
90                 "<br />"
91                 "<br />"
92                 "<b>License:</b> GNU GPL v.2<br /></center>"
93                 ));
94 }
95
96 void MainWindow::help()
97 {
98         QMessageBox::about(this, tr("Help"),
99                 tr("Here will be the help of the Robomon"));
100 }
101
102 void MainWindow::createActions()
103 {
104         exitAct = new QAction(tr("E&xit"), this);
105         exitAct->setShortcut(tr("Ctrl+Q"));
106         exitAct->setStatusTip(tr("Exit the application"));
107         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
108
109         robomonTuningAct = new QAction(QIcon(":/images/tuning.png"), 
110                                                 tr("Robot &Tuning"), this);
111         robomonTuningAct->setShortcut(tr("Ctrl+T"));
112         robomonTuningAct->setStatusTip(tr("Robomon of the Robot Explorer - tuning panel"));
113         connect(robomonTuningAct, SIGNAL(triggered()), 
114                         this, SLOT(addRobomonTuningTab()));
115
116         robomonAtlantisAct = new QAction(QIcon(":/images/robomon_atlantis.png"), 
117                                                 tr("Robot &Atlantis"), this);
118         robomonAtlantisAct->setShortcut(tr("Ctrl+A"));
119         robomonAtlantisAct->setStatusTip(tr("Robomon of the Robot Atlantis"));
120         connect(robomonAtlantisAct, SIGNAL(triggered()), 
121                         this, SLOT(addRobomonAtlantisTab()));
122
123         helpAct = new QAction(tr("&Help"), this);
124         helpAct->setStatusTip(tr("Show the Qt library's About box"));
125         connect(helpAct, SIGNAL(triggered()), this, SLOT(help()));
126
127         aboutAct = new QAction(tr("&About"), this);
128         aboutAct->setStatusTip(tr("Show information about the application"));
129         connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
130
131         connect(closeToolButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
132         
133         showTrails = new QAction("Show &trails", this);
134         showTrails->setCheckable(true);
135         showMap = new QAction("Show &map", this);
136         showMap->setCheckable(true);
137         resetTrails = new QAction("Re&set trails", this);
138
139         useOpenGL = new QAction("Use &OpenGL", this);
140         useOpenGL->setCheckable(true);
141         
142
143         showRobotRef = new QAction("&Reference position", this);
144         showRobotRef->setCheckable(true);
145         showRobotEst = new QAction("&Best available estimated position", this);
146         showRobotEst->setCheckable(true);
147         showRobotEstOdo = new QAction("&Motor odometry", this);
148         showRobotEstOdo->setCheckable(true);
149         showRobotEstIndepOdo = new QAction("&Independent odometry", this);
150         showRobotEstIndepOdo->setCheckable(true);
151 }
152
153 void MainWindow::createMenus()
154 {
155         fileMenu = menuBar()->addMenu(tr("&File"));
156         fileMenu->addSeparator();
157         fileMenu->addAction(exitAct);
158         
159         QMenu *m;
160         m = menuBar()->addMenu(tr("&View"));
161         m->addAction(showMap);
162         m->addAction(showTrails);
163         m->addAction(resetTrails);
164         QMenu *robot = m->addMenu(tr("&Robot"));
165         m->addAction(useOpenGL);
166
167         robot->addAction(showRobotRef);
168         robot->addAction(showRobotEst);
169         robot->addAction(showRobotEstOdo);
170         robot->addAction(showRobotEstIndepOdo);
171         
172         toolsMenu = menuBar()->addMenu(tr("&Tools"));
173         toolsMenu->addAction(robomonTuningAct);
174         toolsMenu->addAction(robomonAtlantisAct);
175         
176         menuBar()->addSeparator();
177         
178         helpMenu = menuBar()->addMenu(tr("&Help"));
179         helpMenu->addAction(helpAct);
180         helpMenu->addAction(aboutAct);
181 }
182
183 void MainWindow::createStatusBar()
184 {
185         coordinates = new QLabel();
186         statusBar()->showMessage(tr("Ready"));
187         statusBar()->addPermanentWidget(coordinates);
188 }
189
190 void MainWindow::createTabs()
191 {
192         tabWidget = new QTabWidget;
193         closeToolButton = new QToolButton();
194
195         closeToolButton->setIcon(QIcon(":/images/close.png"));
196         closeToolButton->setIconSize(QSize(14, 14));
197         closeToolButton->setShortcut(tr("Ctrl+W"));
198         closeToolButton->setToolTip(tr("Close tab (Ctrl+W)"));
199         tabWidget->setCornerWidget(closeToolButton);
200 }
201
202 int MainWindow::closeCurrentTab()
203 {
204         int index = tabWidget->currentIndex();
205         if (index < 0)
206                 return -1;
207         QWidget* tabPage = tabWidget->widget(index);
208         tabPage->close();
209         tabWidget->removeTab(index);
210         delete tabPage;
211
212         return 0;
213 }