6#include <QGraphicsSceneMouseEvent>
20 .type = ElementType::InputRotary,
21 .group = ElementGroup::Input,
24 .canChangeAppearance =
true,
28 static_assert(
validate(constraints));
33 meta.pixmapPath = []{
return QStringLiteral(
":/Components/Input/rotary_icon.svg"); };
34 meta.titleText = QT_TRANSLATE_NOOP(
"InputRotary",
"ROTARY SWITCH");
35 meta.translatedName = QT_TRANSLATE_NOOP(
"InputRotary",
"Rotary Switch");
36 meta.trContext =
"InputRotary";
37 meta.defaultAppearances = QStringList({
38 ":/Components/Input/rotary.svg",
39 ":/Components/Input/rotary_arrow.svg",
187 static QSvgRenderer renderer(QStringLiteral(
":/Components/Input/rotary_arrow.svg"));
197 for (
int port = 0; port <
outputSize(); ++port) {
201 const double angle = 360. /
outputSize() * port;
208 const QRectF mark = QRectF{30.2, 8.727, 3.6, 6.4};
211 painter->setBrush(QBrush{QColor{255, 246, 213}});
212 painter->translate(center.x(), center.y());
213 painter->rotate(angle);
214 painter->translate(-center.x(), -center.y());
215 painter->drawRect(mark);
219 if (m_currentPort != port) {
226 painter->translate(center.x(), center.y());
227 painter->rotate(angle);
228 painter->translate(-center.x(), -center.y());
237 return (m_currentPort == port);
255 m_currentPort = port;
259 if (m_currentPort < 0 || m_currentPort >=
outputSize()) {
266 for (
int index = 0; index <
outputSize(); ++index) {
267 outputPort(index)->
setStatus((m_currentPort == index) ? Status::Active : Status::Inactive);
282 if (!
m_locked && (event->button() == Qt::LeftButton)) {
287 QGraphicsItem::mousePressEvent(event);
296 QMap<QString, QVariant> map;
299 if (!slim || m_currentPort != 0) {
300 map.insert(
"currentPort", m_currentPort);
315 stream >> m_currentPort;
326 if (map.contains(
"currentPort")) {
327 m_currentPort = map.value(
"currentPort").toInt();
330 if (map.contains(
"locked")) {
331 m_locked = map.value(
"locked").toBool();
336 setOn(
true, m_currentPort);
341 if (defaultAppearance) {
347 m_appearance.setUsingDefaultAppearance(defaultAppearance);
353 return static_cast<int>(
outputs().size());
358 return m_currentPort;
Singleton factory for all circuit element types.
Self-registering element trait template and compile-time constraint validation.
ElementMetadata metadataFromConstraints(const ElementConstraints &c)
Converts ElementConstraints to an ElementMetadata with all constraint-derived fields set.
constexpr bool validate(const ElementConstraints &c)
Validates element constraints at compile time.
Enums::ElementType ElementType
Port classes: Port (base), InputPort, and OutputPort.
Deserialization/serialization context structs passed through load()/save() call chains.
Circuit and waveform file serialization/deserialization utilities.
Named version predicates for file-format compatibility checks.
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
QPointF pixmapCenter() const
Returns the centre point of the element's pixmap in local coordinates.
ElementAppearance m_appearance
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the element onto the scene.
virtual void load(QDataStream &stream, SerializationContext &context)
Loads the graphic element through a binary data stream.
OutputPort * outputPort(const int index=0) const
Returns the output port at index (default 0).
virtual void save(QDataStream &stream, SerializationOptions options) const
void setPixmap(const QString &pixmapPath)
Loads and applies the pixmap located at pixmapPath.
const QVector< OutputPort * > & outputs() const
Returns a const reference to the vector of all output ports.
void setStatus(const Status status) override
void setName(const QString &name)
Sets the label text shown next to the port.
static QMap< QString, QVariant > readBoundedMetadata(QDataStream &stream)
Reads the file-level metadata QMap<QString,QVariant> from stream without calling QList::reserve() wit...
bool hasLockState(const QVersionNumber &v)
V3.1: Lock state for input elements; color for some display/button types.
bool hasQMapFormat(const QVersionNumber &v)
V4.1: Format changed from flat binary to keyed QMap; port serial IDs; rotation fix.
Compile-time-validatable subset of ElementMetadata.
Self-registering element information trait.
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...
QVersionNumber version
File-format version read from the stream header.
Options passed to GraphicElement::save() (and friends); the save-side counterpart of SerializationCon...
SerializationPurpose purpose
What this serialization is for; see SerializationPurpose. Mandatory, no default.