RemoteGuiExample2.cpp
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 ArmarXGui::ArmarXObjects::RemoteGuiExample2
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "RemoteGuiExample2.h"
24 
26 
27 
28 namespace armarx
29 {
30 
32  {
33  }
34 
35 
37  {
38  return GetDefaultName();
39  }
40 
41 
43  {
44  return "RemoteGuiExample2";
45  }
46 
47 
49  {
51 
52  return defs;
53  }
54 
55 
57  {
58  }
59 
60 
62  {
63  createTab_Widgets();
64  createTab_Events();
65 
67  }
68 
69 
71  {
72  ARMARX_INFO << "Removing tabs";
73  widgetsTab.remove();
74  eventsTab.remove();
75  }
76 
77 
79  {
81  }
82 
83 
84  void RemoteGuiExample2::RemoteGui_update()
85  {
86  updateTab_Widgets();
87  updateTab_Events();
88  }
89 
90 
91  void RemoteGuiExample2::createTab_Widgets()
92  {
93  // Just add a lot of widgets...
94 
95  VBoxLayout vLayout;
96  {
97  widgetsTab.lineEdit.setValue("Hello");
98 
99  Label label("Line: ");
100  HBoxLayout line{label, widgetsTab.lineEdit};
101  vLayout.addChild(line);
102  }
103 
104  {
105  widgetsTab.combo.addOptions({"First", "Second", "Third", "Fourth"});
106  widgetsTab.combo.setValue("Second");
107 
108  HBoxLayout line{Label("Combo: "), widgetsTab.combo};
109  vLayout.addChild(line);
110  }
111 
112  {
113  widgetsTab.checkBox.setValue(true);
114 
115  HBoxLayout line{Label("Check: "), widgetsTab.checkBox};
116  vLayout.addChild(line);
117  }
118 
119  {
120  widgetsTab.toggle.setValue(true);
121  widgetsTab.toggle.setLabel("Toggle");
122 
123  HBoxLayout line{Label("Toggle: "), widgetsTab.toggle};
124  vLayout.addChild(line);
125  }
126 
127  {
128  widgetsTab.intSlider.setRange(0, 10);
129  widgetsTab.intSlider.setValue(5);
130 
131  widgetsTab.intSpin.setRange(0, 10);
132  widgetsTab.intSpin.setValue(5);
133 
134  HBoxLayout line{Label("Int: "), widgetsTab.intSlider, widgetsTab.intSpin};
135  vLayout.addChild(line);
136  }
137 
138  {
139  widgetsTab.floatSlider.setRange(0.0f, 2.0f);
140  widgetsTab.floatSlider.setSteps(100);
141  widgetsTab.floatSlider.setValue(0.0f);
142 
143  widgetsTab.floatSpin.setRange(0.0f, 2.0f);
144  widgetsTab.floatSpin.setSteps(20);
145  widgetsTab.floatSpin.setDecimals(2);
146  widgetsTab.floatSpin.setValue(0.4f);
147 
148  HBoxLayout line{Label("Float: "), widgetsTab.floatSlider, widgetsTab.floatSpin};
149  vLayout.addChild(line);
150  }
151 
152  {
153  widgetsTab.button.setLabel("Button");
154 
155  HBoxLayout line{Label("Button: "), widgetsTab.button};
156  vLayout.addChild(line);
157  }
158 
159  vLayout.addChild(VSpacer());
160 
161  GroupBox groupBox;
162  groupBox.setLabel("Group VBoxLayout");
163  groupBox.addChild(vLayout);
164 
165  auto makeButton = [](std::string const & text)
166  {
167  Button result;
168  result.setLabel(text);
169  return result;
170  };
171 
172  GroupBox gridGroupBox;
173  gridGroupBox.setLabel("Group GridLayout");
174  gridGroupBox.addChild(
175  GridLayout()
176  .add(makeButton("1"), Pos{0, 0}, Span{1, 2})
177  .add(makeButton("2"), Pos{0, 2}, Span{2, 1})
178  .add(makeButton("3"), Pos{1, 1}, Span{1, 1})
179  .add(makeButton("4"), Pos{1, 0}, Span{2, 1})
180  .add(Label("foooooooooooooooooo"), Pos{2, 1}, Span{1, 2})
181  .add(HSpacer(), Pos{0, 3}, Span{1, 1})
182  );
183 
184  GroupBox collapsedGroup;
185  collapsedGroup.setLabel("Group Collapsed");
186  collapsedGroup.setCollapsed(true);
187  collapsedGroup.addChild(Label("This can only be seen if expanded"));
188 
189  VBoxLayout root = {groupBox, gridGroupBox, collapsedGroup};
190 
191  RemoteGui_createTab("Example2_Widgets", root, &widgetsTab);
192  }
193 
194 
195  void RemoteGuiExample2::updateTab_Widgets()
196  {
197  widgetsTab.receiveUpdates();
198 
199  // Sync the slider and the spin box manually (slider is the master)
200  int intSliderValue = widgetsTab.intSlider.getValue();
201  widgetsTab.intSpin.setValue(intSliderValue);
202 
203  // And the other way around for the float slider/spin box
204  float floatBoxValue = widgetsTab.floatSpin.getValue();
205  widgetsTab.floatSlider.setValue(floatBoxValue);
206 
207  widgetsTab.sendUpdates();
208  }
209 
210 
211  void RemoteGuiExample2::createTab_Events()
212  {
213  VBoxLayout vLayout;
214 
215  {
216  Label label;
217  label.setText("Counter: ");
218 
219  eventsTab.spinInt.setRange(-10, 10);
220  eventsTab.spinInt.setValue(0);
221 
222 
223  HBoxLayout line;
224  line.addChild(label);
225  line.addChild(eventsTab.spinInt);
226 
227  vLayout.addChild(line);
228  }
229 
230  {
231  eventsTab.buttonUp.setLabel("Up");
232  eventsTab.buttonDown.setLabel("Down");
233 
234  HBoxLayout line;
235  line.addChild(eventsTab.buttonUp);
236  line.addChild(eventsTab.buttonDown);
237 
238  vLayout.addChild(line);
239  }
240 
241  vLayout.addChild(VSpacer());
242 
243  RemoteGui_createTab("Example2_Events", vLayout, &eventsTab);
244  }
245 
246 
247  void RemoteGuiExample2::updateTab_Events()
248  {
249  int currentValue = eventsTab.spinInt.getValue();
250  if (eventsTab.buttonUp.wasClicked())
251  {
252  ++currentValue;
253  }
254  if (eventsTab.buttonDown.wasClicked())
255  {
256  --currentValue;
257  }
258 
259  eventsTab.spinInt.setValue(currentValue);
260  }
261 
262 
264 }
armarx::RemoteGui::Client::IntSpinBox::setValue
void setValue(int newValue)
Definition: Widgets.cpp:58
armarx::RemoteGui::Client::FloatSpinBox::getValue
float getValue() const
Definition: Widgets.cpp:332
armarx::RemoteGuiExample2::onExitComponent
void onExitComponent() override
Definition: RemoteGuiExample2.cpp:78
armarx::RemoteGui::Client::Tab::remove
void remove()
Definition: Tab.cpp:40
armarx::WidgetsTab::lineEdit
LineEdit lineEdit
Definition: RemoteGuiExample2.h:39
armarx::WidgetsTab::floatSpin
FloatSpinBox floatSpin
Definition: RemoteGuiExample2.h:47
armarx::WidgetsTab::checkBox
CheckBox checkBox
Definition: RemoteGuiExample2.h:41
armarx::RemoteGuiExample2::onConnectComponent
void onConnectComponent() override
Definition: RemoteGuiExample2.cpp:61
armarx::RemoteGui::makeButton
detail::ButtonBuilder makeButton(std::string const &name)
Definition: IntegerWidgets.h:48
armarx::RemoteGuiExample2::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RemoteGuiExample2.cpp:48
armarx::RemoteGui::Client::ToggleButton::setLabel
void setLabel(std::string const &label)
Definition: Widgets.cpp:258
armarx::RemoteGui::Client::FloatSpinBox::setValue
void setValue(float newValue)
Definition: Widgets.cpp:337
armarx::RemoteGui::Client::Button::wasClicked
bool wasClicked() const
Definition: Widgets.cpp:130
armarx::RemoteGui::Client::FloatSpinBox::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:313
armarx::RemoteGui::Client::FloatSlider::setValue
void setValue(float newValue)
Definition: Widgets.cpp:371
armarx::RemoteGuiExample2::GetDefaultName
static std::string GetDefaultName()
Definition: RemoteGuiExample2.cpp:42
armarx::WidgetsTab::toggle
ToggleButton toggle
Definition: RemoteGuiExample2.h:42
armarx::RemoteGuiExample2::getDefaultName
std::string getDefaultName() const override
Definition: RemoteGuiExample2.cpp:36
armarx::RemoteGui::Client::IntSlider::setValue
void setValue(int newValue)
Definition: Widgets.cpp:297
armarx::WidgetsTab::combo
ComboBox combo
Definition: RemoteGuiExample2.h:40
armarx::RemoteGui::Client::IntSlider::getValue
int getValue() const
Definition: Widgets.cpp:292
armarx::RemoteGui::Client::Tab::sendUpdates
void sendUpdates()
Definition: Tab.cpp:50
armarx::WidgetsTab::intSpin
IntSpinBox intSpin
Definition: RemoteGuiExample2.h:44
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
armarx::EventsTab::buttonDown
Button buttonDown
Definition: RemoteGuiExample2.h:57
armarx::ARMARX_REGISTER_COMPONENT_EXECUTABLE
ARMARX_REGISTER_COMPONENT_EXECUTABLE(RemoteGuiExample2, RemoteGuiExample2::GetDefaultName())
armarx::RemoteGui::Client::IntSlider::setRange
void setRange(int min, int max)
Definition: Widgets.cpp:285
RemoteGuiExample2.h
armarx::WidgetsTab::button
Button button
Definition: RemoteGuiExample2.h:50
armarx::RemoteGui::Client::FloatSpinBox::setDecimals
void setDecimals(int decimals)
Definition: Widgets.cpp:326
armarx::RemoteGui::Client::FloatSpinBox::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:320
armarx::RemoteGui::Client::Button::setLabel
void setLabel(std::string const &label)
Definition: Widgets.cpp:124
armarx::RemoteGuiExample2::onDisconnectComponent
void onDisconnectComponent() override
Definition: RemoteGuiExample2.cpp:70
armarx::RemoteGui::Client::FloatSlider::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:353
armarx::RemoteGuiExample2::RemoteGuiExample2
RemoteGuiExample2()
Definition: RemoteGuiExample2.cpp:31
armarx::WidgetsTab::intSlider
IntSlider intSlider
Definition: RemoteGuiExample2.h:45
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:110
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Decoupled.h
armarx::RemoteGui::Client::LineEdit::setValue
void setValue(std::string const &text)
Definition: Widgets.cpp:146
armarx::RemoteGui::Client::ToggleButton::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:269
armarx::EventsTab::buttonUp
Button buttonUp
Definition: RemoteGuiExample2.h:56
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::RemoteGui::Client::CheckBox::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:242
armarx::RemoteGui::Client::IntSpinBox::setRange
void setRange(int min, int max)
Definition: Widgets.cpp:51
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_createTab
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
Definition: LightweightRemoteGuiComponentPlugin.cpp:95
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGui::Client::ComboBox::addOptions
void addOptions(std::initializer_list< std::string > options)
Definition: Widgets.cpp:174
armarx::RemoteGuiExample2::onInitComponent
void onInitComponent() override
Definition: RemoteGuiExample2.cpp:56
armarx::RemoteGui::Client::IntSpinBox::getValue
int getValue() const
Definition: Widgets.cpp:68
armarx::RemoteGui::Client::Tab::receiveUpdates
void receiveUpdates()
Definition: Tab.cpp:45
armarx::WidgetsTab::floatSlider
FloatSlider floatSlider
Definition: RemoteGuiExample2.h:48
armarx::RemoteGui::Client::ComboBox::setValue
void setValue(std::string const &newValue)
Definition: Widgets.cpp:192
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::EventsTab::spinInt
IntSpinBox spinInt
Definition: RemoteGuiExample2.h:55
armarx::RemoteGui::Client::FloatSlider::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:360