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
27namespace armarx
28{
29
33
34 std::string
36 {
37 return GetDefaultName();
38 }
39
40 std::string
42 {
43 return "RemoteGuiExample2";
44 }
45
54
55 void
59
60 void
62 {
63 createTab_Widgets();
64 createTab_Events();
65
67 }
68
69 void
71 {
72 ARMARX_INFO << "Removing tabs";
73 widgetsTab.remove();
74 eventsTab.remove();
75 }
76
77 void
82
83 void
84 RemoteGuiExample2::RemoteGui_update()
85 {
86 updateTab_Widgets();
87 updateTab_Events();
88 }
89
90 void
91 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(GridLayout()
175 .add(makeButton("1"), Pos{0, 0}, Span{1, 2})
176 .add(makeButton("2"), Pos{0, 2}, Span{2, 1})
177 .add(makeButton("3"), Pos{1, 1}, Span{1, 1})
178 .add(makeButton("4"), Pos{1, 0}, Span{2, 1})
179 .add(Label("foooooooooooooooooo"), Pos{2, 1}, Span{1, 2})
180 .add(HSpacer(), Pos{0, 3}, Span{1, 1}));
181
182 GroupBox collapsedGroup;
183 collapsedGroup.setLabel("Group Collapsed");
184 collapsedGroup.setCollapsed(true);
185 collapsedGroup.addChild(Label("This can only be seen if expanded"));
186
187 VBoxLayout root = {groupBox, gridGroupBox, collapsedGroup};
188
189 RemoteGui_createTab("Example2_Widgets", root, &widgetsTab);
190 }
191
192 void
193 RemoteGuiExample2::updateTab_Widgets()
194 {
195 widgetsTab.receiveUpdates();
196
197 // Sync the slider and the spin box manually (slider is the master)
198 int intSliderValue = widgetsTab.intSlider.getValue();
199 widgetsTab.intSpin.setValue(intSliderValue);
200
201 // And the other way around for the float slider/spin box
202 float floatBoxValue = widgetsTab.floatSpin.getValue();
203 widgetsTab.floatSlider.setValue(floatBoxValue);
204
205 widgetsTab.sendUpdates();
206 }
207
208 void
209 RemoteGuiExample2::createTab_Events()
210 {
211 VBoxLayout vLayout;
212
213 {
214 Label label;
215 label.setText("Counter: ");
216
217 eventsTab.spinInt.setRange(-10, 10);
218 eventsTab.spinInt.setValue(0);
219
220
221 HBoxLayout line;
222 line.addChild(label);
223 line.addChild(eventsTab.spinInt);
224
225 vLayout.addChild(line);
226 }
227
228 {
229 eventsTab.buttonUp.setLabel("Up");
230 eventsTab.buttonDown.setLabel("Down");
231
232 HBoxLayout line;
233 line.addChild(eventsTab.buttonUp);
234 line.addChild(eventsTab.buttonDown);
235
236 vLayout.addChild(line);
237 }
238
239 vLayout.addChild(VSpacer());
240
241 RemoteGui_createTab("Example2_Events", vLayout, &eventsTab);
242 }
243
244 void
245 RemoteGuiExample2::updateTab_Events()
246 {
247 int currentValue = eventsTab.spinInt.getValue();
248 if (eventsTab.buttonUp.wasClicked())
249 {
250 ++currentValue;
251 }
252 if (eventsTab.buttonDown.wasClicked())
253 {
254 --currentValue;
255 }
256
257 eventsTab.spinInt.setValue(currentValue);
258 }
259
261} // namespace armarx
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Brief description of class RemoteGuiExample2.
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
static std::string GetDefaultName()
std::string getDefaultName() const override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
detail::ButtonBuilder makeButton(std::string const &name)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
void setValue(std::string const &text)
Definition Widgets.cpp:147