config_dialog.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2018, Open Source Robotics Foundation, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  *   * Redistributions of source code must retain the above copyright
00010  *     notice, this list of conditions and the following disclaimer.
00011  *   * Redistributions in binary form must reproduce the above
00012  *     copyright notice, this list of conditions and the following
00013  *     disclaimer in the documentation and/or other materials provided
00014  *     with the distribution.
00015  *   * Neither the name of the TU Darmstadt nor the names of its
00016  *     contributors may be used to endorse or promote products derived
00017  *     from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00027  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00029  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #include <QFileDialog>
00034 #include <QGridLayout>
00035 #include <QLabel>
00036 #include <QPushButton>
00037 
00038 #include <rqt_rviz/config_dialog.h>
00039 
00040 namespace rqt_rviz {
00041 
00042 ConfigDialog::ConfigDialog()
00043 {
00044   // Window configurations
00045   this->setWindowTitle(tr("Choose configuration"));
00046   this->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint |
00047       Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
00048 
00049   // File
00050   QLabel* file_label = new QLabel("File path");
00051   file_label->setToolTip("Full path to file");
00052 
00053   file_edit_ = new QLineEdit;
00054   file_edit_->setMinimumWidth(300);
00055 
00056   QPushButton* browse_button = new QPushButton(tr("Browse"));
00057   connect(browse_button, SIGNAL(clicked()), this, SLOT(OnBrowse()));
00058 
00059   // Hide menu
00060   QLabel* hide_label = new QLabel("Hide menu");
00061   hide_label->setToolTip("Check to hide RViz's top menu bar");
00062 
00063   hide_box_ = new QCheckBox();
00064 
00065   // Buttons
00066   QPushButton* cancel_button = new QPushButton(tr("&Cancel"));
00067   this->connect(cancel_button, SIGNAL(clicked()), this, SLOT(close()));
00068 
00069   QPushButton* apply_button = new QPushButton(tr("&Apply"));
00070   apply_button->setDefault(true);
00071   this->connect(apply_button, SIGNAL(clicked()), this, SLOT(accept()));
00072 
00073   QHBoxLayout* buttons_layout = new QHBoxLayout;
00074   buttons_layout->addWidget(cancel_button);
00075   buttons_layout->addWidget(apply_button);
00076 
00077   // Layout
00078   QGridLayout* main_layout = new QGridLayout();
00079 
00080   main_layout->addWidget(file_label, 0, 0);
00081   main_layout->addWidget(file_edit_, 0, 1);
00082   main_layout->addWidget(browse_button, 0, 2);
00083 
00084   main_layout->addWidget(hide_label, 1, 0);
00085   main_layout->addWidget(hide_box_, 1, 1);
00086   main_layout->setAlignment(hide_box_, Qt::AlignLeft);
00087 
00088   main_layout->addLayout(buttons_layout, 2, 0, 1, 3);
00089   main_layout->setColumnStretch(1, 2);
00090 
00091   this->setLayout(main_layout);
00092 }
00093 
00094 ConfigDialog::~ConfigDialog()
00095 {
00096 }
00097 
00098 void ConfigDialog::OnBrowse()
00099 {
00100   QString filename = QFileDialog::getOpenFileName(0,
00101     tr("Choose config file:"), "", tr("Rviz config file (*.rviz)"));
00102 
00103   file_edit_->setText(filename);
00104 }
00105 
00106 std::string ConfigDialog::GetFile() const
00107 {
00108   return file_edit_->text().toStdString();
00109 }
00110 
00111 void ConfigDialog::SetFile(const std::string& file)
00112 {
00113   file_edit_->setText(QString::fromStdString(file));
00114 }
00115 
00116 bool ConfigDialog::GetHide() const
00117 {
00118   return hide_box_->isChecked();
00119 }
00120 
00121 void ConfigDialog::SetHide(const bool hide)
00122 {
00123   hide_box_->setChecked(hide);
00124 }
00125 
00126 }
00127 


rqt_rviz
Author(s): Dorian Scholz
autogenerated on Sat Jun 8 2019 20:26:00