MainWindow.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  TalkingHead - A talking head for robots
00003  *  Copyright (C) 2012 AG Aktives Sehen <agas@uni-koblenz.de>
00004  *                     Universitaet Koblenz-Landau
00005  *
00006  *  This program is free software: you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation, either version 3 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00019  *  MA 02110-1301  USA or see <http://www.gnu.org/licenses/>.
00020  *******************************************************************************/
00021 
00022 #include <string>
00023 #include <vector>
00024 
00025 #include "Config.h"
00026 #include "MainWindow.h"
00027 
00028 MainWindow::MainWindow( QWidget* parent ) : QWidget( parent, Qt::FramelessWindowHint ), talking_head_( 0 )
00029 {
00030     setContentsMargins ( 0, 0, 0, 0 );
00031 
00032     QPalette custom_palette = palette();
00033     custom_palette.setColor ( QPalette::Window, Qt::black );
00034     custom_palette.setColor ( QPalette::WindowText, Qt::white );
00035     setPalette( custom_palette );
00036     setAutoFillBackground ( true );
00037 
00038     // Center Layout (fixed size to fit small screen)
00039     QWidget* center_widget = new QWidget();
00040     center_widget->setContentsMargins ( 0, 0, 0, 0 );
00041 
00042     QVBoxLayout* center_layout = new QVBoxLayout( );
00043     center_layout->setSpacing( 0 );
00044     center_layout->setContentsMargins ( 0, 0, 0, 0 );
00045 
00046 //    //If we have more than one screen, open full-screen on 2nd screen
00047 //    ostringstream command;
00048 //    command << "Number of screens: " << qApp->desktop()->numScreens() << endl
00049 //            << "Screennr.: " << qApp->desktop()->screen(0) << endl
00050 //            << "Screennr.: " << qApp->desktop()->screen(1) << endl
00051 //            << "Primary screen: " << qApp->desktop()->primaryScreen() << endl
00052 //            << "Is virtual desktop: " << qApp->desktop()->isVirtualDesktop() << endl
00053 //            <<  "screen 0: " << qApp->desktop()->availableGeometry(0).left() << ","
00054 //            << qApp->desktop()->availableGeometry(0).top() << ","
00055 //            << qApp->desktop()->availableGeometry(0).right() << ","
00056 //            << qApp->desktop()->availableGeometry(0).bottom() << endl
00057 //            <<  "screen 1: " << qApp->desktop()->availableGeometry(1).left() << ","
00058 //            << qApp->desktop()->availableGeometry(1).top() << ","
00059 //            << qApp->desktop()->availableGeometry(1).right() << ","
00060 //            << qApp->desktop()->availableGeometry(1).bottom() << ",";
00061 
00062 //    ROS_INFO( command.str().c_str() );
00063 
00064     int width = 480;
00065     int height = 640;
00066 
00067     try
00068     {
00069         std::vector< std::vector<float> > material_colors;
00070         const char* cfgFilename =  "../config.cfg";
00071 
00072         Config cfg(cfgFilename);
00073         width = cfg.get("Window Width");
00074         height = cfg.get("Window Height");
00075         std::string mesh_filename = cfg.get("Mesh Filename");
00076         material_colors.push_back(cfg.get("Head Color"));
00077         material_colors.push_back(cfg.get("Iris Color"));
00078         material_colors.push_back(cfg.get("Outline Color"));
00079         talking_head_ = new TalkingHead( this, mesh_filename, material_colors );
00080 
00081         std::cout << "Mesh Filename : " << mesh_filename << std::endl;
00082     }
00083     catch( const std::exception& e )
00084     {
00085         std::cerr << e.what() << std::endl;
00086     }
00087 
00088     setMinimumSize( width, height );
00089 
00090     festival_generator_ = new FestivalGenerator();
00091 
00092     // TextOutputDisplay
00093     text_out_display_= new TextOutDisplay( 0, 27, false, this );
00094     text_out_display_->setMaximumSize( width, (height)/4 );
00095 
00096     // TextRecognitionDisplay
00097     text_rec_display_= new TextOutDisplay( 0, 20, true, this );
00098     custom_palette.setColor ( QPalette::WindowText, QColor( 200, 200, 200 ) );
00099     text_rec_display_->setPalette( custom_palette );
00100     text_rec_display_->setMaximumSize( width, (height)/4 );
00101 
00102     center_layout->addWidget( text_out_display_ );
00103     center_layout->addStretch();
00104     center_layout->addWidget( text_rec_display_ );
00105 
00106     center_layout->setStretchFactor( text_out_display_, 1 );
00107 
00108     center_widget->setFixedSize( width, height/4 );
00109     center_widget->setLayout( center_layout );
00110 
00111     // Main Layout
00112     QVBoxLayout* main_layout = new QVBoxLayout( );
00113     main_layout->setSpacing( 0 );
00114     main_layout->setContentsMargins ( 0, 0, 0, 0 );
00115 
00116     main_layout->addWidget( talking_head_ );
00117     talking_head_->setMinimumSize( width, height/4 );
00118     talking_head_->setMaximumSize( width, (height*3)/4 );
00119 
00120     main_layout->setStretchFactor( talking_head_, 1 );
00121 
00122     QHBoxLayout* h_layout = new QHBoxLayout( );
00123     h_layout->setSpacing( 0 );
00124     h_layout->setContentsMargins ( 0, 0, 0, 0 );
00125 
00126     h_layout->addStretch();
00127     h_layout->addWidget( center_widget );
00128     h_layout->addStretch();
00129 
00130     main_layout->addStretch();
00131     main_layout->addLayout( h_layout );
00132     main_layout->addStretch();
00133 
00134     setLayout( main_layout );
00135 
00136     ostringstream next_command;
00137     next_command << "Info: " << qApp->desktop()->screenNumber( talking_head_ ) << endl;
00138     ROS_INFO( next_command.str().c_str() );
00139 }
00140 
00141 MainWindow::~MainWindow() {}
00142 
00143 void MainWindow::setNodeHandle(ros::NodeHandle* node_handle)
00144 {
00145     talking_head_->subscribeWithNodeHandle( *node_handle );
00146 
00147     text_out_display_->subscribeWithNodeHandle( *node_handle );
00148 
00149     festival_generator_->subscribeWithNodeHandle( *node_handle );
00150 
00151     text_rec_display_->subscribeWithNodeHandle( *node_handle );
00152 }


robot_face
Author(s): AGAS, Julian Giesen, David Gossow
autogenerated on Mon Oct 6 2014 04:10:26