moveit2
The MoveIt Motion Planning Framework for ROS 2.
helper_widgets.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 
38 #include <QFileDialog>
39 #include <QFont>
40 #include <QLabel>
41 #include <QLineEdit>
42 #include <QPushButton>
43 #include <QVBoxLayout>
44 
45 namespace moveit_setup
46 {
47 // ******************************************************************************************
48 // ******************************************************************************************
49 // Class for Header of Screen
50 // ******************************************************************************************
51 // ******************************************************************************************
52 
53 HeaderWidget::HeaderWidget(const std::string& title, const std::string& instructions, QWidget* parent) : QWidget(parent)
54 {
55  // Basic widget container
56  QVBoxLayout* layout = new QVBoxLayout(this);
57 
58  // Page Title
59  QLabel* page_title = new QLabel(this);
60  page_title->setText(title.c_str());
61  QFont page_title_font(QFont().defaultFamily(), 18, QFont::Bold);
62  page_title->setFont(page_title_font);
63  page_title->setWordWrap(true);
64  page_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
65  layout->addWidget(page_title);
66 
67  // Page Instructions
68  QLabel* page_instructions = new QLabel(this);
69  page_instructions->setText(instructions.c_str());
70  page_instructions->setWordWrap(true);
71  page_instructions->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
72  layout->addWidget(page_instructions);
73 
74  // Margin on bottom
75  layout->setContentsMargins(0, 0, 0, 0); // last 15
76 
77  this->setLayout(layout);
78 
79  // For some reason, this style sheet setting affects the placement layout!?
80  this->setStyleSheet(QString("background-color:%1;").arg(QWidget::palette().color(QWidget::backgroundRole()).name()));
81 }
82 
83 // ******************************************************************************************
84 // ******************************************************************************************
85 // Class for selecting files
86 // ******************************************************************************************
87 // ******************************************************************************************
88 
89 // ******************************************************************************************
90 // Create the widget
91 // ******************************************************************************************
92 LoadPathWidget::LoadPathWidget(const QString& title, const QString& instructions, QWidget* parent, const bool dir_only,
93  const bool load_only)
94  : QFrame(parent), dir_only_(dir_only), load_only_(load_only)
95 {
96  // Set frame graphics
97  setFrameShape(QFrame::StyledPanel);
98  setFrameShadow(QFrame::Raised);
99  setLineWidth(1);
100  setMidLineWidth(0);
101 
102  // Basic widget container
103  QVBoxLayout* layout = new QVBoxLayout(this);
104 
105  // Horizontal layout splitter
106  QHBoxLayout* hlayout = new QHBoxLayout();
107 
108  // Widget Title
109  QLabel* widget_title = new QLabel(this);
110  widget_title->setText(title);
111  QFont widget_title_font(QFont().defaultFamily(), 12, QFont::Bold);
112  widget_title->setFont(widget_title_font);
113  layout->addWidget(widget_title);
114  layout->setAlignment(widget_title, Qt::AlignTop);
115 
116  // Widget Instructions
117  QLabel* widget_instructions = new QLabel(this);
118  widget_instructions->setText(instructions);
119  widget_instructions->setWordWrap(true);
120  widget_instructions->setTextFormat(Qt::RichText);
121  layout->addWidget(widget_instructions);
122  layout->setAlignment(widget_instructions, Qt::AlignTop);
123 
124  // Line Edit for path
125  path_box_ = new QLineEdit(this);
126  connect(path_box_, SIGNAL(textChanged(QString)), this, SIGNAL(pathChanged(QString)));
127  connect(path_box_, SIGNAL(editingFinished()), this, SIGNAL(pathEditingFinished()));
128  hlayout->addWidget(path_box_);
129 
130  // Button
131  QPushButton* browse_button = new QPushButton(this);
132  browse_button->setText("Browse");
133  connect(browse_button, SIGNAL(clicked()), this, SLOT(btnFileDialog()));
134  hlayout->addWidget(browse_button);
135 
136  // Add horizontal layer to vertical layer
137  layout->addLayout(hlayout);
138 
139  setLayout(layout);
140 }
141 
142 // ******************************************************************************************
143 // Load the file dialog
144 // ******************************************************************************************
145 void LoadPathWidget::btnFileDialog()
146 {
147  QString path;
148  if (dir_only_) // only allow user to select a directory
149  {
150  path = QFileDialog::getExistingDirectory(this, "Open Package Directory", path_box_->text(),
151  QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
152  }
153  else // only allow user to select file
154  {
155  QString start_path;
156 
157  start_path = path_box_->text();
158 
159  if (load_only_)
160  {
161  path = QFileDialog::getOpenFileName(this, "Open File", start_path, "");
162  }
163  else
164  {
165  path = QFileDialog::getSaveFileName(this, "Create/Load File", start_path, "");
166  }
167  }
168 
169  // check they did not press cancel
170  if (!path.isNull())
171  path_box_->setText(path);
172 }
173 
174 // ******************************************************************************************
175 // Get the QString path
176 // ******************************************************************************************
178 {
179  return path_box_->text();
180 }
181 
182 // ******************************************************************************************
183 // Get Std String path
184 // ******************************************************************************************
185 std::string LoadPathWidget::getPath() const
186 {
187  return getQPath().toStdString();
188 }
189 
190 // ******************************************************************************************
191 // Set the file/dir path
192 // ******************************************************************************************
193 void LoadPathWidget::setPath(const QString& path)
194 {
195  path_box_->setText(path);
196 }
197 
198 // ******************************************************************************************
199 // Set the file/dir path with std string
200 // ******************************************************************************************
201 void LoadPathWidget::setPath(const std::string& path)
202 {
203  path_box_->setText(QString(path.c_str()));
204 }
205 
206 LoadPathArgsWidget::LoadPathArgsWidget(const QString& title, const QString& instructions,
207  const QString& arg_instructions, QWidget* parent, const bool dir_only,
208  const bool load_only)
209  : LoadPathWidget(title, instructions, parent, dir_only, load_only)
210 {
211  // Line Edit for xacro args
212  args_instructions_ = new QLabel(arg_instructions, this);
213  args_ = new QLineEdit(this);
214 
215  layout()->addWidget(args_instructions_);
216  layout()->addWidget(args_);
217 }
218 
220 {
221  return args_->text();
222 }
223 
224 void LoadPathArgsWidget::setArgs(const QString& args)
225 {
226  args_->setText(args);
227 }
228 
230 {
231  args_->setEnabled(enabled);
232 }
233 } // namespace moveit_setup
HeaderWidget(const std::string &title, const std::string &instructions, QWidget *parent)
Constructor.
void setArgsEnabled(bool enabled=true)
void setArgs(const QString &args)
LoadPathArgsWidget(const QString &title, const QString &instructions, const QString &arg_instructions, QWidget *parent, const bool dir_only=false, const bool load_only=false)
Constructor.
LoadPathWidget(const QString &title, const QString &instructions, QWidget *parent, const bool dir_only=false, const bool load_only=false)
Constructor.
void pathChanged(const QString &path)
QString getQPath() const
Returns the file path in QString format.
void setPath(const QString &path)
Set the path with QString.
std::string getPath() const
Returns the file path in std::string format.
name
Definition: setup.py:7