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 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 // Class for Header of Screen
00048 // ******************************************************************************************
00049 // ******************************************************************************************
00050 
00051 HeaderWidget::HeaderWidget(const std::string& title, const std::string& instructions, QWidget* parent) : QWidget(parent)
00052 {
00053   // Basic widget container
00054   QVBoxLayout* layout = new QVBoxLayout(this);
00055   layout->setAlignment(Qt::AlignTop);
00056 
00057   // Page Title
00058   QLabel* page_title = new QLabel(this);
00059   page_title->setText(title.c_str());
00060   QFont page_title_font("Arial", 18, QFont::Bold);
00061   page_title->setFont(page_title_font);
00062   page_title->setWordWrap(true);
00063   layout->addWidget(page_title);
00064   layout->setAlignment(page_title, Qt::AlignTop);
00065 
00066   // Page Instructions
00067   QLabel* page_instructions = new QLabel(this);
00068   page_instructions->setText(instructions.c_str());
00069   page_instructions->setWordWrap(true);
00070   // page_instructions->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
00071   page_instructions->setMinimumWidth(1);
00072   layout->addWidget(page_instructions);
00073   layout->setAlignment(page_instructions, Qt::AlignTop);
00074 
00075   // Margin on bottom
00076   layout->setContentsMargins(0, 0, 0, 0);  // last 15
00077 
00078   this->setLayout(layout);
00079   // this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
00080 }
00081 
00082 // ******************************************************************************************
00083 // ******************************************************************************************
00084 // Class for selecting files
00085 // ******************************************************************************************
00086 // ******************************************************************************************
00087 
00088 // ******************************************************************************************
00089 // Create the widget
00090 // ******************************************************************************************
00091 LoadPathWidget::LoadPathWidget(const std::string& title, const std::string& instructions, const bool dir_only,
00092                                const bool load_only, QWidget* parent)
00093   : QFrame(parent), dir_only_(dir_only), load_only_(load_only)
00094 {
00095   // Set frame graphics
00096   setFrameShape(QFrame::StyledPanel);
00097   setFrameShadow(QFrame::Raised);
00098   setLineWidth(1);
00099   setMidLineWidth(0);
00100 
00101   // Basic widget container
00102   QVBoxLayout* layout = new QVBoxLayout(this);
00103 
00104   // Horizontal layout splitter
00105   QHBoxLayout* hlayout = new QHBoxLayout();
00106 
00107   // Widget Title
00108   QLabel* widget_title = new QLabel(this);
00109   widget_title->setText(title.c_str());
00110   QFont widget_title_font("Arial", 12, QFont::Bold);
00111   widget_title->setFont(widget_title_font);
00112   layout->addWidget(widget_title);
00113   layout->setAlignment(widget_title, Qt::AlignTop);
00114 
00115   // Widget Instructions
00116   QLabel* widget_instructions = new QLabel(this);
00117   widget_instructions->setText(instructions.c_str());
00118   widget_instructions->setWordWrap(true);
00119   widget_instructions->setTextFormat(Qt::RichText);
00120   layout->addWidget(widget_instructions);
00121   layout->setAlignment(widget_instructions, Qt::AlignTop);
00122 
00123   // Line Edit
00124   path_box_ = new QLineEdit(this);
00125   hlayout->addWidget(path_box_);
00126 
00127   // Button
00128   QPushButton* browse_button = new QPushButton(this);
00129   browse_button->setText("Browse");
00130   connect(browse_button, SIGNAL(clicked()), this, SLOT(btn_file_dialog()));
00131   hlayout->addWidget(browse_button);
00132 
00133   // Add horizontal layer to verticle layer
00134   layout->addLayout(hlayout);
00135 
00136   setLayout(layout);
00137 }
00138 
00139 // ******************************************************************************************
00140 // Load the file dialog
00141 // ******************************************************************************************
00142 void LoadPathWidget::btn_file_dialog()
00143 {
00144   QString path;
00145   if (dir_only_)  // only allow user to select a directory
00146   {
00147     path = QFileDialog::getExistingDirectory(this, "Open Package Directory", path_box_->text(),
00148                                              QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
00149   }
00150   else  // only allow user to select file
00151   {
00152     QString start_path;
00153 
00154     start_path = path_box_->text();
00155 
00156     if (load_only_)
00157     {
00158       path = QFileDialog::getOpenFileName(this, "Open File", start_path, "");
00159     }
00160     else
00161     {
00162       path = QFileDialog::getSaveFileName(this, "Create/Load File", start_path, "");
00163     }
00164   }
00165 
00166   // check they did not press cancel
00167   if (path != NULL)
00168     path_box_->setText(path);
00169 }
00170 
00171 // ******************************************************************************************
00172 // Get the QString path
00173 // ******************************************************************************************
00174 const QString LoadPathWidget::getQPath()
00175 {
00176   return path_box_->text();
00177 }
00178 
00179 // ******************************************************************************************
00180 // Get Std String path
00181 // ******************************************************************************************
00182 const std::string LoadPathWidget::getPath()
00183 {
00184   return getQPath().toStdString();
00185 }
00186 
00187 // ******************************************************************************************
00188 // Set the file/dir path
00189 // ******************************************************************************************
00190 void LoadPathWidget::setPath(const QString& path)
00191 {
00192   path_box_->setText(path);
00193 }
00194 
00195 // ******************************************************************************************
00196 // Set the file/dir path with std string
00197 // ******************************************************************************************
00198 void LoadPathWidget::setPath(const std::string& path)
00199 {
00200   path_box_->setText(QString(path.c_str()));
00201 }
00202 }


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Wed Jun 19 2019 19:25:13