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 width = 8;
|
||||||
constexpr float height = 14;
|
constexpr float height = 14;
|
||||||
baseRect_ = QRectF(-width/2.0f, -height/2.0f, width, height);
|
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)
|
void DisplayFlagButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
painter->setPen(Qt::NoPen);
|
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;
|
constexpr float roundRad = 3;
|
||||||
painter->drawRoundedRect(baseRect_, roundRad, roundRad);
|
painter->drawRoundedRect(baseRect_, roundRad, roundRad);
|
||||||
}
|
}
|
||||||
@@ -29,3 +57,17 @@ float DisplayFlagButton::getWidth()
|
|||||||
{
|
{
|
||||||
return baseRect_.width();
|
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
|
#pragma once
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
#include <QBrush>
|
||||||
|
|
||||||
class DisplayFlagButton
|
class DisplayFlagButton
|
||||||
: public QGraphicsItem
|
: public QGraphicsItem
|
||||||
@@ -7,11 +8,21 @@ class DisplayFlagButton
|
|||||||
public:
|
public:
|
||||||
DisplayFlagButton(QGraphicsItem *parent = nullptr);
|
DisplayFlagButton(QGraphicsItem *parent = nullptr);
|
||||||
float getWidth();
|
float getWidth();
|
||||||
|
void setEnabled(bool enabled);
|
||||||
private:
|
private:
|
||||||
QRectF baseRect_;
|
QRectF baseRect_;
|
||||||
QColor disabledColor_=QColor("#373737");
|
QColor disabledColor_=QColor("#373737");
|
||||||
QColor enabledColor_=QColor("#00BFFF");
|
QColor enabledColor_=QColor("#00BFFF");
|
||||||
|
QColor hoveredColor_=QColor("#666666");
|
||||||
|
QBrush disabledBrush_;
|
||||||
|
QBrush enabledBrush_;
|
||||||
|
QBrush hoveredBrush_;
|
||||||
|
bool hovered_=false;
|
||||||
|
bool enabled_=false;
|
||||||
protected:
|
protected:
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 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/Network.h"
|
||||||
|
#include "gui/network/DisplayFlagButton.h"
|
||||||
#include "gui/network/NodeEdgeGraphic.h"
|
#include "gui/network/NodeEdgeGraphic.h"
|
||||||
#include "gui/network/NetworkGraphicsView.h"
|
#include "gui/network/NetworkGraphicsView.h"
|
||||||
#include "gui/network/NetworkGraphicsScene.h"
|
#include "gui/network/NetworkGraphicsScene.h"
|
||||||
@@ -115,14 +116,22 @@ void Network::leftMousePressed(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
deleteEdge(clickedEdge);
|
deleteEdge(clickedEdge);
|
||||||
}
|
}
|
||||||
|
// socket logic
|
||||||
else if(clickedSocket)
|
else if(clickedSocket)
|
||||||
{
|
{
|
||||||
socketClicked(static_cast<SocketGraphic*>(clickedSocket), event);
|
socketClicked(static_cast<SocketGraphic*>(clickedSocket), event);
|
||||||
}
|
}
|
||||||
|
// floating edge
|
||||||
else if(floatingEdge_)
|
else if(floatingEdge_)
|
||||||
{
|
{
|
||||||
destroyFloatingEdge();
|
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()
|
NodeEdgeGraphic::~NodeEdgeGraphic()
|
||||||
{
|
{
|
||||||
std::cout << "edge destructor\n";
|
std::cout << "edge destructor\n";
|
||||||
scene()->removeItem(this);
|
cleanUp();
|
||||||
socket1_->removeEdge(this);
|
std::cout << "destructor finished\n";
|
||||||
socket2_->removeEdge(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeEdgeGraphic::updatePath()
|
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;
|
qreal padding_=40;
|
||||||
|
|
||||||
void updatePath();
|
void updatePath();
|
||||||
|
void cleanUp();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user