]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robomon/MainWindow.cpp
MainWindow: add menu item (robomon): View -> Show shape detect
[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(showShapeDetect, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(showShapeDetect(bool)));
56         connect(useOpenGL, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(useOpenGL(bool)));
57
58         connect(showRobotRef, SIGNAL(toggled(bool)), robomonAtlantis->robotRefPos, SLOT(mySetVisible(bool)));
59         connect(showRobotEst, SIGNAL(toggled(bool)), robomonAtlantis->robotEstPosBest, SLOT(mySetVisible(bool)));
60         connect(showRobotEstOdo, SIGNAL(toggled(bool)), robomonAtlantis->robotEstPosOdo, SLOT(mySetVisible(bool)));
61         connect(showRobotEstIndepOdo, SIGNAL(toggled(bool)), robomonAtlantis->robotEstPosIndepOdo, SLOT(mySetVisible(bool)));
62         connect(robomonAtlantis->playgroundScene, SIGNAL(mouseMoved(QPointF)), this, SLOT(showCoordinates(QPointF)));
63
64         showRobotRef->setChecked(true);
65         showRobotEst->setChecked(true);
66         showRobotEstOdo->setChecked(false);
67         showRobotEstIndepOdo->setChecked(false);
68 }
69
70 void MainWindow::showCoordinates(QPointF pos)
71 {
72         QString s = QString("X=%1 m, Y=%2 m").arg(pos.x(), 0, 'f', 3).arg(pos.y(), 0, 'f', 3);
73         coordinates->setText(s);
74 }
75
76 void MainWindow::about()
77 {
78         QMessageBox::about(this, tr("About Robomon"),
79                 tr(
80                 "<center>"
81                 "<h1>Robomon 2.0</h1><br /><br />"
82                 "<b>Robomon</b> is an application for graphic "
83                 "visualization and control of the robot.<br /><br />"
84                 "<b>Authors:</b> "
85                 "Martin &#381;&#205;DEK, "
86                 "Michal SOJKA, "
87                 "TRAN Duy Khanh"
88                 "<br />"
89                 "<br />"
90                 "<a href=\"http://rtime.felk.cvut.cz/dragons\">CTU Dragons</a>"
91                 "<br />"
92                 "<br />"
93                 "<b>License:</b> GNU GPL v.2<br /></center>"
94                 ));
95 }
96
97 void MainWindow::help()
98 {
99         QMessageBox::about(this, tr("Help"),
100                 tr("Here will be the help of the Robomon"));
101 }
102
103 void MainWindow::createActions()
104 {
105         exitAct = new QAction(tr("E&xit"), this);
106         exitAct->setShortcut(tr("Ctrl+Q"));
107         exitAct->setStatusTip(tr("Exit the application"));
108         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
109
110         robomonTuningAct = new QAction(QIcon(":/images/tuning.png"), 
111                                                 tr("Robot &Tuning"), this);
112         robomonTuningAct->setShortcut(tr("Ctrl+T"));
113         robomonTuningAct->setStatusTip(tr("Robomon of the Robot Explorer - tuning panel"));
114         connect(robomonTuningAct, SIGNAL(triggered()), 
115                         this, SLOT(addRobomonTuningTab()));
116
117         robomonAtlantisAct = new QAction(QIcon(":/images/robomon_atlantis.png"), 
118                                                 tr("Robot &Atlantis"), this);
119         robomonAtlantisAct->setShortcut(tr("Ctrl+A"));
120         robomonAtlantisAct->setStatusTip(tr("Robomon of the Robot Atlantis"));
121         connect(robomonAtlantisAct, SIGNAL(triggered()), 
122                         this, SLOT(addRobomonAtlantisTab()));
123
124         helpAct = new QAction(tr("&Help"), this);
125         helpAct->setStatusTip(tr("Show the Qt library's About box"));
126         connect(helpAct, SIGNAL(triggered()), this, SLOT(help()));
127
128         aboutAct = new QAction(tr("&About"), this);
129         aboutAct->setStatusTip(tr("Show information about the application"));
130         connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
131
132         connect(closeToolButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
133         
134         showTrails = new QAction("Show &trails", this);
135         showTrails->setCheckable(true);
136         showMap = new QAction("Show &map", this);
137         showMap->setCheckable(true);
138         showShapeDetect = new QAction("Show s&hape detect", this);
139         showShapeDetect->setCheckable(true);
140         resetTrails = new QAction("Re&set trails", this);
141
142         useOpenGL = new QAction("Use &OpenGL", this);
143         useOpenGL->setCheckable(true);
144         
145
146         showRobotRef = new QAction("&Reference position", this);
147         showRobotRef->setCheckable(true);
148         showRobotEst = new QAction("&Best available estimated position", this);
149         showRobotEst->setCheckable(true);
150         showRobotEstOdo = new QAction("&Motor odometry", this);
151         showRobotEstOdo->setCheckable(true);
152         showRobotEstIndepOdo = new QAction("&Independent odometry", this);
153         showRobotEstIndepOdo->setCheckable(true);
154 }
155
156 void MainWindow::createMenus()
157 {
158         fileMenu = menuBar()->addMenu(tr("&File"));
159         fileMenu->addSeparator();
160         fileMenu->addAction(exitAct);
161         
162         QMenu *m;
163         m = menuBar()->addMenu(tr("&View"));
164         m->addAction(showMap);
165         m->addAction(showTrails);
166         m->addAction(resetTrails);
167         m->addAction(showShapeDetect);
168         QMenu *robot = m->addMenu(tr("&Robot"));
169         m->addAction(useOpenGL);
170
171         robot->addAction(showRobotRef);
172         robot->addAction(showRobotEst);
173         robot->addAction(showRobotEstOdo);
174         robot->addAction(showRobotEstIndepOdo);
175         
176         toolsMenu = menuBar()->addMenu(tr("&Tools"));
177         toolsMenu->addAction(robomonTuningAct);
178         toolsMenu->addAction(robomonAtlantisAct);
179         
180         menuBar()->addSeparator();
181         
182         helpMenu = menuBar()->addMenu(tr("&Help"));
183         helpMenu->addAction(helpAct);
184         helpMenu->addAction(aboutAct);
185 }
186
187 void MainWindow::createStatusBar()
188 {
189         coordinates = new QLabel();
190         statusBar()->showMessage(tr("Ready"));
191         statusBar()->addPermanentWidget(coordinates);
192 }
193
194 void MainWindow::createTabs()
195 {
196         tabWidget = new QTabWidget;
197         closeToolButton = new QToolButton();
198
199         closeToolButton->setIcon(QIcon(":/images/close.png"));
200         closeToolButton->setIconSize(QSize(14, 14));
201         closeToolButton->setShortcut(tr("Ctrl+W"));
202         closeToolButton->setToolTip(tr("Close tab (Ctrl+W)"));
203         tabWidget->setCornerWidget(closeToolButton);
204 }
205
206 int MainWindow::closeCurrentTab()
207 {
208         int index = tabWidget->currentIndex();
209         if (index < 0)
210                 return -1;
211         QWidget* tabPage = tabWidget->widget(index);
212         tabPage->close();
213         tabWidget->removeTab(index);
214         delete tabPage;
215
216         return 0;
217 }