SILICON
Loading...
Searching...
No Matches
graphicalText.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#pragma once
8
10
11namespace SILICON::ui {
12
15public:
16 static constexpr std::string_view COMPONENT_TYPE = "Text";
17
18 explicit GraphicalText(QGraphicsItem* parent = nullptr);
19
20 [[nodiscard]] int type() const override { return TEXT; }
21 [[nodiscard]] std::string getTypeName() const override
22 {
23 return std::string(COMPONENT_TYPE);
24 }
25 [[nodiscard]] const PropertyMap& getProperties() const override { return properties; }
26 [[nodiscard]] std::optional<std::reference_wrapper<const StringPropertyOptions>>
27 getStringPropertyOptions(std::string_view key) const override;
28 [[nodiscard]] bool isMultilineProperty(std::string_view key) const override
29 {
30 return key == "text";
31 }
32 [[nodiscard]] bool participatesInCollisions() const override { return false; }
33
34 [[nodiscard]] std::span<const ResizeHandle> resizeHandles() const override
35 {
36 return AllResizeHandles;
37 }
38 [[nodiscard]] PropertyMap resizedProperties(QSizeF size, ResizeHandle handle,
39 const PropertyMap& initial) override;
40
41 void applyProperty(std::string_view key, const PropertyValue& value) override;
42 [[nodiscard]] nlohmann::ordered_json serialize() const override;
43 void loadSerializedState(const nlohmann::json& json) override;
44
45private:
46 void setProperties(PropertyMap next);
47 PropertyMap properties{{"text", std::string("Text")},
48 {"size", 12},
49 {"font", std::string("Quicksand")},
50 {"wrapWidth", 0}};
51};
52
53} // namespace SILICON::ui
GraphicalComponent(ItemCategory category, QGraphicsItem *shape, QGraphicsItem *parent=nullptr, bool scanShape=false)
void applyProperty(std::string_view key, const PropertyValue &value) override
nlohmann::ordered_json serialize() const override
Serializes the component to JSON.
int type() const override
std::optional< std::reference_wrapper< const StringPropertyOptions > > getStringPropertyOptions(std::string_view key) const override
PropertyMap resizedProperties(QSizeF size, ResizeHandle handle, const PropertyMap &initial) override
bool participatesInCollisions() const override
Annotations remain selectable but do not obstruct placement or routing.
void setProperties(PropertyMap next)
void loadSerializedState(const nlohmann::json &json) override
Loads subclass-specific serialized state.
static constexpr std::string_view COMPONENT_TYPE
GraphicalText(QGraphicsItem *parent=nullptr)
std::string getTypeName() const override
Gets the component type name for serialization.
std::span< const ResizeHandle > resizeHandles() const override
const PropertyMap & getProperties() const override
Properties exposed by graphical and simulation components alike.
bool isMultilineProperty(std::string_view key) const override
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
std::unordered_map< std::string, PropertyValue, TransparentStringHash, TransparentStringEqual > PropertyMap
Map from property names to their values.
constexpr std::array AllResizeHandles