header_widget.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Dave Coleman */
36 
37 #include <QPushButton>
38 #include <QFont>
39 #include <QFileDialog>
40 #include <QVBoxLayout>
41 #include "header_widget.h"
42 
43 namespace moveit_setup_assistant
44 {
45 // ******************************************************************************************
46 // ******************************************************************************************
47 // Class for Header of Screen
48 // ******************************************************************************************
49 // ******************************************************************************************
50 
51 HeaderWidget::HeaderWidget(const std::string& title, const std::string& instructions, QWidget* parent) : QWidget(parent)
52 {
53  // Basic widget container
54  QVBoxLayout* layout = new QVBoxLayout(this);
55  layout->setAlignment(Qt::AlignTop);
56 
57  // Page Title
58  QLabel* page_title = new QLabel(this);
59  page_title->setText(title.c_str());
60  QFont page_title_font(QFont().defaultFamily(), 18, QFont::Bold);
61  page_title->setFont(page_title_font);
62  page_title->setWordWrap(true);
63  layout->addWidget(page_title);
64  layout->setAlignment(page_title, Qt::AlignTop);
65 
66  // Page Instructions
67  QLabel* page_instructions = new QLabel(this);
68  page_instructions->setText(instructions.c_str());
69  page_instructions->setWordWrap(true);
70  // page_instructions->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
71  page_instructions->setMinimumWidth(1);
72  layout->addWidget(page_instructions);
73  layout->setAlignment(page_instructions, Qt::AlignTop);
74 
75  // Margin on bottom
76  layout->setContentsMargins(0, 0, 0, 0); // last 15
77 
78  this->setLayout(layout);
79  // this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
80 }
81 
82 // ******************************************************************************************
83 // ******************************************************************************************
84 // Class for selecting files
85 // ******************************************************************************************
86 // ******************************************************************************************
87 
88 // ******************************************************************************************
89 // Create the widget
90 // ******************************************************************************************
91 LoadPathWidget::LoadPathWidget(const QString& title, const QString& instructions, QWidget* parent, const bool dir_only,
92  const bool load_only)
93  : QFrame(parent), dir_only_(dir_only), load_only_(load_only)
94 {
95  // Set frame graphics
96  setFrameShape(QFrame::StyledPanel);
97  setFrameShadow(QFrame::Raised);
98  setLineWidth(1);
99  setMidLineWidth(0);
100 
101  // Basic widget container
102  QVBoxLayout* layout = new QVBoxLayout(this);
103 
104  // Horizontal layout splitter
105  QHBoxLayout* hlayout = new QHBoxLayout();
106 
107  // Widget Title
108  QLabel* widget_title = new QLabel(this);
109  widget_title->setText(title);
110  QFont widget_title_font(QFont().defaultFamily(), 12, QFont::Bold);
111  widget_title->setFont(widget_title_font);
112  layout->addWidget(widget_title);
113  layout->setAlignment(widget_title, Qt::AlignTop);
114 
115  // Widget Instructions
116  QLabel* widget_instructions = new QLabel(this);
117  widget_instructions->setText(instructions);
118  widget_instructions->setWordWrap(true);
119  widget_instructions->setTextFormat(Qt::RichText);
120  layout->addWidget(widget_instructions);
121  layout->setAlignment(widget_instructions, Qt::AlignTop);
122 
123  // Line Edit for path
124  path_box_ = new QLineEdit(this);
125  connect(path_box_, SIGNAL(textChanged(QString)), this, SIGNAL(pathChanged(QString)));
126  connect(path_box_, SIGNAL(editingFinished()), this, SIGNAL(pathEditingFinished()));
127  hlayout->addWidget(path_box_);
128 
129  // Button
130  QPushButton* browse_button = new QPushButton(this);
131  browse_button->setText("Browse");
132  connect(browse_button, SIGNAL(clicked()), this, SLOT(btn_file_dialog()));
133  hlayout->addWidget(browse_button);
134 
135  // Add horizontal layer to verticle layer
136  layout->addLayout(hlayout);
137 
138  setLayout(layout);
139 }
140 
141 // ******************************************************************************************
142 // Load the file dialog
143 // ******************************************************************************************
145 {
146  QString path;
147  if (dir_only_) // only allow user to select a directory
148  {
149  path = QFileDialog::getExistingDirectory(this, "Open Package Directory", path_box_->text(),
150  QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
151  }
152  else // only allow user to select file
153  {
154  QString start_path;
155 
156  start_path = path_box_->text();
157 
158  if (load_only_)
159  {
160  path = QFileDialog::getOpenFileName(this, "Open File", start_path, "");
161  }
162  else
163  {
164  path = QFileDialog::getSaveFileName(this, "Create/Load File", start_path, "");
165  }
166  }
167 
168  // check they did not press cancel
169  if (path != NULL)
170  path_box_->setText(path);
171 }
172 
173 // ******************************************************************************************
174 // Get the QString path
175 // ******************************************************************************************
177 {
178  return path_box_->text();
179 }
180 
181 // ******************************************************************************************
182 // Get Std String path
183 // ******************************************************************************************
184 std::string LoadPathWidget::getPath() const
185 {
186  return getQPath().toStdString();
187 }
188 
189 // ******************************************************************************************
190 // Set the file/dir path
191 // ******************************************************************************************
192 void LoadPathWidget::setPath(const QString& path)
193 {
194  path_box_->setText(path);
195 }
196 
197 // ******************************************************************************************
198 // Set the file/dir path with std string
199 // ******************************************************************************************
200 void LoadPathWidget::setPath(const std::string& path)
201 {
202  path_box_->setText(QString(path.c_str()));
203 }
204 
205 LoadPathArgsWidget::LoadPathArgsWidget(const QString& title, const QString& instructions,
206  const QString& arg_instructions, QWidget* parent, const bool dir_only,
207  const bool load_only)
208  : LoadPathWidget(title, instructions, parent, dir_only, load_only)
209 {
210  // Line Edit for xacro args
211  args_instructions_ = new QLabel(arg_instructions, this);
212  args_ = new QLineEdit(this);
213 
214  layout()->addWidget(args_instructions_);
215  layout()->addWidget(args_);
216 }
217 
219 {
220  return args_->text();
221 }
222 
223 void LoadPathArgsWidget::setArgs(const QString& args)
224 {
225  args_->setText(args);
226 }
227 
229 {
230  args_->setEnabled(enabled);
231 }
232 }
#define NULL
LoadPathArgsWidget(const QString &title, const QString &instructions, const QString &arg_instructions, QWidget *parent, const bool dir_only=false, const bool load_only=false)
Constructor.
HeaderWidget(const std::string &title, const std::string &instructions, QWidget *parent)
Contructor.
path
void setPath(const QString &path)
Set the path with QString.
void pathChanged(const QString &path)
LoadPathWidget(const QString &title, const QString &instructions, QWidget *parent, const bool dir_only=false, const bool load_only=false)
Constructor.
void btn_file_dialog()
Load the file dialog.
std::string getPath() const
Returns the file path in std::string format.
QString getQPath() const
Returns the file path in QString format.


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Wed Jul 10 2019 04:04:34