BatteryWidget.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QGridLayout>
4 #include <QLabel>
5 #include <QPaintEvent>
6 #include <QPainter>
7 #include <QPainterPath>
8 #include <QTimer>
9 #include <QWidget>
10 
11 #include <IceUtil/UUID.h>
12 
14 #include <ArmarXCore/interface/components/BatteryManagementInterface.h>
15 
17 
18 Q_DECLARE_METATYPE(armarx::dto::BatteryStatus)
19 
20 namespace armarx
21 {
22  class ArmarXMainWindow;
23 
24  class BatteryIcon : public QWidget
25  {
26  Q_OBJECT
27  public:
28  explicit BatteryIcon(QWidget* parent = 0);
29 
30  void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
31 
32  void setPercentage(int percentage);
33 
34  void setState(dto::BatteryState state);
35 
36  QSize sizeHint() const Q_DECL_OVERRIDE;
37 
38  private:
39  int percentage = 0;
40  dto::BatteryState state = dto::BatteryState::unavailable;
41  };
42 
44  {
45  Q_OBJECT
46  public:
47  explicit BatteryWidget(QWidget* parent = 0, ArmarXMainWindow* mainWindow = 0);
48 
49  QWidget* getBatteryWidget();
50 
51  signals:
54 
55  public slots:
56  void updateBatteryStatus();
57 
58  void updateTooltip();
59 
60  void setBatteryStatus(dto::BatteryStatus batteryStatus);
61 
62  // ManagedIceObject interface
63  protected:
64  void onInitComponent() override;
65  void onConnectComponent() override;
66  void onDisconnectComponent() override;
67  std::string getDefaultName() const override;
68 
69  private:
70  ArmarXMainWindow* mainWindow;
71  QGridLayout* layout;
72  BatteryIcon* icon;
73  QLabel* lbl;
74  QString txtPercentage;
75  QTimer* timer;
76 
77  armarx::BatteryManagementInterfacePrx batteryManagement;
78 
79  dto::BatteryStatus const invalidStatus{.name = "invalid",
80  .state = dto::BatteryState::unavailable,
81  .designEnergy_Wh = -1,
82  .fullChargeEnergy_Wh = -1,
83  .energy_Wh = -1,
84  .energyFromFullCharge_pct = 0,
85  .fullEnergyFromDesignEnergy_pct = 0,
86  .temperature_degC = -1,
87  .ratedVoltage_V = -1,
88  .voltage_V = -1,
89  .current_A = -1,
90  .power_W = -1,
91  .remainingTime_h = -1,
92  .hasError = false,
93  .error = ""};
94 
95  dto::BatteryStatus lastStatus = invalidStatus;
96 
97  // ArmarXWidgetController interface
98  public:
99  static QString
101  {
102  return "BatteryWidget";
103  }
104 
105  void loadSettings(QSettings* settings) override;
106  void saveSettings(QSettings* settings) override;
107  std::string iceNameUUID = IceUtil::generateUUID();
108  };
109 
111 } // namespace armarx
armarx::BatteryIcon::setState
void setState(dto::BatteryState state)
Definition: BatteryWidget.cpp:121
armarx::BatteryWidget::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: BatteryWidget.cpp:276
armarx::BatteryWidget::updateBatteryStatus
void updateBatteryStatus()
Definition: BatteryWidget.cpp:315
armarx::BatteryWidget::BatteryWidget
BatteryWidget(QWidget *parent=0, ArmarXMainWindow *mainWindow=0)
Definition: BatteryWidget.cpp:132
armarx::ArmarXMainWindow
The ArmarXMainWindow class.
Definition: ArmarXMainWindow.h:76
armarx::BatteryState
BatteryState
Definition: SensorValueBattery.h:10
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
armarx::BatteryWidget::stopPeriodicStateUpdate
void stopPeriodicStateUpdate()
armarx::BatteryWidget::getBatteryWidget
QWidget * getBatteryWidget()
Definition: BatteryWidget.cpp:167
IceInternal::Handle< BatteryWidget >
armarx::BatteryWidget::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: BatteryWidget.cpp:270
armarx::BatteryIcon::BatteryIcon
BatteryIcon(QWidget *parent=0)
Definition: BatteryWidget.cpp:10
ArmarXComponentWidgetController.h
armarx::BatteryIcon::paintEvent
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE
Definition: BatteryWidget.cpp:17
armarx::BatteryWidget::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: BatteryWidget.cpp:309
IceGridAdmin.h
armarx::BatteryIcon::sizeHint
QSize sizeHint() const Q_DECL_OVERRIDE
Definition: BatteryWidget.cpp:127
armarx::BatteryWidget
Definition: BatteryWidget.h:43
armarx::BatteryWidget::updateTooltip
void updateTooltip()
Definition: BatteryWidget.cpp:173
armarx::BatteryWidget::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: BatteryWidget.cpp:288
armarx::BatteryIcon
Definition: BatteryWidget.h:24
armarx::BatteryWidget::setBatteryStatus
void setBatteryStatus(dto::BatteryStatus batteryStatus)
Definition: BatteryWidget.cpp:334
armarx::BatteryWidget::GetWidgetName
static QString GetWidgetName()
Definition: BatteryWidget.h:100
armarx::BatteryWidget::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: BatteryWidget.cpp:359
armarx::BatteryWidget::iceNameUUID
std::string iceNameUUID
Definition: BatteryWidget.h:107
armarx::BatteryWidget::startPeriodicStateUpdate
void startPeriodicStateUpdate()
armarx::BatteryIcon::setPercentage
void setPercentage(int percentage)
Definition: BatteryWidget.cpp:115
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::BatteryWidget::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: BatteryWidget.cpp:303