2 * MainWindow.cpp 07/10/31
4 * Top window layer. All tabs will be added to this main window.
6 * Copyright: (c) 2007 CTU Dragons
7 * CTU FEE - Department of Control Engineering
8 * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
14 #include "MainWindow.h"
15 #include "RobomonTuning.h"
16 #include "RobomonAtlantis.h"
18 MainWindow::MainWindow()
29 setCentralWidget(tabWidget);
31 addRobomonAtlantisTab();
34 void MainWindow::closeEvent(QCloseEvent *event)
36 while (closeCurrentTab() != -1) ;
40 void MainWindow::addRobomonTuningTab()
42 RobomonTuning *robomonTuning = new RobomonTuning();
43 tabWidget->addTab(robomonTuning, tr("Robomon Tuning"));
44 tabWidget->setCurrentWidget(robomonTuning);
47 void MainWindow::addRobomonAtlantisTab()
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)));
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)));
64 showRobotRef->setChecked(true);
65 showRobotEst->setChecked(true);
66 showRobotEstOdo->setChecked(false);
67 showRobotEstIndepOdo->setChecked(false);
70 void MainWindow::showCoordinates(QPointF pos)
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);
76 void MainWindow::about()
78 QMessageBox::about(this, tr("About Robomon"),
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 />"
85 "Martin ŽÍDEK, "
90 "<a href=\"http://rtime.felk.cvut.cz/dragons\">CTU Dragons</a>"
93 "<b>License:</b> GNU GPL v.2<br /></center>"
97 void MainWindow::help()
99 QMessageBox::about(this, tr("Help"),
100 tr("Here will be the help of the Robomon"));
103 void MainWindow::createActions()
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()));
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()));
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()));
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()));
128 aboutAct = new QAction(tr("&About"), this);
129 aboutAct->setStatusTip(tr("Show information about the application"));
130 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
132 connect(closeToolButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
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);
142 useOpenGL = new QAction("Use &OpenGL", this);
143 useOpenGL->setCheckable(true);
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);
156 void MainWindow::createMenus()
158 fileMenu = menuBar()->addMenu(tr("&File"));
159 fileMenu->addSeparator();
160 fileMenu->addAction(exitAct);
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);
171 robot->addAction(showRobotRef);
172 robot->addAction(showRobotEst);
173 robot->addAction(showRobotEstOdo);
174 robot->addAction(showRobotEstIndepOdo);
176 toolsMenu = menuBar()->addMenu(tr("&Tools"));
177 toolsMenu->addAction(robomonTuningAct);
178 toolsMenu->addAction(robomonAtlantisAct);
180 menuBar()->addSeparator();
182 helpMenu = menuBar()->addMenu(tr("&Help"));
183 helpMenu->addAction(helpAct);
184 helpMenu->addAction(aboutAct);
187 void MainWindow::createStatusBar()
189 coordinates = new QLabel();
190 statusBar()->showMessage(tr("Ready"));
191 statusBar()->addPermanentWidget(coordinates);
194 void MainWindow::createTabs()
196 tabWidget = new QTabWidget;
197 closeToolButton = new QToolButton();
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);
206 int MainWindow::closeCurrentTab()
208 int index = tabWidget->currentIndex();
211 QWidget* tabPage = tabWidget->widget(index);
213 tabWidget->removeTab(index);