header_widget.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2012, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 /* Author: Dave Coleman */
00036 
00037 #include <QPushButton>
00038 #include <QFont>
00039 #include <QFileDialog>
00040 #include <QVBoxLayout>
00041 #include "header_widget.h"
00042 
00043 namespace moveit_setup_assistant
00044 {
00045 
00046 // ******************************************************************************************
00047 // ******************************************************************************************
00048 // Class for Header of Screen
00049 // ******************************************************************************************
00050 // ******************************************************************************************
00051 
00052 HeaderWidget::HeaderWidget( const std::string &title, const std::string &instructions, QWidget *parent )
00053   : QWidget(parent)
00054 {
00055   // Basic widget container
00056   QVBoxLayout *layout = new QVBoxLayout(this);
00057   layout->setAlignment( Qt::AlignTop);
00058 
00059   // Page Title
00060   QLabel *page_title = new QLabel( this );
00061   page_title->setText( title.c_str() );
00062   QFont page_title_font( "Arial", 18, QFont::Bold );
00063   page_title->setFont(page_title_font);
00064   page_title->setWordWrap(true);
00065   layout->addWidget( page_title);
00066   layout->setAlignment( page_title, Qt::AlignTop);
00067 
00068   // Page Instructions
00069   QLabel *page_instructions = new QLabel( this );
00070   page_instructions->setText( instructions.c_str() );
00071   page_instructions->setWordWrap(true);
00072   //page_instructions->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
00073   page_instructions->setMinimumWidth(1);
00074   layout->addWidget( page_instructions );
00075   layout->setAlignment( page_instructions, Qt::AlignTop);
00076 
00077   // Margin on bottom
00078   layout->setContentsMargins( 0, 0, 0, 0); // last 15
00079 
00080   this->setLayout(layout);
00081   //this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
00082 }
00083 
00084 
00085 // ******************************************************************************************
00086 // ******************************************************************************************
00087 // Class for selecting files
00088 // ******************************************************************************************
00089 // ******************************************************************************************
00090 
00091 // ******************************************************************************************
00092 // Create the widget
00093 // ******************************************************************************************
00094 LoadPathWidget::LoadPathWidget( const std::string &title, const std::string &instructions,
00095                                 const bool dir_only, const bool load_only, QWidget* parent )
00096   : QFrame(parent), dir_only_(dir_only), load_only_(load_only)
00097 {
00098   // Set frame graphics
00099   setFrameShape(QFrame::StyledPanel);
00100   setFrameShadow(QFrame::Raised);
00101   setLineWidth(1);
00102   setMidLineWidth(0);
00103 
00104   // Basic widget container
00105   QVBoxLayout *layout = new QVBoxLayout(this);
00106 
00107   // Horizontal layout splitter
00108   QHBoxLayout *hlayout = new QHBoxLayout();
00109 
00110   // Widget Title
00111   QLabel * widget_title = new QLabel(this);
00112   widget_title->setText( title.c_str() );
00113   QFont widget_title_font( "Arial", 12, QFont::Bold );
00114   widget_title->setFont(widget_title_font);
00115   layout->addWidget( widget_title);
00116   layout->setAlignment( widget_title, Qt::AlignTop);
00117 
00118   // Widget Instructions
00119   QLabel * widget_instructions = new QLabel(this);
00120   widget_instructions->setText( instructions.c_str() );
00121   widget_instructions->setWordWrap(true);
00122   widget_instructions->setTextFormat( Qt::RichText );
00123   layout->addWidget( widget_instructions);
00124   layout->setAlignment( widget_instructions, Qt::AlignTop);
00125 
00126   // Line Edit
00127   path_box_ = new QLineEdit(this);
00128   hlayout->addWidget(path_box_);
00129 
00130   // Button
00131   QPushButton *browse_button = new QPushButton(this);
00132   browse_button->setText("Browse");
00133   connect( browse_button, SIGNAL( clicked() ), this, SLOT( btn_file_dialog() ) );
00134   hlayout->addWidget(browse_button);
00135 
00136   // Add horizontal layer to verticle layer
00137   layout->addLayout(hlayout);
00138 
00139   setLayout(layout);
00140 }
00141 
00142 // ******************************************************************************************
00143 // Load the file dialog
00144 // ******************************************************************************************
00145 void LoadPathWidget::btn_file_dialog()
00146 {
00147   QString path;
00148   if( dir_only_ ) // only allow user to select a directory
00149   {
00150     path = QFileDialog::getExistingDirectory(this, "Open Package Directory", path_box_->text(),
00151                                              QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
00152   }
00153   else // only allow user to select file
00154   {
00155     QString start_path;
00156 
00157       start_path = path_box_->text();
00158 
00159     if( load_only_ )
00160     {
00161       path = QFileDialog::getOpenFileName(this, "Open File", start_path, "");
00162     }
00163     else
00164     {
00165       path = QFileDialog::getSaveFileName(this, "Create/Load File", start_path, "" );
00166     }
00167   }
00168 
00169   // check they did not press cancel
00170   if (path != NULL)
00171     path_box_->setText( path );
00172 }
00173 
00174 // ******************************************************************************************
00175 // Get the QString path
00176 // ******************************************************************************************
00177 const QString LoadPathWidget::getQPath()
00178 {
00179   return path_box_->text();
00180 }
00181 
00182 // ******************************************************************************************
00183 // Get Std String path
00184 // ******************************************************************************************
00185 const std::string LoadPathWidget::getPath()
00186 {
00187   return getQPath().toStdString();
00188 }
00189 
00190 // ******************************************************************************************
00191 // Set the file/dir path
00192 // ******************************************************************************************
00193 void LoadPathWidget::setPath( const QString &path )
00194 {
00195   path_box_->setText( path );
00196 }
00197 
00198 // ******************************************************************************************
00199 // Set the file/dir path with std string
00200 // ******************************************************************************************
00201 void LoadPathWidget::setPath( const std::string &path )
00202 {
00203   path_box_->setText( QString( path.c_str() ) );
00204 }
00205 
00206 
00207 }


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Mon Oct 6 2014 02:32:27