BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
powerunit_gui.h
Go to the documentation of this file.
1 /*! \file
2  * \brief A class for the GUI controlling of a power unit
3  * \author Benjamin Pritchard (ben@bennyp.org)
4  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
5  */
6 
7 #ifndef POWERUNIT_GUI_H
8 #define POWERUNIT_GUI_H
9 
10 #include <QLabel>
11 #include <QSlider>
12 #include <QPushButton>
13 #include <QMessageBox>
14 #include <QSharedPointer>
15 
16 #include "powerunit.h"
17 #include "microcontexception.h"
18 
19 //! A GUI interface to a power unit
21 {
22  Q_OBJECT;
23 
24 private:
25  QLabel * _label; //!< A label for the power unit
26  QSlider * _levelslider; //!< A slider for displaying and controlling the dimmer level
27  QPushButton * _onbutton; //!< A button that will turn the power unit on
28  QPushButton *_offbutton; //!< A button that will turn the power unit off
29  QWidget * _parent; //!< A parent widget
30 
31  Q_DISABLE_COPY(PUInterfaceGUI)
32 
33  //! Displays a message box with exception information
34  void ExceptionBox(const MCInterfaceException & e);
35 
36 private slots:
37  //! Called when the dimmer level slider is changed
38  /*!
39  * \param[in] val The new level
40  * \throw MCInterfaceException There is a problem communicating this command
41  * to the microcontroller
42  */
43  void LevelSliderChange(int val);
44 
45  //! Called when an event should turn the power unit on
46  /*!
47  * \throw MCInterfaceException There is a problem communicating this command
48  * to the microcontroller
49  */
50  void TurnOn(void);
51 
52  //! Called when an event should turn the power unit on
53  /*!
54  * \throw MCInterfaceException There is a problem communicating this command
55  * to the microcontroller
56  */
57  void TurnOff(void);
58 
59 public:
60 
61  //! Create an object with the given information
62  /*!
63  * \param id The numerical ID of the power unit (see commands.h)
64  * \param desc A text description of this unit
65  * \param mc The microcontroller controlling this unit
66  * \param parent A parent widget
67  */
68  PUInterfaceGUI(quint8 id, const QString & desc, QSharedPointer<MCInterface> mc, QWidget *parent);
69 
70  ~PUInterfaceGUI();
71 
72  //! Attaches this PUInterfaceGUI object to the interface elements
73  void AttachToGui(QLabel * label, QPushButton * onbutton, QPushButton * offbutton,
74  QSlider * levelslider);
75 
76  //! Synchronizes the GUI elements with the state of the underlying PUInterface object
77  /*!
78  * This does not obtain any information from the microcontroller
79  */
80  void SyncGUI(void);
81 
82  //! Resets the state of the power unit
83  /*!
84  * This does not send or receive any information from the microcontroller
85  */
86  void Reset(void);
87 
88  //! Changes the state and dimmer level to the passed values
89  /*!
90  * This does not send or receive any information from the microcontroller
91  */
92  void SyncState(char state, quint8 level);
93 };
94 
95 #endif // MICROCONT_GUI_H
96