wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
InputRotary.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
11
20{
21 Q_OBJECT
22
23public:
24 // --- Lifecycle ---
25
27 explicit InputRotary(QGraphicsItem *parent = nullptr);
28
29 // --- State Queries ---
30
32 bool isOn(const int port = 0) const override;
33
35 int outputSize() const override;
36
38 int outputValue() const override;
39
40 // --- State Setters ---
41
43 void setOff() override;
44
46 void setOn() override;
47
53 void setOn(const bool value, const int port = 0) override;
54
57 void setWaveformValue(const bool value, const int port = 0) override;
58
59 // --- Visual ---
60
62 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
63
65 void refresh() override;
66
68 void setAppearance(const bool defaultAppearance, const QString &fileName) override;
69
71 void updatePortsProperties() override;
72
73 // --- Serialization ---
74
76 void load(QDataStream &stream, SerializationContext &context) override;
77
79 void save(QDataStream &stream, SerializationOptions options) const override;
80
81protected:
82 // --- Event handlers ---
83
85 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
86
87private:
88 // --- Members ---
89
90 QPixmap m_rotary;
91 int m_currentPort = 0;
92};
Abstract base class for user-controllable input elements.
GraphicElementInput(ElementType type, QGraphicsItem *parent=nullptr)
int outputValue() const override
Returns the index of the currently active output port.
InputRotary(QGraphicsItem *parent=nullptr)
Constructs the rotary switch with optional parent.
void setOn() override
Activates port 0 (no-op if already at 0).
void updatePortsProperties() override
Recalculates port positions based on the current output count.
bool isOn(const int port=0) const override
Returns true if output port port is the currently active selection.
void save(QDataStream &stream, SerializationOptions options) const override
Serializes the current port selection to stream.
void setWaveformValue(const bool value, const int port=0) override
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
int outputSize() const override
Returns the number of selectable output ports.
void setAppearance(const bool defaultAppearance, const QString &fileName) override
Applies custom appearance images for the rotary body and arrow.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the rotary wheel with the indicator arrow pointing to the active port.
void setOff() override
Resets the selection to port 0 (logic-0 on all ports).
void refresh() override
Refreshes the arrow direction and port positions.
void load(QDataStream &stream, SerializationContext &context) override
Deserializes the current port selection.
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...
Options passed to GraphicElement::save() (and friends); the save-side counterpart of SerializationCon...