feat: add display flag
This commit is contained in:
@@ -26,6 +26,7 @@ qt_add_executable(${AppExec}
|
|||||||
src/gui/network/SocketGraphic.cpp
|
src/gui/network/SocketGraphic.cpp
|
||||||
src/gui/network/NodeEdgeGraphic.cpp
|
src/gui/network/NodeEdgeGraphic.cpp
|
||||||
src/gui/network/FloatingEdgeGraphic.cpp
|
src/gui/network/FloatingEdgeGraphic.cpp
|
||||||
|
src/gui/network/DisplayFlagButton.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets)
|
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets)
|
||||||
|
|||||||
31
src/gui/network/DisplayFlagButton.cpp
Normal file
31
src/gui/network/DisplayFlagButton.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "gui/network/DisplayFlagButton.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <qgraphicsitem.h>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
|
||||||
|
DisplayFlagButton::DisplayFlagButton(QGraphicsItem *parent)
|
||||||
|
: QGraphicsItem(parent)
|
||||||
|
{
|
||||||
|
constexpr float width = 8;
|
||||||
|
constexpr float height = 14;
|
||||||
|
baseRect_ = QRectF(-width/2.0f, -height/2.0f, width, height);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayFlagButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
|
{
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(QBrush(disabledColor_));
|
||||||
|
constexpr float roundRad = 3;
|
||||||
|
painter->drawRoundedRect(baseRect_, roundRad, roundRad);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF DisplayFlagButton::boundingRect() const
|
||||||
|
{
|
||||||
|
return baseRect_;
|
||||||
|
}
|
||||||
|
|
||||||
|
float DisplayFlagButton::getWidth()
|
||||||
|
{
|
||||||
|
return baseRect_.width();
|
||||||
|
}
|
||||||
17
src/gui/network/DisplayFlagButton.h
Normal file
17
src/gui/network/DisplayFlagButton.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
|
class DisplayFlagButton
|
||||||
|
: public QGraphicsItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DisplayFlagButton(QGraphicsItem *parent = nullptr);
|
||||||
|
float getWidth();
|
||||||
|
private:
|
||||||
|
QRectF baseRect_;
|
||||||
|
QColor disabledColor_=QColor("#373737");
|
||||||
|
QColor enabledColor_=QColor("#00BFFF");
|
||||||
|
protected:
|
||||||
|
QRectF boundingRect() const override;
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "gui/network/DisplayFlagButton.h"
|
||||||
#include "gui/network/SocketGraphic.h"
|
#include "gui/network/SocketGraphic.h"
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
@@ -19,6 +20,14 @@ NodeGraphic::NodeGraphic(QGraphicsItem *parent)
|
|||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
|
|
||||||
initSockets();
|
initSockets();
|
||||||
|
initFlagButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeGraphic::initFlagButtons()
|
||||||
|
{
|
||||||
|
displayFlagButton_ = new DisplayFlagButton(this);
|
||||||
|
float padding = 4;
|
||||||
|
displayFlagButton_->setPos(QPointF(bodyRect_.right()-displayFlagButton_->getWidth()/2.0f-padding, bodyRect_.center().y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeGraphic::initSockets()
|
void NodeGraphic::initSockets()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include "gui/network/DisplayFlagButton.h"
|
||||||
#include "gui/network/SocketGraphic.h"
|
#include "gui/network/SocketGraphic.h"
|
||||||
#include "gui/network/NodeEdgeGraphic.h"
|
#include "gui/network/NodeEdgeGraphic.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -29,6 +30,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void initSockets();
|
void initSockets();
|
||||||
|
void initFlagButtons();
|
||||||
|
|
||||||
std::vector<SocketGraphic*> inputs_;
|
std::vector<SocketGraphic*> inputs_;
|
||||||
std::vector<SocketGraphic*> outputs_;
|
std::vector<SocketGraphic*> outputs_;
|
||||||
|
|
||||||
@@ -41,6 +44,8 @@ private:
|
|||||||
int inputSocketCnt_=0;
|
int inputSocketCnt_=0;
|
||||||
int outputSocketCnt_=0;
|
int outputSocketCnt_=0;
|
||||||
|
|
||||||
|
DisplayFlagButton* displayFlagButton_;
|
||||||
|
|
||||||
void updatePositions(QPointF pos);
|
void updatePositions(QPointF pos);
|
||||||
protected:
|
protected:
|
||||||
// QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
// QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user