2022-04-07 22:21:23 +00:00
|
|
|
#include "component_display.h"
|
2022-05-15 14:13:29 +00:00
|
|
|
#include "attribute_dialog.h"
|
|
|
|
#include "name_dialog.h"
|
2022-04-07 22:21:23 +00:00
|
|
|
|
2022-04-10 15:24:15 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
2022-04-20 19:50:39 +00:00
|
|
|
#include <QGraphicsScene>
|
2022-04-10 15:24:15 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-04-07 22:21:23 +00:00
|
|
|
namespace display {
|
|
|
|
|
2022-05-08 22:51:47 +00:00
|
|
|
void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
|
|
QMenu menu;
|
|
|
|
menu.addAction("Izmjeni ime", [this](){});
|
|
|
|
menu.addSeparator();
|
2022-05-15 14:13:29 +00:00
|
|
|
for(int i=0; i<this->instance->attributes.size(); i++) {
|
|
|
|
auto* attr = &this->instance->attributes[i];
|
|
|
|
bool enabled = attr->attribute.getPopup().has_value();
|
|
|
|
|
|
|
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr->name),
|
|
|
|
[attr]() {
|
|
|
|
auto dialog = new AttributeDialog(attr);
|
|
|
|
dialog->exec();
|
|
|
|
});
|
2022-05-08 22:51:47 +00:00
|
|
|
action->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
menu.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Bus::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
|
|
QMenu menu;
|
|
|
|
menu.addAction("Izmjeni ime", [this](){});
|
|
|
|
menu.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-04-10 15:24:15 +00:00
|
|
|
ComponentWrapper *ComponentWrapper::ofWire(domain::WireInstance *wire) {
|
|
|
|
auto component = new ComponentWrapper();
|
2022-04-07 22:21:23 +00:00
|
|
|
component->wireInstance = wire;
|
|
|
|
component->redraw();
|
|
|
|
return component;
|
2022-04-08 18:17:58 +00:00
|
|
|
}
|
2022-04-10 15:24:15 +00:00
|
|
|
ComponentWrapper *ComponentWrapper::ofComponent(domain::ComponentInstance *instance) {
|
|
|
|
auto component = new ComponentWrapper();
|
2022-04-07 22:21:23 +00:00
|
|
|
component->componentInstance = instance;
|
2022-04-10 15:24:15 +00:00
|
|
|
component->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
component->componentItem = new ComponentItem(instance, component);
|
|
|
|
|
|
|
|
for(auto& pin: instance->component.getPins()) {
|
|
|
|
component->pinItems.push_back(new PinItem(pin, component));
|
|
|
|
}
|
|
|
|
|
2022-04-07 22:21:23 +00:00
|
|
|
component->redraw();
|
|
|
|
return component;
|
2022-04-08 18:17:58 +00:00
|
|
|
}
|
2022-04-10 15:24:15 +00:00
|
|
|
ComponentWrapper *ComponentWrapper::ofBus(domain::BusInstance *instance) {
|
|
|
|
auto component = new ComponentWrapper();
|
2022-04-07 22:21:23 +00:00
|
|
|
component->busInstance = instance;
|
2022-04-10 15:24:15 +00:00
|
|
|
component->setFlag(QGraphicsItem::ItemIsMovable, true);
|
2022-04-07 22:21:23 +00:00
|
|
|
component->redraw();
|
|
|
|
return component;
|
2022-04-08 18:17:58 +00:00
|
|
|
}
|
2022-04-20 19:50:39 +00:00
|
|
|
void ComponentWrapper::clear() {
|
|
|
|
for(auto item: childItems()) {
|
|
|
|
this->removeFromGroup(item);
|
|
|
|
item->scene()->removeItem(item);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
if(componentInstance) {
|
|
|
|
componentItem->clear();
|
|
|
|
for(auto pinItem: pinItems) {
|
|
|
|
pinItem->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 15:24:15 +00:00
|
|
|
void ComponentWrapper::redraw() {
|
2022-04-20 19:50:39 +00:00
|
|
|
|
2022-04-07 22:21:23 +00:00
|
|
|
if(componentInstance) {
|
2022-04-20 19:50:39 +00:00
|
|
|
addToGroup(componentItem);
|
2022-04-10 15:24:15 +00:00
|
|
|
componentItem->redraw();
|
|
|
|
for(auto pinItem: pinItems) {
|
2022-04-20 19:50:39 +00:00
|
|
|
addToGroup(pinItem);
|
2022-04-10 15:24:15 +00:00
|
|
|
pinItem->redraw();
|
2022-04-07 22:21:23 +00:00
|
|
|
}
|
|
|
|
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(componentInstance->name)));
|
|
|
|
}
|
|
|
|
if(busInstance && busInstance->bus.getDisplay()) {
|
|
|
|
busInstance->bus.getDisplay()->render(this);
|
|
|
|
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(busInstance->name)));
|
|
|
|
}
|
|
|
|
if(wireInstance) {
|
|
|
|
wireInstance->display.render(this);
|
|
|
|
this->addToGroup(new QGraphicsSimpleTextItem(QString::fromStdString(wireInstance->name)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 15:24:15 +00:00
|
|
|
ComponentItem::ComponentItem(domain::ComponentInstance *instance, QGraphicsItem *parent): componentInstance(instance) {
|
|
|
|
setParentItem(parent);
|
|
|
|
redraw();
|
|
|
|
setToolTip(QString::fromStdString(this->componentInstance->component.getTooltip()));
|
|
|
|
}
|
|
|
|
void ComponentItem::redraw() {
|
|
|
|
componentInstance->component.getDisplay().render(this);
|
|
|
|
}
|
2022-04-20 19:50:39 +00:00
|
|
|
void ComponentItem::clear() {
|
|
|
|
for(auto item: childItems()) {
|
|
|
|
this->removeFromGroup(item);
|
|
|
|
item->scene()->removeItem(item);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 15:24:15 +00:00
|
|
|
|
|
|
|
void ComponentItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
|
|
|
|
QMenu menu;
|
2022-04-20 19:50:39 +00:00
|
|
|
auto instance = this->componentInstance;
|
|
|
|
menu.addAction("Izmjeni ime", [instance, this](){
|
|
|
|
DialogManager::updateName(instance);
|
|
|
|
auto *wrapper = static_cast<ComponentWrapper*>(this->parentItem());
|
|
|
|
wrapper->clear();
|
|
|
|
wrapper->redraw();
|
|
|
|
});
|
2022-04-10 15:24:15 +00:00
|
|
|
menu.addSeparator();
|
|
|
|
for(auto attr: componentInstance->attributes) {
|
2022-05-07 12:19:43 +00:00
|
|
|
bool enabled = attr.attribute.getPopup().has_value();
|
2022-04-19 06:16:41 +00:00
|
|
|
|
2022-05-07 12:19:43 +00:00
|
|
|
auto action = menu.addAction(QString::fromStdString("Izmjeni " + attr.name),
|
|
|
|
[&attr, this]() {
|
|
|
|
DialogManager::updateAttribute(&attr);
|
2022-04-20 19:50:39 +00:00
|
|
|
|
|
|
|
this->redraw();
|
|
|
|
});
|
2022-04-19 06:16:41 +00:00
|
|
|
action->setEnabled(enabled);
|
2022-04-10 15:24:15 +00:00
|
|
|
}
|
|
|
|
menu.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
PinItem::PinItem(domain::Pin pin, QGraphicsItem *parent): pin(pin) {
|
|
|
|
setParentItem(parent);
|
|
|
|
redraw();
|
|
|
|
setToolTip(QString::fromStdString(pin.getTooltip()));
|
|
|
|
}
|
|
|
|
void PinItem::redraw() {
|
|
|
|
pin.getDisplay().render(this);
|
|
|
|
}
|
2022-04-20 19:50:39 +00:00
|
|
|
void PinItem::clear() {
|
|
|
|
for(auto item: childItems()) {
|
|
|
|
this->removeFromGroup(item);
|
|
|
|
item->scene()->removeItem(item);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2022-05-08 22:51:47 +00:00
|
|
|
*/
|
2022-04-07 22:21:23 +00:00
|
|
|
} // namespace display
|