main_window.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include <QtGui>
00013 #include <QMessageBox>
00014 #include <iostream>
00015 #include "../include/dabo_coop_gui/main_window.hpp"
00016 
00017 /*****************************************************************************
00018 ** Namespaces
00019 *****************************************************************************/
00020 
00021 namespace dabo_coop_gui {
00022 
00023 using namespace Qt;
00024 
00025 /*****************************************************************************
00026 ** Implementation [MainWindow]
00027 *****************************************************************************/
00028 
00029 MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
00030     : QMainWindow(parent)
00031     , qnode(argc,argv)
00032 {
00033   ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
00034   QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); // qApp is a global variable for the application
00035 
00036   ReadSettings();
00037   setWindowIcon(QIcon(":/images/logos/iri.png"));
00038   ui.tab_manager->setCurrentIndex(0); // ensure the first tab is showing - qt-designer should have this already hardwired, but often loses it (settings?).
00039   QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
00040 
00041   QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
00042   this->loadTexts();
00043   this->currentGoalIndex=0;
00044 
00045   /*********************
00046   ** Auto Start
00047   **********************/
00048   this->qnode.initialize();
00049 
00050   this->setLanguage(1); //English
00051   ui.label_goal->setStyleSheet("");
00052   ui.button_demo_exit->setEnabled(false);
00053   //this->getGoals();
00054 
00055   //TODO: switch blank/arrow cursor with param?
00056   qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
00057   //qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
00058   
00059   QTimer *timer = new QTimer(this);
00060   connect(timer, SIGNAL(timeout()), this, SLOT(timerDone()));
00061   timer->start(1000);
00062 }
00063 
00064 MainWindow::~MainWindow() {}
00065 
00066 /*****************************************************************************
00067 ** Implementation [Slots]
00068 *****************************************************************************/
00069 
00070 /*
00071  * These triggers whenever the button is clicked, regardless of whether it
00072  * is already checked or not.
00073  */
00074 void MainWindow::on_button_cat_clicked(bool check)
00075 {
00076   this->setLanguage(0);
00077 }
00078 
00079 void MainWindow::on_button_eng_clicked(bool check)
00080 {
00081   this->setLanguage(1);
00082 }
00083 
00084 void MainWindow::on_button_esp_clicked(bool check)
00085 {
00086   this->setLanguage(2);
00087 }
00088 
00089 void MainWindow::on_button_demo_exit_clicked(bool check)
00090 {
00091   std::cout << "exit clicked" << std::endl;
00092   this->qnode.exit();
00093   ui.button_demo_exit->setEnabled(false);
00094 }
00095 
00096 
00097 /*****************************************************************************
00098 ** Implemenation [Slots][manually connected]
00099 *****************************************************************************/
00100 
00107 void MainWindow::timerDone()
00108 {
00109   std::string goal;
00110   if(this->qnode.getGoal(goal))
00111   {
00112     if(goal=="monument")
00113     {
00114       this->currentGoalIndex=1;
00115       ui.label_goal->setStyleSheet("QLabel { image: url(:/images/goals/monument.png); image-position: left; }");
00116     }
00117     else if(goal=="bakery")
00118     {
00119       this->currentGoalIndex=2;
00120       ui.label_goal->setStyleSheet("QLabel { image: url(:/images/goals/bakery.png); image-position: left; }");
00121     }
00122     else if(goal=="kiosk")
00123     {
00124       this->currentGoalIndex=3;
00125       ui.label_goal->setStyleSheet("QLabel { image: url(:/images/goals/kiosk.ico); image-position: left; }");
00126     }
00127     else
00128     {
00129       this->currentGoalIndex=0;
00130       ui.label_goal->setStyleSheet("");
00131     }
00132     ui.label_goal->setText(this->goals[this->currentGoalIndex][this->lastLanguage].c_str());
00133     ui.button_demo_exit->setEnabled(true);
00134   }
00135 }
00136 
00137 void MainWindow::setLanguage(int index)
00138 {
00139   if(index!=this->lastLanguage)
00140   {
00141     for(unsigned int i=0; i<this->tabs.size(); i++)
00142     {
00143       ui.tab_manager->setTabText(i, this->tabs[i][index].c_str());
00144     }
00145     ui.label_info_title->setText(this->info[0][index].c_str());
00146     ui.label_info_1->setText(this->info[1][index].c_str());
00147     ui.label_info_2->setText(this->info[2][index].c_str());
00148     ui.label_info_3->setText(this->info[3][index].c_str());
00149     ui.label_info_4->setText(this->info[4][index].c_str());
00150     ui.label_info_5->setText(this->info[5][index].c_str());
00151     ui.label_info_title_2->setText(this->info[6][index].c_str());
00152     ui.label_info_6->setText(this->info[7][index].c_str());
00153     ui.label_info_7->setText(this->info[8][index].c_str());
00154     ui.label_info_8->setText(this->info[9][index].c_str());
00155     ui.label_info_9->setText(this->info[10][index].c_str());
00156     ui.label_info_10->setText(this->info[11][index].c_str());
00157 
00158     ui.label_demo->setText(this->goals[4][index].c_str());
00159     ui.label_goal->setText(this->goals[this->currentGoalIndex][index].c_str());
00160 
00161     if(index==0)
00162     {
00163       std::cout << "Setting language to Catalan" << std::endl;
00164       ui.button_cat->setIcon(QIcon(":/images/lang/cat.png"));
00165       ui.button_eng->setIcon(QIcon(":/images/lang/eng_bw.png"));
00166       ui.button_esp->setIcon(QIcon(":/images/lang/esp_bw.png"));
00167     }
00168     else if(index==1)
00169     {
00170       std::cout << "Setting language to English" << std::endl;
00171       ui.button_cat->setIcon(QIcon(":/images/lang/cat_bw.png"));
00172       ui.button_eng->setIcon(QIcon(":/images/lang/eng.png"));
00173       ui.button_esp->setIcon(QIcon(":/images/lang/esp_bw.png"));
00174     }
00175     else if(index==2)
00176     {
00177       std::cout << "Setting language to Spanish" << std::endl;
00178       ui.button_cat->setIcon(QIcon(":/images/lang/cat_bw.png"));
00179       ui.button_eng->setIcon(QIcon(":/images/lang/eng_bw.png"));
00180       ui.button_esp->setIcon(QIcon(":/images/lang/esp.png"));
00181     }
00182 
00183     this->lastLanguage=index;
00184   }
00185 }
00186 
00187 void MainWindow::getGoals()
00188 {
00189   std::vector<std::string>locations;
00190   if(this->qnode.getLocations(locations))
00191   {
00192     
00193     std::cout << "Locations ("<< locations.size() << "): ";
00194     for(unsigned int i=0; i<locations.size(); i++)
00195     {
00196        std::cout << locations[i] << " ";
00197     }
00198     std::cout << std::endl;
00199   }
00200 }
00201 
00202 void MainWindow::loadTexts()
00203 {
00204   std::vector<std::string> tab;
00205   tab.push_back("Demo");
00206   tab.push_back("Demo");
00207   tab.push_back("Demo");
00208   this->tabs.push_back(tab);
00209   tab.clear();
00210   tab.push_back("Info");
00211   tab.push_back("Info");
00212   tab.push_back("Info");
00213   this->tabs.push_back(tab);
00214   tab.clear();
00215   tab.push_back("Sobre");
00216   tab.push_back("About");
00217   tab.push_back("Acerca de");
00218   this->tabs.push_back(tab);
00219   tab.clear();
00220 
00221   std::vector<std::string> text;
00222   text.push_back("<b>Tibi i Dabo</b>");
00223   text.push_back("<b>Tibi and Dabo<b>");
00224   text.push_back("<b>Tibi y Dabo<b>");
00225   this->info.push_back(text);
00226   text.clear();
00227   text.push_back("- Robots socials i urbans.");
00228   text.push_back("- Social and urban robots.");
00229   text.push_back("- Robots sociales y urbanos");
00230   this->info.push_back(text);
00231   text.clear();
00232   text.push_back("- Plataforma <i><b>Segway rmp200</i></b> per navegació en entorns urbans.");
00233   text.push_back("- <i><b>Segway rmp200</i></b> platform for navigation in urban environments.");
00234   text.push_back("- Plataforma <i><b>Segway rmp200</i></b> para navegación en entornos urbanos.");
00235   this->info.push_back(text);
00236   text.clear();
00237   text.push_back("- Sensors de rang làser <i><b>Hokuyo</i></b> per localització i detecció d'obstacles.");
00238   text.push_back("- <i><b>Hokuyo</i></b> range laser sensors for localization and obstacle detection.");
00239   text.push_back("- Sensores de rango láser <i><b>Hokuyo</i></b> para localización y detección de obstáculos.");
00240   this->info.push_back(text);
00241   text.clear();
00242   text.push_back("- Càmara estèreo <i><b>Bumblebee2</i></b> per visió per computador.");
00243   text.push_back("- <i><b>Bumblebee2</i></b> Stereo camera for computer visión.");
00244   text.push_back("- Cámara estéreo <i><b>Bumblebee2</i></b> para visión por computador.");
00245   this->info.push_back(text);
00246   text.clear();
00247   text.push_back("- Cap, braços, pantalla tàctil i parla per la interacció humà robot");
00248   text.push_back("- Head, arms, touch screen and speech for human robot interaction.");
00249   text.push_back("- Cabeza, brazos, pantalla táctil y habla para la interacción humano robot.");
00250   this->info.push_back(text);
00251   text.clear();
00252   text.push_back("<b>Cotxe</b>");
00253   text.push_back("<b>Car</b>");
00254   text.push_back("<b>Coche</b>");
00255   this->info.push_back(text);
00256   text.clear();
00257   text.push_back("- Vehicle de transport autònom.");
00258   text.push_back("- Autonomous transport vehicle.");
00259   text.push_back("- Vehículo de transporte autónomo.");
00260   this->info.push_back(text);
00261   text.clear();
00262   text.push_back("- Plataforma Ackerman tipus cotxe.");
00263   text.push_back("- Ackerman car-like platform.");
00264   text.push_back("- Plataforma Ackerman tipo coche");
00265   this->info.push_back(text);
00266   text.clear();
00267   text.push_back("- Sensors de rang làser: parada de seguretat, detecció d'obstacles i localització.");
00268   text.push_back("- Range laser sensors: security stop, obstacle detection and localization.");
00269   text.push_back("- Sensores de rango láser para parada de seguridad, detección de obstáculos y localización.");
00270   this->info.push_back(text);
00271   text.clear();
00272   text.push_back("- Làser 3D Velodyne i Càmara 360º Ladybug: percepció de l'entorn.");
00273   text.push_back("- 3D laser Velodyne and 360 camera Ladybug: environment perception.");
00274   text.push_back("- Láser 3D Velodyne i cámara 360º Ladybug: percepción del entorno.");
00275   this->info.push_back(text);
00276   text.clear();
00277   text.push_back("- Pantalla tàctil: interacció amb passatgers.");
00278   text.push_back("- Touchscreen: passengers interaction.");
00279   text.push_back("- Pantalla táctil: interacción con pasajeros.");
00280   this->info.push_back(text);
00281   text.clear();
00282 
00283   std::vector<std::string> goal;
00284   goal.push_back("");
00285   goal.push_back("");
00286   goal.push_back("");
00287   this->goals.push_back(goal);
00288   goal.clear();
00289   goal.push_back("Monument");
00290   goal.push_back("Monument");
00291   goal.push_back("Monumento");
00292   this->goals.push_back(goal);
00293   goal.clear();
00294   goal.push_back("Forn de pa");
00295   goal.push_back("Bakery");
00296   goal.push_back("Panadería");
00297   this->goals.push_back(goal);
00298   goal.clear();
00299   goal.push_back("Quiosc");
00300   goal.push_back("Kiosk");
00301   goal.push_back("Quiosco");
00302   this->goals.push_back(goal);
00303   goal.clear();
00304   goal.push_back("Benvingut al:");
00305   goal.push_back("Welcome to the:");
00306   goal.push_back("Bienvenido a:");
00307   this->goals.push_back(goal);
00308   goal.clear();
00309 }
00310 
00311 /*****************************************************************************
00312 ** Implementation [Menu]
00313 *****************************************************************************/
00314 
00315 void MainWindow::on_actionAbout_triggered() {
00316     QMessageBox::about(this, tr("About ..."),tr("<h2>Tibi Dabo Gui</h2><p>Copyright IRI</p><p>Graphic User Interface for Tibi Dabo robots.</p>"));
00317 }
00318 
00319 /*****************************************************************************
00320 ** Implementation [Configuration]
00321 *****************************************************************************/
00322 
00323 void MainWindow::ReadSettings() {
00324     QSettings settings("Qt-Ros Package", "tibi_dabo_gui");
00325     restoreGeometry(settings.value("geometry").toByteArray());
00326     restoreState(settings.value("windowState").toByteArray());
00327 }
00328 
00329 void MainWindow::WriteSettings() {
00330     QSettings settings("Qt-Ros Package", "tibi_dabo_gui");
00331     settings.setValue("geometry", saveGeometry());
00332     settings.setValue("windowState", saveState());
00333 }
00334 
00335 void MainWindow::closeEvent(QCloseEvent *event)
00336 {
00337     WriteSettings();
00338     QMainWindow::closeEvent(event);
00339 }
00340 
00341 }  // namespace dabo_coop_gui
00342 


dabo_coop_gui
Author(s): fherrero
autogenerated on Fri Dec 6 2013 23:14:17