feat: add display flag
This commit is contained in:
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 <stdexcept>
|
||||
#include <string>
|
||||
#include "gui/network/DisplayFlagButton.h"
|
||||
#include "gui/network/SocketGraphic.h"
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
@@ -19,6 +20,14 @@ NodeGraphic::NodeGraphic(QGraphicsItem *parent)
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
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()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <QGraphicsItem>
|
||||
#include <QPainter>
|
||||
#include "gui/network/DisplayFlagButton.h"
|
||||
#include "gui/network/SocketGraphic.h"
|
||||
#include "gui/network/NodeEdgeGraphic.h"
|
||||
#include <iostream>
|
||||
@@ -29,6 +30,8 @@ public:
|
||||
|
||||
private:
|
||||
void initSockets();
|
||||
void initFlagButtons();
|
||||
|
||||
std::vector<SocketGraphic*> inputs_;
|
||||
std::vector<SocketGraphic*> outputs_;
|
||||
|
||||
@@ -41,6 +44,8 @@ private:
|
||||
int inputSocketCnt_=0;
|
||||
int outputSocketCnt_=0;
|
||||
|
||||
DisplayFlagButton* displayFlagButton_;
|
||||
|
||||
void updatePositions(QPointF pos);
|
||||
protected:
|
||||
// QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
||||
|
||||
Reference in New Issue
Block a user