]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robomon/MainWindow.cpp
robomon controls map and trail visibility from the new View menu
[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         createToolBars();
28         createStatusBar();
29
30         setCentralWidget(tabWidget);
31         
32         addRobomonAtlantisTab();
33 }
34
35 void MainWindow::closeEvent(QCloseEvent *event)
36 {
37         while (closeCurrentTab() != -1) ;
38         event->accept();
39 }
40
41 void MainWindow::addRobomonTuningTab()
42 {
43         RobomonTuning *robomonTuning = new RobomonTuning();
44         tabWidget->addTab(robomonTuning, tr("Robomon Tuning"));
45         tabWidget->setCurrentWidget(robomonTuning);
46 }
47
48 void MainWindow::addRobomonAtlantisTab()
49 {
50         RobomonAtlantis *robomonAtlantis = new RobomonAtlantis();
51         tabWidget->addTab(robomonAtlantis, tr("Robomon - Temples of Atlantis"));
52         tabWidget->setCurrentWidget(robomonAtlantis);
53         connect(showMap, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(showMap(bool)));
54         connect(showTrails, SIGNAL(toggled( bool )), robomonAtlantis, SLOT(showTrails(bool)));
55         connect(resetTrails, SIGNAL(triggered()), robomonAtlantis, SLOT(resetTrails()));
56 }
57
58 void MainWindow::about()
59 {
60         QMessageBox::about(this, tr("About Robomon"),
61                 tr(
62                 "<center>"
63                 "<h1>Robomon 2.0</h1><br /><br />"
64                 "<b>Robomon</b> is an application for graphic "
65                 "visualization and control of the robot.<br /><br />"
66                 "<b>Authors:</b> "
67                 "Martin &#381;&#205;DEK, "
68                 "Michal SOJKA, "
69                 "TRAN Duy Khanh"
70                 "<br />"
71                 "<br />"
72                 "<a href=\"http://rtime.felk.cvut.cz/dragons\">CTU Dragons</a>"
73                 "<br />"
74                 "<br />"
75                 "<b>License:</b> GNU GPL v.2<br /></center>"
76                 ));
77 }
78
79 void MainWindow::help()
80 {
81         QMessageBox::about(this, tr("Help"),
82                 tr("Here will be the help of the Robomon"));
83 }
84
85 void MainWindow::createActions()
86 {
87         exitAct = new QAction(tr("E&xit"), this);
88         exitAct->setShortcut(tr("Ctrl+Q"));
89         exitAct->setStatusTip(tr("Exit the application"));
90         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
91
92         robomonTuningAct = new QAction(QIcon(":/images/tuning.png"), 
93                                                 tr("Robot &Tuning"), this);
94         robomonTuningAct->setShortcut(tr("Ctrl+T"));
95         robomonTuningAct->setStatusTip(tr("Robomon of the Robot Explorer - tuning panel"));
96         connect(robomonTuningAct, SIGNAL(triggered()), 
97                         this, SLOT(addRobomonTuningTab()));
98
99         robomonAtlantisAct = new QAction(QIcon(":/images/robomon_atlantis.png"), 
100                                                 tr("Robot &Atlantis"), this);
101         robomonAtlantisAct->setShortcut(tr("Ctrl+A"));
102         robomonAtlantisAct->setStatusTip(tr("Robomon of the Robot Atlantis"));
103         connect(robomonAtlantisAct, SIGNAL(triggered()), 
104                         this, SLOT(addRobomonAtlantisTab()));
105
106         helpAct = new QAction(tr("&Help"), this);
107         helpAct->setStatusTip(tr("Show the Qt library's About box"));
108         connect(helpAct, SIGNAL(triggered()), this, SLOT(help()));
109
110         aboutAct = new QAction(tr("&About"), this);
111         aboutAct->setStatusTip(tr("Show information about the application"));
112         connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
113
114         connect(closeToolButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
115         
116         showTrails = new QAction("Show &trails", this);
117         showTrails->setCheckable(true);
118         showMap = new QAction("Show &map", this);
119         showMap->setCheckable(true);
120         resetTrails = new QAction("&Reset trails", this);
121 }
122
123 void MainWindow::createMenus()
124 {
125         fileMenu = menuBar()->addMenu(tr("&File"));
126         fileMenu->addSeparator();
127         fileMenu->addAction(exitAct);
128         
129         QMenu *m;
130         m = menuBar()->addMenu(tr("&View"));
131         m->addAction(showMap);
132         m->addAction(showTrails);
133         m->addAction(resetTrails);
134         
135         toolsMenu = menuBar()->addMenu(tr("&Tools"));
136         toolsMenu->addAction(robomonTuningAct);
137         toolsMenu->addAction(robomonAtlantisAct);
138         
139         menuBar()->addSeparator();
140         
141         helpMenu = menuBar()->addMenu(tr("&Help"));
142         helpMenu->addAction(helpAct);
143         helpMenu->addAction(aboutAct);
144 }
145
146 void MainWindow::createToolBars()
147 {
148         fileToolBar = addToolBar(tr("File"));
149         
150         toolsToolBar = addToolBar(tr("Tools"));
151         toolsToolBar->addAction(robomonTuningAct);
152         toolsToolBar->addAction(robomonAtlantisAct);
153 }
154
155 void MainWindow::createStatusBar()
156 {
157         statusBar()->showMessage(tr("Ready"));
158 }
159
160 void MainWindow::createTabs()
161 {
162         tabWidget = new QTabWidget;
163         closeToolButton = new QToolButton();
164
165         closeToolButton->setIcon(QIcon(":/images/close.png"));
166         closeToolButton->setIconSize(QSize(14, 14));
167         closeToolButton->setShortcut(tr("Ctrl+W"));
168         closeToolButton->setToolTip(tr("Close tab (Ctrl+W)"));
169         tabWidget->setCornerWidget(closeToolButton);
170 }
171
172 int MainWindow::closeCurrentTab()
173 {
174         int index = tabWidget->currentIndex();
175         if (index < 0)
176                 return -1;
177         QWidget* tabPage = tabWidget->widget(index);
178         tabPage->close();
179         tabWidget->removeTab(index);
180         delete tabPage;
181
182         return 0;
183 }