23#include <QGraphicsRectItem>
31using namespace SILICON::core;
35 constexpr QRectF RomBodyRect(0.0, 0.0, 100.0, 80.0);
37 class RomShape final :
public QGraphicsRectItem {
39 explicit RomShape(QGraphicsItem* parent =
nullptr)
40 : QGraphicsRectItem(RomBodyRect, parent)
44 void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
45 QWidget* widget)
override
51 painter->setRenderHint(QPainter::Antialiasing,
false);
54 painter->drawRect(rect());
56 painter->setFont(QFont(
"Quicksand", 10, QFont::Bold));
57 painter->drawText(rect(), QStringLiteral(
"ROM"), QTextOption(Qt::AlignCenter));
62 std::shared_ptr<ROM> makeRom()
64 return std::make_shared<ROM>(
Bus(1), std::make_shared<Wire>(),
65 std::make_shared<Wire>(),
Bus(8));
100 const auto rom = std::dynamic_pointer_cast<ROM>(component);
102 throw std::logic_error(
"GraphicalROM requires a ROM component");
110 if (key !=
"binaryContents") {
119 const auto& slug = std::get<std::string>(value);
120 prepareGeometryChange();
140 .value_or(std::string());
150 const bool affectsConfiguredDocument =
156 || affectsConfiguredDocument)
174std::shared_ptr<const std::string>
182 const auto* document =
documents->find(path);
186 return std::make_shared<const std::string>(document->getContents());
bool printPortNames
Whether to print port names.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Handles double-clicks not consumed by a component-specific action.
bool openDocumentOnDoubleClick(QGraphicsSceneMouseEvent *event, const std::string &path)
Queues document navigation for a left double-click in normal mode.
void setPorts(const std::vector< PortPair > &busToPortInputs, const std::vector< PortPair > &busToPortOutputs) override
Sets ports and validates against component I/O.
void applyProperty(std::string_view key, const PropertyValue &value) override
Applies a component property while notifying Qt about possible geometry changes.
bool isEditable
Whether the component allows property editing.
GraphicalLogicComponent(ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
virtual void setComponent(const Component_ptr &component)
Sets the associated logical component.
Component_ptr associatedComponent
The logical component this graphical component represents.
const SILICON::project::DocumentStore * documents
GraphicalROM(QGraphicsItem *parent=nullptr)
void applyProperty(std::string_view key, const SILICON::core::PropertyValue &value) override
Applies a component property while notifying Qt about possible geometry changes.
void unsubscribeFromDocuments()
void setDocumentStore(const SILICON::project::DocumentStore *documents)
void refreshBinaryContents()
std::shared_ptr< const std::string > resolveBinaryContents(std::string_view slug) const
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
std::uint64_t documentListenerId
void setComponent(const SILICON::core::Component_ptr &component) override
Sets the associated logical component.
void subscribeToDocuments()
std::string currentSlug() const
static const QColor & getColor(theme::ColorToken token)
std::shared_ptr< Component > Component_ptr
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
std::string documentPathForSlug(const DocumentType type, const std::string_view slug)
bool isValidDocumentSlug(const std::string_view slug)
std::pair< QString, QPoint > PortPair
std::optional< std::string > path