PropertiesWidget.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::Gui
17 * @author Kai Welke (welke@kit.edu)
18 * @copyright 2012 Humanoids Group, IAIM, IFA
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 // Qt
26 #include <QWidget>
27 #include <QFormLayout>
28 #include <QLabel>
29 #include <QBoxLayout>
30 #include <QGroupBox>
31 #include <QVariant>
33 
34 
35 namespace armarx
36 {
37  class PropertiesWidget : public QWidget
38  {
39  Q_OBJECT
40  public:
41  PropertiesWidget(QWidget* parent = 0, Qt::WindowFlags f = 0) :
42  QWidget(parent, f)
43  {
44  createUi();
45  setPropertiesTitle("title not set");
46  }
47 
48  ~PropertiesWidget() override {}
49 
50  virtual void createUi()
51  {
52  // setup widgets
53  content = new QGroupBox(this);
54  content->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
55  contentLayout = new QGridLayout();
56  content->setLayout(contentLayout);
57 
58  // setup main layout
59  QBoxLayout* boxLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
60  boxLayout->addWidget(content);
61 
62  setLayout(boxLayout);
63  }
64  public slots:
65  void setPropertiesTitle(const QString& title)
66  {
67  QString fullTitle;
68  fullTitle = "Properties for " + title;
69  content->setTitle(fullTitle);
70  }
71 
72  void addProperty(const QString& label, QWidget* propertyWidget)
73  {
74  QString fullLabel = "<b>" + label + ": </b>";
75  auto rowCount = contentLayout->rowCount();
76  contentLayout->addWidget(new QLabel(fullLabel), rowCount, 0);
77  contentLayout->addWidget(propertyWidget, rowCount, 1);
78  contentLayout->addItem(new QSpacerItem(50, 10, QSizePolicy::Expanding), rowCount, 2);
79  }
80 
81  void addProperty(const QString& label, const QString& text)
82  {
83  auto rowCount = contentLayout->rowCount();
84  setProperty(rowCount, label, text);
85  }
86 
87  void setProperty(int row, const QString& label, const QString& text)
88  {
89  QString fullLabel = "<b>" + label + ": </b>";
90  QLabel* textLabel = new QLabel(this);
91  textLabel->setText(text);
92  textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
93 
94  QLabel* labelLabel = new QLabel(fullLabel);
95  labelLabel->setProperty(rawLabelPropertyString.c_str(), label);
96  contentLayout->addWidget(labelLabel, row, 0);
97  contentLayout->addWidget(textLabel, row, 1);
98  contentLayout->addItem(new QSpacerItem(50, 10, QSizePolicy::Expanding), row, 2);
99  }
100 
101  void setProperty(const QString& label, const QString& text)
102  {
103  int row;
104  for (row = 0; row < contentLayout->rowCount(); ++row)
105  {
106  if (!contentLayout->itemAtPosition(row, 0))
107  {
108  continue;
109  }
110  QLabel* labelWidget = qobject_cast<QLabel*>(contentLayout->itemAtPosition(row, 0)->widget());
111  if (labelWidget && labelWidget->property(rawLabelPropertyString.c_str()).toString() == label)
112  {
113  QLabel* textWidget = qobject_cast<QLabel*>(contentLayout->itemAtPosition(row, 1)->widget());
114  if (textWidget)
115  {
116  textWidget->setText(text);
117  }
118  return;
119  }
120  }
121  setProperty(row, label, text);
122  }
123 
124 
125  void addHeading(const QString& heading)
126  {
127  QString fullHeading = "<b>" + heading + ": </b>";
128  QLabel* textLabel = new QLabel(this);
129  textLabel->setText(fullHeading);
130  textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
131 
132  auto rowCount = contentLayout->rowCount();
133  contentLayout->addWidget(textLabel, rowCount, 0, 1, 3);
134  }
135 
136  void addWidget(QWidget* widget)
137  {
138  auto rowCount = contentLayout->rowCount();
139  contentLayout->addWidget(widget, rowCount, 0, 1, 3);
140  }
141  public:
142  const std::string rawLabelPropertyString = "RawLabel";
143  QGridLayout* getContentLayout() const
144  {
145  return contentLayout;
146  }
147 
148  private:
149  QGroupBox* content;
150  QGridLayout* contentLayout;
151  };
152 
153 
154 
155 }
156 
armarx::PropertiesWidget::addProperty
void addProperty(const QString &label, const QString &text)
Definition: PropertiesWidget.h:81
armarx::PropertiesWidget::addHeading
void addHeading(const QString &heading)
Definition: PropertiesWidget.h:125
armarx::PropertiesWidget::addProperty
void addProperty(const QString &label, QWidget *propertyWidget)
Definition: PropertiesWidget.h:72
armarx::PropertiesWidget::setProperty
void setProperty(const QString &label, const QString &text)
Definition: PropertiesWidget.h:101
armarx::PropertiesWidget::rawLabelPropertyString
const std::string rawLabelPropertyString
Definition: PropertiesWidget.h:142
armarx::PropertiesWidget::setProperty
void setProperty(int row, const QString &label, const QString &text)
Definition: PropertiesWidget.h:87
armarx::PropertiesWidget::setPropertiesTitle
void setPropertiesTitle(const QString &title)
Definition: PropertiesWidget.h:65
armarx::PropertiesWidget::createUi
virtual void createUi()
Definition: PropertiesWidget.h:50
armarx::PropertiesWidget::PropertiesWidget
PropertiesWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: PropertiesWidget.h:41
armarx::PropertiesWidget::addWidget
void addWidget(QWidget *widget)
Definition: PropertiesWidget.h:136
Logging.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PropertiesWidget::getContentLayout
QGridLayout * getContentLayout() const
Definition: PropertiesWidget.h:143
armarx::PropertiesWidget::~PropertiesWidget
~PropertiesWidget() override
Definition: PropertiesWidget.h:48
armarx::PropertiesWidget
Definition: PropertiesWidget.h:37