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(useOpenGL, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(useOpenGL(bool)));
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)));
63 showRobotRef->setChecked(true);
64 showRobotEst->setChecked(true);
65 showRobotEstOdo->setChecked(false);
66 showRobotEstIndepOdo->setChecked(false);
69 void MainWindow::showCoordinates(QPointF pos)
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);
75 void MainWindow::about()
77 QMessageBox::about(this, tr("About Robomon"),
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 />"
84 "Martin ŽÍDEK, "
89 "<a href=\"http://rtime.felk.cvut.cz/dragons\">CTU Dragons</a>"
92 "<b>License:</b> GNU GPL v.2<br /></center>"
96 void MainWindow::help()
98 QMessageBox::about(this, tr("Help"),
99 tr("Here will be the help of the Robomon"));
102 void MainWindow::createActions()
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()));
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()));
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()));
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()));
127 aboutAct = new QAction(tr("&About"), this);
128 aboutAct->setStatusTip(tr("Show information about the application"));
129 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
131 connect(closeToolButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
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);
139 useOpenGL = new QAction("Use &OpenGL", this);
140 useOpenGL->setCheckable(true);
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);
153 void MainWindow::createMenus()
155 fileMenu = menuBar()->addMenu(tr("&File"));
156 fileMenu->addSeparator();
157 fileMenu->addAction(exitAct);
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);
167 robot->addAction(showRobotRef);
168 robot->addAction(showRobotEst);
169 robot->addAction(showRobotEstOdo);
170 robot->addAction(showRobotEstIndepOdo);
172 toolsMenu = menuBar()->addMenu(tr("&Tools"));
173 toolsMenu->addAction(robomonTuningAct);
174 toolsMenu->addAction(robomonAtlantisAct);
176 menuBar()->addSeparator();
178 helpMenu = menuBar()->addMenu(tr("&Help"));
179 helpMenu->addAction(helpAct);
180 helpMenu->addAction(aboutAct);
183 void MainWindow::createStatusBar()
185 coordinates = new QLabel();
186 statusBar()->showMessage(tr("Ready"));
187 statusBar()->addPermanentWidget(coordinates);
190 void MainWindow::createTabs()
192 tabWidget = new QTabWidget;
193 closeToolButton = new QToolButton();
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);
202 int MainWindow::closeCurrentTab()
204 int index = tabWidget->currentIndex();
207 QWidget* tabPage = tabWidget->widget(index);
209 tabWidget->removeTab(index);