feat: add display flag button click logic
This commit is contained in:
@@ -9,13 +9,41 @@ DisplayFlagButton::DisplayFlagButton(QGraphicsItem *parent)
|
||||
constexpr float width = 8;
|
||||
constexpr float height = 14;
|
||||
baseRect_ = QRectF(-width/2.0f, -height/2.0f, width, height);
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
disabledBrush_ = QBrush(disabledColor_);
|
||||
enabledBrush_ = QBrush(enabledColor_);
|
||||
hoveredBrush_ = QBrush(hoveredColor_);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DisplayFlagButton::setEnabled(bool enabled)
|
||||
{
|
||||
enabled_ = enabled;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void DisplayFlagButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QBrush(disabledColor_));
|
||||
// painter->setBrush(QBrush(disabledColor_));
|
||||
QBrush usedBrush;
|
||||
if(hovered_)
|
||||
{
|
||||
usedBrush = hoveredBrush_;
|
||||
}
|
||||
else if(enabled_)
|
||||
{
|
||||
usedBrush = enabledBrush_;
|
||||
}
|
||||
else
|
||||
{
|
||||
usedBrush = disabledColor_;
|
||||
}
|
||||
painter->setBrush(usedBrush);
|
||||
constexpr float roundRad = 3;
|
||||
painter->drawRoundedRect(baseRect_, roundRad, roundRad);
|
||||
}
|
||||
@@ -29,3 +57,17 @@ float DisplayFlagButton::getWidth()
|
||||
{
|
||||
return baseRect_.width();
|
||||
}
|
||||
|
||||
void DisplayFlagButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
hovered_ = true;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void DisplayFlagButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
hovered_ = false;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <QGraphicsItem>
|
||||
#include <QBrush>
|
||||
|
||||
class DisplayFlagButton
|
||||
: public QGraphicsItem
|
||||
@@ -7,11 +8,21 @@ class DisplayFlagButton
|
||||
public:
|
||||
DisplayFlagButton(QGraphicsItem *parent = nullptr);
|
||||
float getWidth();
|
||||
void setEnabled(bool enabled);
|
||||
private:
|
||||
QRectF baseRect_;
|
||||
QColor disabledColor_=QColor("#373737");
|
||||
QColor enabledColor_=QColor("#00BFFF");
|
||||
QColor hoveredColor_=QColor("#666666");
|
||||
QBrush disabledBrush_;
|
||||
QBrush enabledBrush_;
|
||||
QBrush hoveredBrush_;
|
||||
bool hovered_=false;
|
||||
bool enabled_=false;
|
||||
protected:
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "gui/network/Network.h"
|
||||
#include "gui/network/DisplayFlagButton.h"
|
||||
#include "gui/network/NodeEdgeGraphic.h"
|
||||
#include "gui/network/NetworkGraphicsView.h"
|
||||
#include "gui/network/NetworkGraphicsScene.h"
|
||||
@@ -115,14 +116,22 @@ void Network::leftMousePressed(QMouseEvent *event)
|
||||
{
|
||||
deleteEdge(clickedEdge);
|
||||
}
|
||||
// socket logic
|
||||
else if(clickedSocket)
|
||||
{
|
||||
socketClicked(static_cast<SocketGraphic*>(clickedSocket), event);
|
||||
}
|
||||
// floating edge
|
||||
else if(floatingEdge_)
|
||||
{
|
||||
destroyFloatingEdge();
|
||||
}
|
||||
// display flag
|
||||
else if(QGraphicsItem* clickedDisplayFlag = itemOfType<DisplayFlagButton>(clickedItems))
|
||||
{
|
||||
std::cout << "HERE\n";
|
||||
static_cast<DisplayFlagButton*>(clickedDisplayFlag)->setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,8 @@ NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2,
|
||||
NodeEdgeGraphic::~NodeEdgeGraphic()
|
||||
{
|
||||
std::cout << "edge destructor\n";
|
||||
scene()->removeItem(this);
|
||||
socket1_->removeEdge(this);
|
||||
socket2_->removeEdge(this);
|
||||
cleanUp();
|
||||
std::cout << "destructor finished\n";
|
||||
}
|
||||
|
||||
void NodeEdgeGraphic::updatePath()
|
||||
@@ -95,4 +94,9 @@ void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
||||
|
||||
}
|
||||
|
||||
|
||||
void NodeEdgeGraphic::cleanUp()
|
||||
{
|
||||
scene()->removeItem(this);
|
||||
socket1_->removeEdge(this);
|
||||
socket2_->removeEdge(this);
|
||||
}
|
||||
|
||||
@@ -33,5 +33,6 @@ private:
|
||||
qreal padding_=40;
|
||||
|
||||
void updatePath();
|
||||
void cleanUp();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user