7#include <QGraphicsDropShadowEffect>
10#include <QGraphicsScene>
13#define TRIANGLEH (double)((double)PORT_LINE_WIDTH * (double)sqrt(3.0) ) / 2.0
20 this->
module = module;
21 this->moduleId = moduleId;
23 this->editingMode = editingMode;
24 this->manager = manager;
26 externalSelection =
false;
58 this->running = running;
62void ModuleItem::init()
66 setFlag(ItemIsSelectable,
true);
75 QFontMetrics fontMetric(
font);
76#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
77 int textWidth = fontMetric.horizontalAdvance(
itemName);
79 int textWidth = fontMetric.width(
itemName);
81 int mod = textWidth % 16;
84 prepareGeometryChange();
92 if(module->inputCount() > 0){
94 for(
int i=0;i<
module->inputCount();i++){
97 prepareGeometryChange();
103 if(module->inputCount() > 1){
104 int newH = (
module->inputCount() * 2 * PORT_LINE_WIDTH) ;
116 if(module->outputCount() > 0){
117 for(
int i=0;i<
module->outputCount();i++){
120 prepareGeometryChange();
123 if(module->outputCount() > 1){
124 int newH = (
module->outputCount() * 2 * PORT_LINE_WIDTH) ;
139 auto* effect =
new QGraphicsDropShadowEffect();
140 effect->setColor(QColor(80,80,80,80));
141 effect->setBlurRadius(5);
142 setGraphicsEffect(effect);
166 if(manager && editingMode){
178 return (
int)(QGraphicsItem::UserType + (int)
itemType);
180void ModuleItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
188 if(module->inputCount() <= 1){
189 partialH = (qreal)
mainRect.height()/(qreal)((qreal)
module->inputCount() + 1.0);
190 for(
int i=0; i <
module->inputCount(); i++){
191 painter->setPen(QPen(QBrush(QColor(Qt::black)),
BORDERWIDTH));
199 for(
int i=0; i <
module->inputCount(); i++){
200 painter->setPen(QPen(QBrush(QColor(Qt::black)),
BORDERWIDTH));
210 if(module->outputCount() <= 1){
211 partialH = (qreal)
mainRect.height()/(qreal)((qreal)
module->outputCount() + 1.0);
212 for(
int i=0; i <
module->outputCount(); i++){
214 painter->setPen(QPen(QBrush(QColor(Qt::black)),
BORDERWIDTH));
228 for(
int i=0; i <
module->outputCount(); i++){
231 painter->setPen(QPen(QBrush(QColor(Qt::black)),
BORDERWIDTH));
251 painter->setPen(QPen(QBrush(QColor(
"#BF0303")),
BORDERWIDTH ));
253 painter->setPen(QPen(QBrush(QColor(
"#00E400")),
BORDERWIDTH ));
257 painter->setPen(QPen(QBrush(QColor(
"#BF0303")),
BORDERWIDTH, Qt::DashLine ));
259 painter->setPen(QPen(QBrush(QColor(
"#00E400")),
BORDERWIDTH , Qt::DashLine));
263 path.addRoundedRect(
mainRect, 5.0, 5.0 );
265 painter->setBrush(QBrush(QColor(220,220,220)));
267 painter->setBrush(QBrush(QColor(Qt::white)));
271 painter->drawPath(path);
276 painter->setPen(QPen(QBrush(QColor(Qt::black)),1));
309 QGraphicsItem::mouseMoveEvent(event);
315 setZValue(zValue() + 10);
318 parentItem()->setSelected(
true);
320 QGraphicsItem::mousePressEvent(event);
325 QPointF startIngPoint;
327 return startIngPoint;
336 modBase.
points.push_back(p);
337 module->setModelBase(modBase);
350 setZValue(zValue() - 10);
353 parentItem()->setSelected(
true);
356 QGraphicsItem::mouseReleaseEvent(event);
361 externalSelection =
true;
362 setSelected(selected);
367 if (change == QGraphicsItem::ItemPositionChange) {
375 QPointF newPos = value.toPointF();
377 return closestPoint+=
offset;
380 if (change == QGraphicsItem::ItemSelectedHasChanged) {
382 if(!externalSelection){
385 externalSelection =
false;
408 qDebug() <<
"MODULE RELEASED";
471 setAcceptHoverEvents(
true);
472 setFlag(ItemSendsGeometryChanges,
true);
473 setFlag(ItemIsSelectable,
true);
494 this->parent = parent;
519 setAcceptHoverEvents(
true);
520 setFlag(ItemSendsGeometryChanges,
true);
521 setFlag(ItemIsSelectable,
true);
542 this->parent = parent;
561void PortItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
563 painter->setPen(QPen(QBrush(QColor(Qt::black)),
BORDERWIDTH/2));
565 switch (portAvailable) {
568 painter->setBrush(QBrush(QColor(
"#F74D4D")));
570 painter->setBrush(QBrush(QColor(
"#BF0303")));
575 painter->setBrush(QBrush(QColor(
"#1CE61C")));
577 painter->setBrush(QBrush(QColor(
"#008C00")));
582 painter->setBrush(QBrush(QColor(
"#8C8c8c")));
584 painter->setBrush(QBrush(QColor(
"#4B4B4B")));
594 painter->drawArc(
boundingR,-90 * 16, -180 * 16);
596 painter->drawPolygon(polygon);
620 qDebug() <<
"PORT PRESSED";
623 QGraphicsItem::mousePressEvent(event);
628 qDebug() <<
"PORT RELEASED";
630 if(!
moved && event->modifiers() == Qt::NoModifier && event->button() == Qt::LeftButton){
644 qDebug() <<
"PORT MOVED";
647 QGraphicsItem::mouseMoveEvent(event);
663 return {-triangleH/2, - 0};
672 return {triangleH/2, - 0};
723 portAvailable = available;
ItemSignalHandler * sigHandler
QPointF computeTopLeftGridPoint(const QPointF &pointP)
ItemSignalHandler * signalHandler()
void moduleSelected(QGraphicsItem *it)
void newConnectionRequested(QPointF, QGraphicsItem *it)
void newConnectionAdded(QPointF, QGraphicsItem *it)
ModuleItem(Module *module, int moduleId, bool nestedInApp=false, bool editingMode=false, Manager *manager=NULL, BuilderItem *parent=0)
void portReleased(PortItem *port, QGraphicsSceneMouseEvent *e)
void portMoved(PortItem *port, QGraphicsSceneMouseEvent *e)
int type() const override
void setModuleSelected(bool selected)
void updateGraphicModel()
QList< PortItem * > oPorts
QRectF boundingRect() const override
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void mousePressEvent(QGraphicsSceneMouseEvent *e) override
void portPressed(PortItem *port, QGraphicsSceneMouseEvent *e)
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override
QPointF connectionPoint() override
QList< PortItem * > iPorts
Module * getInnerModule()
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
QPointF connectionPoint() override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
InputData * getInputData()
QRectF boundingRect() const override
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
void setAvailable(PortStatus)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
int type() const override
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
OutputData * getOutputData()
std::vector< GyPoint > points
bool removeIModuleFromApplication(Application *application, const char *szTag)
Application * getApplication()
KnowledgeBase * getKnowledgeBase()