LayoutWidgets.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QGroupBox>
4 #include <QHBoxLayout>
5 #include <QVBoxLayout>
6 #include <QGridLayout>
7 
8 #include "Basic.h"
9 
10 namespace armarx::RemoteGui
11 {
12  struct GroupBoxHandler : TypedWidget<GroupBox, QGroupBox>
13  {
14  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
15  const QObject* stateChangeReceiver, const char* stateChangeSlot)
16  {
18  QGroupBox* widget = new QGroupBox;
19  widget->setTitle(toQString(desc.label));
20  widget->setCheckable(true);
21  widget->setChecked(true);
22 
23  //use an arrow as indicator for the checkbox
24  {
25  widget->setStyleSheet(R"(
26  QGroupBox::indicator:checked {
27  image: url(:/icons/TriangleBlackDown.svg);
28  }
29  QGroupBox::indicator:unchecked {
30  image: url(:/icons/TriangleBlackRight.svg);
31  }
32  )");
33  }
34 
35  QHBoxLayout* layout = new QHBoxLayout;
36  widget->setLayout(layout);
37  layout->setContentsMargins(0, 0, 0, 0);
38 
39  QWidget* holder = new QWidget;
40  layout->addWidget(holder);
41 
42  QObject::connect(widget, SIGNAL(clicked(bool)), holder, SLOT(setVisible(bool)));
43 
44  if (desc.children.size() > 0)
45  {
46 
47  QVBoxLayout* layout = new QVBoxLayout;
48  holder->setLayout(layout);
49  layout->setContentsMargins(9, 0, 0, 0);
50  for (const auto& child : desc.children)
51  {
52  layout->addWidget(createChild(child));
53  }
54  }
55 
56  widget->setChecked(!desc.collapsed);
57  holder->setVisible(!desc.collapsed);
58 
59  return widget;
60  }
61  };
62 
63  struct VBoxLayoutHandler : TypedWidget<VBoxLayout, QWidget>
64  {
65  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
66  const QObject* stateChangeReceiver, const char* stateChangeSlot)
67  {
69  QWidgetT* widget = new QWidget();
70 
71  QVBoxLayout* layout = new QVBoxLayout(widget);
72  widget->setLayout(layout);
73  layout->setContentsMargins(0, 0, 0, 0);
74  for (const RemoteGui::WidgetPtr& child : desc.children)
75  {
76  QWidget* childWidget = createChild(child);
77  layout->addWidget(childWidget);
78  }
79 
80  return widget;
81  }
82  };
83 
84  struct HBoxLayoutHandler : TypedWidget<HBoxLayout, QWidget>
85  {
86  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
87  const QObject* stateChangeReceiver, const char* stateChangeSlot)
88  {
90  QWidgetT* widget = new QWidget();
91 
92  QHBoxLayout* layout = new QHBoxLayout(widget);
93  widget->setLayout(layout);
94  layout->setContentsMargins(0, 0, 0, 0);
95  for (const RemoteGui::WidgetPtr& child : desc.children)
96  {
97  QWidget* childWidget = createChild(child);
98  layout->addWidget(childWidget);
99  }
100 
101  return widget;
102  }
103  };
104  struct SimpleGridLayoutSpanningChildHandler : TypedWidget<SimpleGridLayoutSpanningChild, QWidget>
105  {
106  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
107  const QObject* stateChangeReceiver, const char* stateChangeSlot)
108  {
109  ARMARX_TRACE;
110  ARMARX_CHECK_GREATER(desc.columns, 0);
111  switch (desc.children.size())
112  {
113  case 0:
114  return new QWidget;
115  case 1:
116  return createChild(desc.children.front());
117  default:; //below
118  }
119 
120  QWidgetT* widget = new QWidget();
121 
122  QHBoxLayout* layout = new QHBoxLayout(widget);
123  widget->setLayout(layout);
124  layout->setContentsMargins(0, 0, 0, 0);
125  for (const RemoteGui::WidgetPtr& child : desc.children)
126  {
127  QWidget* childWidget = createChild(child);
128  layout->addWidget(childWidget);
129  }
130 
131  return widget;
132 
133  }
134  };
135  struct SimpleGridLayoutHandler : TypedWidget<SimpleGridLayout, QWidget>
136  {
137  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
138  const QObject* stateChangeReceiver, const char* stateChangeSlot)
139  {
140  ARMARX_TRACE;
141  QWidgetT* widget = new QWidget();
142 
143  QGridLayout* layout = new QGridLayout(widget);
144  widget->setLayout(layout);
145  layout->setContentsMargins(0, 0, 0, 0);
146  ARMARX_CHECK_GREATER(desc.columns, 0);
147  int col = 0;
148  int row = 0;
149  for (const RemoteGui::WidgetPtr& child : desc.children)
150  {
151  QWidget* childWidget = createChild(child);
152  int colspan = 1;
153  if (auto spc = SimpleGridLayoutSpanningChildPtr::dynamicCast(child); spc)
154  {
155  colspan = std::max(1, spc->columns);
156  }
157  layout->addWidget(childWidget, row, col, 1, colspan);
158 
159  if (col + colspan >= desc.columns)
160  {
161  //next row
162  ++row;
163  col = 0;
164  }
165  else
166  {
167  col += colspan;
168  }
169  }
170 
171  return widget;
172  }
173  };
174 
175  struct GridLayoutHandler : TypedWidget<GridLayout, QWidget>
176  {
177  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
178  const QObject* stateChangeReceiver, const char* stateChangeSlot)
179  {
180  ARMARX_TRACE;
181  QWidgetT* widget = new QWidget();
182 
183  QGridLayout* layout = new QGridLayout(widget);
184  widget->setLayout(layout);
185  layout->setContentsMargins(0, 0, 0, 0);
186  int maxrow = 0;
187  for (std::size_t i = 0; i < desc.children.size(); ++i)
188  {
189  const RemoteGui::WidgetPtr& child = desc.children.at(i);
190 
191  QWidget* childWidget = createChild(child);
192 
193  GridLayoutData l;
194  if (i < desc.childrenLayoutInfo.size())
195  {
196  l = desc.childrenLayoutInfo.at(i);
197  }
198  else
199  {
200  l.col = 0;
201  l.row = maxrow;
202  l.spanCol = 1;
203  l.spanRow = 1;
204  }
205  maxrow = std::max(maxrow, l.row + l.spanRow);
206  layout->addWidget(childWidget, l.row, l.col, l.spanRow, l.spanCol);
207  }
208 
209  return widget;
210  }
211  };
212 }
armarx::RemoteGui::VBoxLayoutHandler
Definition: LayoutWidgets.h:63
armarx::RemoteGui::HBoxLayoutHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: LayoutWidgets.h:86
armarx::RemoteGui
Definition: LightweightRemoteGuiComponentPlugin.h:30
armarx::RemoteGui::Client::VBoxLayout
Definition: Widgets.h:167
armarx::RemoteGui::VBoxLayoutHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: LayoutWidgets.h:65
armarx::RemoteGui::TypedWidget
Definition: TypedWidget.h:115
ARMARX_CHECK_GREATER
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
Definition: ExpressionException.h:116
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::RemoteGui::SimpleGridLayoutSpanningChildHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: LayoutWidgets.h:106
Basic.h
armarx::RemoteGui::GroupBoxHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: LayoutWidgets.h:14
armarx::RemoteGui::SimpleGridLayoutHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: LayoutWidgets.h:137
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
armarx::RemoteGui::GroupBoxHandler
Definition: LayoutWidgets.h:12
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::RemoteGui::GridLayoutHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: LayoutWidgets.h:177
armarx::RemoteGui::TypedWidget< GroupBox, QGroupBox >::QWidgetT
QGroupBox QWidgetT
Definition: TypedWidget.h:118
armarx::RemoteGui::GridLayoutHandler
Definition: LayoutWidgets.h:175
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
armarx::RemoteGui::Client::HBoxLayout
Definition: Widgets.h:160
armarx::RemoteGui::toQString
QString toQString(std::string const &string)
Definition: WidgetHandler.cpp:12
armarx::RemoteGui::CreateWidgetCallback
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
Definition: WidgetHandler.h:20
armarx::RemoteGui::SimpleGridLayoutHandler
Definition: LayoutWidgets.h:135
armarx::RemoteGui::HBoxLayoutHandler
Definition: LayoutWidgets.h:84
armarx::RemoteGui::SimpleGridLayoutSpanningChildHandler
Definition: LayoutWidgets.h:104
armarx::RemoteGui::TypedWidget< SimpleGridLayoutSpanningChild, QWidget >::RemoteWidgetT
SimpleGridLayoutSpanningChild RemoteWidgetT
Definition: TypedWidget.h:117