config_item.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #include <mapviz/config_item.h>
00031 #include <QMenu>
00032 #include <QAction>
00033 #include <QInputDialog>
00034 
00035 namespace mapviz
00036 {
00037   ConfigItem::ConfigItem(QWidget *parent, Qt::WFlags flags) :
00038     QWidget(parent, flags),
00039     item_(0),
00040     visible_(true)
00041   {
00042     ui_.setupUi(this);
00043 
00044     edit_name_action_   = new  QAction("Edit Name", this);
00045     remove_item_action_ = new  QAction("Remove", this);
00046     remove_item_action_->setIcon(QIcon(":/images/remove-icon-th.png"));
00047 
00048     connect(edit_name_action_, SIGNAL(triggered()), this, SLOT(EditName()));
00049     connect(remove_item_action_, SIGNAL(triggered()), this, SLOT(Remove()));
00050   }
00051 
00052   ConfigItem::~ConfigItem()
00053   {
00054   }
00055 
00056   void ConfigItem::ToggleDraw(bool toggled)
00057   {
00058     if (visible_ != toggled)
00059     {
00060       visible_ = toggled;      
00061       if (ui_.show->isChecked() != toggled)
00062       {
00063         ui_.show->setChecked(toggled);
00064       }
00065       
00066       Q_EMIT ToggledDraw(item_, toggled);
00067     }
00068   }
00069 
00070   void ConfigItem::contextMenuEvent(QContextMenuEvent* event)
00071   {
00072     QMenu menu(this);
00073     menu.addAction(edit_name_action_);
00074     menu.addAction(remove_item_action_);
00075     menu.exec(event->globalPos());
00076   }
00077 
00078   void ConfigItem::SetName(QString name)
00079   {
00080     name_ = name;
00081     ui_.namelabel->setText(type_ + " (" + name_ + ")");
00082   }
00083 
00084   void ConfigItem::SetType(QString type)
00085   {
00086     type_ = type;
00087     ui_.namelabel->setText(type_ + " (" + name_ + ")");
00088   }
00089 
00090   void ConfigItem::SetWidget(QWidget* widget)
00091   {
00092     ui_.label->hide();
00093     ui_.content_layout->addWidget(widget);
00094   }
00095 
00096   void ConfigItem::EditName()
00097   {
00098     bool ok;
00099     QString text = QInputDialog::getText(
00100       this, 
00101       tr("Set Display name"),
00102       tr(""), 
00103       QLineEdit::Normal,
00104       name_, &ok);
00105      
00106     if (ok && !text.isEmpty())
00107     {
00108       SetName(text);
00109     }
00110   }
00111 
00112   void ConfigItem::Remove()
00113   {
00114     Q_EMIT RemoveRequest(item_);
00115   }
00116 
00117   void ConfigItem::Hide()
00118   {
00119     if (!ui_.content->isHidden())
00120     {
00121       ui_.content->hide();
00122       ui_.signlabel->setText(" + ");
00123     }
00124     else
00125     {
00126       ui_.content->show();
00127       ui_.signlabel->setText(" - ");
00128     }
00129 
00130     Q_EMIT UpdateSizeHint();
00131   }
00132 }


mapviz
Author(s): Marc Alban
autogenerated on Thu Jun 6 2019 18:50:58