98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
#ifndef DISPLAY_COMPONENT_H
|
|
#define DISPLAY_COMPONENT_H
|
|
|
|
#include <comdel/domain/instance.h>
|
|
#include <comdel/domain/wireinstance.h>
|
|
|
|
#include <QGraphicsItemGroup>
|
|
|
|
namespace display {
|
|
|
|
class Pin: public QGraphicsItemGroup
|
|
{
|
|
private:
|
|
domain::Pin pin;
|
|
public:
|
|
Pin(domain::Pin pin): pin(pin) {
|
|
pin.getDisplay().render(this);
|
|
}
|
|
};
|
|
|
|
class Component: public QGraphicsItemGroup
|
|
{
|
|
private:
|
|
std::shared_ptr<domain::ComponentInstance> instance;
|
|
public:
|
|
Component(const std::shared_ptr<domain::ComponentInstance>& instance): instance(instance) {
|
|
setFlag(ItemSendsGeometryChanges, true);
|
|
|
|
instance->component.getDisplay().render(this);
|
|
}
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
|
|
|
class Bus: public QGraphicsItemGroup
|
|
{
|
|
std::shared_ptr<domain::BusInstance> busInstance;
|
|
public:
|
|
Bus(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
|
instance->bus.getDisplay()->render(this);
|
|
}
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
};
|
|
|
|
class ComponentGroup: public QGraphicsItemGroup
|
|
{
|
|
private:
|
|
std::shared_ptr<domain::ComponentInstance> componentInstance;
|
|
|
|
public:
|
|
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance>& instance): componentInstance(instance) {
|
|
setFlag(ItemIsMovable, true);
|
|
setFlag(ItemSendsGeometryChanges, true);
|
|
|
|
setHandlesChildEvents(false);
|
|
|
|
addToGroup(new display::Component(instance));
|
|
|
|
for(auto &pin: instance->component.getPins()) {
|
|
addToGroup(new display::Pin(pin));
|
|
}
|
|
|
|
setPos(instance->position.first, instance->position.second);
|
|
}
|
|
|
|
protected:
|
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
|
|
|
};
|
|
|
|
class BusGroup: public QGraphicsItemGroup
|
|
{
|
|
private:
|
|
std::shared_ptr<domain::BusInstance> busInstance;
|
|
|
|
public:
|
|
explicit BusGroup(const std::shared_ptr<domain::BusInstance>& instance): busInstance(instance) {
|
|
setFlag(ItemIsMovable, true);
|
|
setFlag(ItemSendsGeometryChanges, true);
|
|
|
|
setHandlesChildEvents(false);
|
|
|
|
addToGroup(new display::Bus(instance));
|
|
|
|
setPos(instance->position.first, instance->position.second);
|
|
}
|
|
|
|
protected:
|
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
|
};
|
|
|
|
|
|
|
|
} // namespace display
|
|
|
|
#endif // DISPLAY_COMPONENT_H
|