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 <QBoxLayout>
27#include <QFormLayout>
28#include <QGroupBox>
29#include <QLabel>
30#include <QVariant>
31#include <QWidget>
32
34
35namespace armarx
36{
37 class PropertiesWidget : public QWidget
38 {
39 Q_OBJECT
40 public:
41 PropertiesWidget(QWidget* parent = 0, Qt::WindowFlags f = 0) : QWidget(parent, f)
42 {
43 createUi();
44 setPropertiesTitle("title not set");
45 }
46
48 {
49 }
50
51 virtual void
53 {
54 // setup widgets
55 content = new QGroupBox(this);
56 content->setSizePolicy(
57 QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
58 contentLayout = new QGridLayout();
59 content->setLayout(contentLayout);
60
61 // setup main layout
62 QBoxLayout* boxLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
63 boxLayout->addWidget(content);
64
65 setLayout(boxLayout);
66 }
67
68 public slots:
69
70 void
71 setPropertiesTitle(const QString& title)
72 {
73 QString fullTitle;
74 fullTitle = "Properties for " + title;
75 content->setTitle(fullTitle);
76 }
77
78 void
79 addProperty(const QString& label, QWidget* propertyWidget)
80 {
81 QString fullLabel = "<b>" + label + ": </b>";
82 auto rowCount = contentLayout->rowCount();
83 contentLayout->addWidget(new QLabel(fullLabel), rowCount, 0);
84 contentLayout->addWidget(propertyWidget, rowCount, 1);
85 contentLayout->addItem(new QSpacerItem(50, 10, QSizePolicy::Expanding), rowCount, 2);
86 }
87
88 void
89 addProperty(const QString& label, const QString& text)
90 {
91 auto rowCount = contentLayout->rowCount();
92 setProperty(rowCount, label, text);
93 }
94
95 void
96 setProperty(int row, const QString& label, const QString& text)
97 {
98 QString fullLabel = "<b>" + label + ": </b>";
99 QLabel* textLabel = new QLabel(this);
100 textLabel->setText(text);
101 textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
102
103 QLabel* labelLabel = new QLabel(fullLabel);
104 labelLabel->setProperty(rawLabelPropertyString.c_str(), label);
105 contentLayout->addWidget(labelLabel, row, 0);
106 contentLayout->addWidget(textLabel, row, 1);
107 contentLayout->addItem(new QSpacerItem(50, 10, QSizePolicy::Expanding), row, 2);
108 }
109
110 void
111 setProperty(const QString& label, const QString& text)
112 {
113 int row;
114 for (row = 0; row < contentLayout->rowCount(); ++row)
115 {
116 if (!contentLayout->itemAtPosition(row, 0))
117 {
118 continue;
119 }
120 QLabel* labelWidget =
121 qobject_cast<QLabel*>(contentLayout->itemAtPosition(row, 0)->widget());
122 if (labelWidget &&
123 labelWidget->property(rawLabelPropertyString.c_str()).toString() == label)
124 {
125 QLabel* textWidget =
126 qobject_cast<QLabel*>(contentLayout->itemAtPosition(row, 1)->widget());
127 if (textWidget)
128 {
129 textWidget->setText(text);
130 }
131 return;
132 }
133 }
134 setProperty(row, label, text);
135 }
136
137 void
138 addHeading(const QString& heading)
139 {
140 QString fullHeading = "<b>" + heading + ": </b>";
141 QLabel* textLabel = new QLabel(this);
142 textLabel->setText(fullHeading);
143 textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
144
145 auto rowCount = contentLayout->rowCount();
146 contentLayout->addWidget(textLabel, rowCount, 0, 1, 3);
147 }
148
149 void
150 addWidget(QWidget* widget)
151 {
152 auto rowCount = contentLayout->rowCount();
153 contentLayout->addWidget(widget, rowCount, 0, 1, 3);
154 }
155
156 public:
157 const std::string rawLabelPropertyString = "RawLabel";
158
159 QGridLayout*
161 {
162 return contentLayout;
163 }
164
165 private:
166 QGroupBox* content;
167 QGridLayout* contentLayout;
168 };
169
170
171} // namespace armarx
void addWidget(QWidget *widget)
void setProperty(const QString &label, const QString &text)
void setProperty(int row, const QString &label, const QString &text)
const std::string rawLabelPropertyString
void addHeading(const QString &heading)
void addProperty(const QString &label, QWidget *propertyWidget)
void setPropertiesTitle(const QString &title)
QGridLayout * getContentLayout() const
void addProperty(const QString &label, const QString &text)
PropertiesWidget(QWidget *parent=0, Qt::WindowFlags f=0)
This file offers overloads of toIce() and fromIce() functions for STL container types.