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 namespace armarx
28 {
29 
31  {
32  }
33 
34  std::string
36  {
37  return GetDefaultName();
38  }
39 
40  std::string
42  {
43  return "RemoteGuiExample2";
44  }
45 
48  {
51 
52  return defs;
53  }
54 
55  void
57  {
58  }
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
79  {
81  }
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
armarx::RemoteGui::Client::IntSpinBox::setValue
void setValue(int newValue)
Definition: Widgets.cpp:59
armarx::RemoteGui::Client::FloatSpinBox::getValue
float getValue() const
Definition: Widgets.cpp:352
armarx::RemoteGuiExample2::onExitComponent
void onExitComponent() override
Definition: RemoteGuiExample2.cpp:78
armarx::RemoteGui::Client::Tab::remove
void remove()
Definition: Tab.cpp:43
armarx::WidgetsTab::lineEdit
LineEdit lineEdit
Definition: RemoteGuiExample2.h:37
armarx::WidgetsTab::floatSpin
FloatSpinBox floatSpin
Definition: RemoteGuiExample2.h:45
armarx::WidgetsTab::checkBox
CheckBox checkBox
Definition: RemoteGuiExample2.h:39
armarx::RemoteGuiExample2::onConnectComponent
void onConnectComponent() override
Definition: RemoteGuiExample2.cpp:61
armarx::RemoteGui::makeButton
detail::ButtonBuilder makeButton(std::string const &name)
Definition: IntegerWidgets.h:52
armarx::RemoteGuiExample2::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RemoteGuiExample2.cpp:47
armarx::RemoteGui::Client::ToggleButton::setLabel
void setLabel(std::string const &label)
Definition: Widgets.cpp:269
armarx::RemoteGui::Client::FloatSpinBox::setValue
void setValue(float newValue)
Definition: Widgets.cpp:358
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:330
armarx::RemoteGui::Client::FloatSlider::setValue
void setValue(float newValue)
Definition: Widgets.cpp:396
armarx::RemoteGuiExample2::GetDefaultName
static std::string GetDefaultName()
Definition: RemoteGuiExample2.cpp:41
armarx::WidgetsTab::toggle
ToggleButton toggle
Definition: RemoteGuiExample2.h:40
armarx::RemoteGuiExample2::getDefaultName
std::string getDefaultName() const override
Definition: RemoteGuiExample2.cpp:35
armarx::RemoteGui::Client::IntSlider::setValue
void setValue(int newValue)
Definition: Widgets.cpp:313
armarx::WidgetsTab::combo
ComboBox combo
Definition: RemoteGuiExample2.h:38
armarx::RemoteGui::Client::IntSlider::getValue
int getValue() const
Definition: Widgets.cpp:307
armarx::RemoteGui::Client::Tab::sendUpdates
void sendUpdates()
Definition: Tab.cpp:55
armarx::WidgetsTab::intSpin
IntSpinBox intSpin
Definition: RemoteGuiExample2.h:42
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:6
armarx::EventsTab::buttonDown
Button buttonDown
Definition: RemoteGuiExample2.h:55
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:299
RemoteGuiExample2.h
armarx::WidgetsTab::button
Button button
Definition: RemoteGuiExample2.h:48
armarx::RemoteGui::Client::FloatSpinBox::setDecimals
void setDecimals(int decimals)
Definition: Widgets.cpp:345
armarx::RemoteGui::Client::FloatSpinBox::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:338
armarx::RemoteGui::Client::Button::setLabel
void setLabel(std::string const &label)
Definition: Widgets.cpp:123
armarx::RemoteGuiExample2::onDisconnectComponent
void onDisconnectComponent() override
Definition: RemoteGuiExample2.cpp:70
armarx::RemoteGui::Client::FloatSlider::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:375
armarx::RemoteGuiExample2::RemoteGuiExample2
RemoteGuiExample2()
Definition: RemoteGuiExample2.cpp:30
armarx::WidgetsTab::intSlider
IntSlider intSlider
Definition: RemoteGuiExample2.h:43
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:119
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
Decoupled.h
armarx::RemoteGui::Client::LineEdit::setValue
void setValue(std::string const &text)
Definition: Widgets.cpp:147
armarx::RemoteGui::Client::ToggleButton::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:282
armarx::EventsTab::buttonUp
Button buttonUp
Definition: RemoteGuiExample2.h:54
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::RemoteGui::Client::CheckBox::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:252
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:103
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGui::Client::ComboBox::addOptions
void addOptions(std::initializer_list< std::string > options)
Definition: Widgets.cpp:177
armarx::RemoteGuiExample2::onInitComponent
void onInitComponent() override
Definition: RemoteGuiExample2.cpp:56
armarx::RemoteGui::Client::IntSpinBox::getValue
int getValue() const
Definition: Widgets.cpp:71
armarx::RemoteGui::Client::Tab::receiveUpdates
void receiveUpdates()
Definition: Tab.cpp:49
armarx::WidgetsTab::floatSlider
FloatSlider floatSlider
Definition: RemoteGuiExample2.h:46
armarx::RemoteGui::Client::ComboBox::setValue
void setValue(std::string const &newValue)
Definition: Widgets.cpp:197
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::EventsTab::spinInt
IntSpinBox spinInt
Definition: RemoteGuiExample2.h:53
armarx::RemoteGui::Client::FloatSlider::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:383