AdvancedControllerRemoteCPP/panel/panelwidget.h

56 lines
1.9 KiB
C++

// panelwidget.h - the front panel of the AdvancedController: the same buttons with the same
// icons as the real device, drawn as vectors. A click on a button sends the "KEY" command the
// physical button generates; the led of every button mirrors the real led of the device.
// Hold a button for 1.5 s to get the "long press" where the device has one (ENTER -> camera
// OSD menu, crosshair 1 / 2 -> edit mode).
#ifndef PANELWIDGET_H
#define PANELWIDGET_H
#include <QElapsedTimer>
#include <QHash>
#include <QString>
#include <QWidget>
class PanelWidget : public QWidget
{
Q_OBJECT
public:
static constexpr int LongPressMs = 1500; // hold time for the long press (as in the firmware)
explicit PanelWidget(QWidget *parent = nullptr);
void setLeds(quint32 mask); // bit order = AdvCtrl::RemoteClient::LedNames
void setInteractive(bool on); // presses count only while the controller is connected
// A button pressed / released by the mouse or the PC keyboard.
void press(const QString &button);
void release(const QString &button);
signals:
void keyPressed(const QString &key); // name for "KEY", e.g. "ENTER" or "LONGENTER"
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
struct Geometry
{
double scale; // pixels per unit (1 unit = distance between button centres)
double ox; // top left corner of the panel
double oy;
};
Geometry geometry() const;
QString buttonAt(const QPointF &pos) const;
quint32 m_mask = 0;
bool m_interactive = false;
QHash<QString, QElapsedTimer> m_pressed; // buttons held down and since when
QString m_mouseButton; // button under the mouse press
};
#endif // PANELWIDGET_H