20 .type = ElementType::Display14,
21 .group = ElementGroup::Output,
24 .canChangeAppearance =
true,
27 .rotatesGraphic =
false,
29 static_assert(
validate(constraints));
34 meta.pixmapPath = []{
return QStringLiteral(
":/Components/Output/Counter/counter_14_on.svg"); };
35 meta.titleText = QT_TRANSLATE_NOOP(
"Display14",
"14-SEGMENT DISPLAY");
36 meta.translatedName = QT_TRANSLATE_NOOP(
"Display14",
"14-Segment Display");
37 meta.trContext =
"Display14";
38 meta.defaultAppearances = QStringList({
39 ":/Components/Output/Counter/counter_14_off.svg",
40 ":/Components/Output/Counter/counter_a.svg",
41 ":/Components/Output/Counter/counter_b.svg",
42 ":/Components/Output/Counter/counter_c.svg",
43 ":/Components/Output/Counter/counter_d.svg",
44 ":/Components/Output/Counter/counter_e.svg",
45 ":/Components/Output/Counter/counter_f.svg",
46 ":/Components/Output/Counter/counter_g1.svg",
47 ":/Components/Output/Counter/counter_g2.svg",
48 ":/Components/Output/Counter/counter_h.svg",
49 ":/Components/Output/Counter/counter_j.svg",
50 ":/Components/Output/Counter/counter_k.svg",
51 ":/Components/Output/Counter/counter_l.svg",
52 ":/Components/Output/Counter/counter_m.svg",
53 ":/Components/Output/Counter/counter_n.svg",
54 ":/Components/Output/Counter/counter_dp.svg",
114 for (
auto *port :
inputs()) {
115 port->setRequired(
false);
116 port->setDefaultStatus(Status::Inactive);
124void Display14::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
130 const QRectF body(0, 0, 64, 64);
131 if (
inputPort(0)->status() == Status::Active) { g1.at(m_colorNumber)->render(painter, body); }
132 if (
inputPort(1)->status() == Status::Active) { f.at(m_colorNumber)->render(painter, body); }
133 if (
inputPort(2)->status() == Status::Active) { e.at(m_colorNumber)->render(painter, body); }
134 if (
inputPort(3)->status() == Status::Active) { d.at(m_colorNumber)->render(painter, body); }
135 if (
inputPort(4)->status() == Status::Active) { a.at(m_colorNumber)->render(painter, body); }
136 if (
inputPort(5)->status() == Status::Active) { b.at(m_colorNumber)->render(painter, body); }
137 if (
inputPort(6)->status() == Status::Active) { dp.at(m_colorNumber)->render(painter, body); }
138 if (
inputPort(7)->status() == Status::Active) { c.at(m_colorNumber)->render(painter, body); }
139 if (
inputPort(8)->status() == Status::Active) { g2.at(m_colorNumber)->render(painter, body); }
140 if (
inputPort(9)->status() == Status::Active) { h.at(m_colorNumber)->render(painter, body); }
141 if (
inputPort(10)->status() == Status::Active) { j.at(m_colorNumber)->render(painter, body); }
142 if (
inputPort(11)->status() == Status::Active) { k.at(m_colorNumber)->render(painter, body); }
143 if (
inputPort(12)->status() == Status::Active) { l.at(m_colorNumber)->render(painter, body); }
144 if (
inputPort(13)->status() == Status::Active) { m.at(m_colorNumber)->render(painter, body); }
145 if (
inputPort(14)->status() == Status::Active) { n.at(m_colorNumber)->render(painter, body); }
163 QMap<QString, QVariant> map;
167 map.insert(
"color",
color());
187 if (map.contains(
"color")) {
188 setColor(map.value(
"color").toString());
Graphic element for the 14-segment LED display.
Graphic element for the 7-segment LED display.
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.
14-segment LED display output element (14 segments + decimal point = 15 inputs).
void save(QDataStream &stream, SerializationOptions options) const override
Serializes the color selection to stream.
void refresh() override
Refreshes the displayed segments based on current input states.
static constexpr const char * kDefaultColor
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Display14(QGraphicsItem *parent=nullptr)
Constructs the element with optional parent.
void load(QDataStream &stream, SerializationContext &context) override
QString color() const override
Returns the current display color name.
void updatePortsProperties() override
Updates port positions (fixed at 15 inputs).
void setColor(const QString &color) override
Sets the display color.
static QVector< std::shared_ptr< QSvgRenderer > > cachedSegmentRenderers(const QString &resourcePath)
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
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.
InputPort * inputPort(const int index=0) const
Returns the input port at index (default 0).
static int colorNameToIndex(const QString &color)
Maps a color name ("White","Red","Green","Blue","Purple") to indices 0–4.
virtual void save(QDataStream &stream, SerializationOptions options) const
const QVector< InputPort * > & inputs() const
Returns a const reference to the vector of all input ports.
void setName(const QString &name)
Sets the label text shown next to the port.
static QString readBoundedString(QDataStream &stream)
Reads a QString from stream, refusing to allocate more bytes than remain in the stream (prevents OOM ...
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.
static const bool registered
static ElementMetadata metadata()
static constexpr ElementConstraints constraints
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.