IntegerWidgets.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QSpinBox>
4 #include <QSlider>
5 #include <QPushButton>
6 
7 #include "Basic.h"
8 
9 namespace armarx::RemoteGui
10 {
11  struct IntSpinBoxHandler : TypedWidget<IntSpinBox, QSpinBox, VALUE_VARIANT_INT>
12  {
13  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
14  const QObject* stateChangeReceiver, const char* stateChangeSlot)
15  {
17  QWidgetT* widget = new QWidgetT();
18 
19  widget->setToolTip(QString::fromStdString(desc.toolTip));
20  widget->setMinimum(desc.min);
21  widget->setMaximum(desc.max);
22 
23  QObject::connect(widget, SIGNAL(valueChanged(int)), stateChangeReceiver, stateChangeSlot);
24 
25  return widget;
26  }
27 
28  static void updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
29  {
30  widget->setValue(value);
31  }
32 
33  static ValueT handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
34  {
35  return widget->value();
36  }
37  };
38 
39  struct IntSliderHandler : TypedWidget<IntSlider, QSlider, VALUE_VARIANT_INT>
40  {
41  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
42  const QObject* stateChangeReceiver, const char* stateChangeSlot)
43  {
45  QWidgetT* widget = new QWidgetT();
46 
47  widget->setToolTip(QString::fromStdString(desc.toolTip));
48  widget->setOrientation(Qt::Horizontal);
49 
50  widget->setMinimum(desc.min);
51  widget->setMaximum(desc.max);
52 
53  QObject::connect(widget, SIGNAL(valueChanged(int)), stateChangeReceiver, stateChangeSlot);
54 
55  return widget;
56  }
57 
58  static void updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
59  {
60  widget->setValue(value);
61  }
62 
63  static ValueT handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
64  {
65  return widget->value();
66  }
67  };
68 
69  struct ButtonHandler : TypedWidget<Button, QPushButton, VALUE_VARIANT_INT>
70  {
71  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
72  const QObject* stateChangeReceiver, const char* stateChangeSlot)
73  {
75  QWidgetT* widget = new QWidgetT();
76  widget->setToolTip(QString::fromStdString(desc.toolTip));
77  widget->setText(toQString(desc.label));
78 
79  QObject::connect(widget, SIGNAL(clicked()), stateChangeReceiver, stateChangeSlot);
80 
81  return widget;
82  }
83 
84  static void updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
85  {
86  widget->setProperty("ClickCount", QVariant(value));
87  }
88 
89  static ValueT handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
90  {
91  int newValue = widget->property("ClickCount").toInt() + 1;
92  widget->setProperty("ClickCount", QVariant(newValue));
93  return newValue;
94  }
95  };
96 }
armarx::RemoteGui::ButtonHandler
Definition: IntegerWidgets.h:69
armarx::RemoteGui::ButtonHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: IntegerWidgets.h:84
armarx::RemoteGui
Definition: LightweightRemoteGuiComponentPlugin.h:30
armarx::RemoteGui::TypedWidget
Definition: TypedWidget.h:115
armarx::RemoteGui::ButtonHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: IntegerWidgets.h:71
armarx::RemoteGui::IntSpinBoxHandler
Definition: IntegerWidgets.h:11
armarx::RemoteGui::TypedWidget< IntSpinBox, QSpinBox, VALUE_VARIANT_INT >::ValueT
typename Storage< ValueType >::Type ValueT
Definition: TypedWidget.h:120
armarx::RemoteGui::IntSliderHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: IntegerWidgets.h:63
armarx::RemoteGui::IntSpinBoxHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: IntegerWidgets.h:33
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RemoteGui::ButtonHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: IntegerWidgets.h:89
Basic.h
armarx::RemoteGui::IntSliderHandler
Definition: IntegerWidgets.h:39
armarx::RemoteGui::Client::IntSlider
Definition: Widgets.h:81
armarx::RemoteGui::IntSliderHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: IntegerWidgets.h:58
armarx::RemoteGui::IntSpinBoxHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: IntegerWidgets.h:28
armarx::RemoteGui::TypedWidget< IntSpinBox, QSpinBox, VALUE_VARIANT_INT >::QWidgetT
QSpinBox QWidgetT
Definition: TypedWidget.h:118
armarx::RemoteGui::IntSliderHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: IntegerWidgets.h:41
armarx::RemoteGui::Client::IntSpinBox
Definition: Widgets.h:69
armarx::RemoteGui::toQString
QString toQString(std::string const &string)
Definition: WidgetHandler.cpp:12
armarx::RemoteGui::Client::Button
Definition: Widgets.h:120
armarx::RemoteGui::CreateWidgetCallback
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
Definition: WidgetHandler.h:20
armarx::RemoteGui::IntSpinBoxHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: IntegerWidgets.h:13