Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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 }