Maki
Formally verified low-code orchestration
Loading...
Searching...
No Matches
node_base.h
1#pragma once
2
3#include <QFont>
4#include <QGraphicsItem>
5#include <QGraphicsSvgItem>
6#include <QString>
7
8#include "app_configs.h"
9#include "config.h"
10#include "ids.h"
11#include "result.h"
12#include "widgets/settings_manager.h"
13
17class NodeBase : public QGraphicsItem
18{
19public:
20 enum
21 {
22 Type = Types::BASE_NODE
23 };
24
33 explicit NodeBase(const QString& id, const QString& nodeId, std::shared_ptr<NodeConfig> config, QGraphicsItem* parent);
34
38 virtual ~NodeBase();
39
45 QString id() const;
46
52 virtual int type() const override;
53
59 virtual QString nodeId() const;
60
66 std::shared_ptr<NodeConfig> config() const;
67
73 virtual QRectF boundingRect() const override;
74
80 virtual QRectF labelBoundingRect() const;
81
82 virtual QRectF nodeRect() const;
83 virtual QRectF extraBoundingRect() const;
84
90 virtual QRectF scaledRect() const;
91
98 virtual QRectF drawingRect(const QRectF& input) const;
99
106 virtual QPainterPath nodeShape(const QRectF& bounds) const;
107
108 QPainterPath geometricBodyOutlinePath(const QRectF& drawingBounds) const;
109
118 void paintNode(const QRectF& bounds, const QColor& background, const QPen& text, QPainter* painter);
119 void paintNodeBody(const QRectF& bounds, QPainter* painter);
120
126 virtual QPixmap nodePixmap() const;
127
133 virtual QString nodeIcon() const;
134
138 virtual void toggleLabelVisibility(bool forceVisible = false);
139
143 virtual void settingsChanged(const AppearanceSettings& appearance);
144
145protected:
146 std::shared_ptr<NodeConfig> mConfig;
147
148 QString mIconPath = "";
149 QGraphicsSvgItem* mIconItem = nullptr;
150 QSvgRenderer* mRenderer;
151 mutable QPainterPath mSvgOutlineCachePath{};
152 mutable QString mSvgOutlineCacheKey{};
153 mutable QRectF mSvgOutlineCacheTarget{};
154
155 QRectF shapeSvgTargetRect(const QSvgRenderer* renderer, const QRectF& drawingBounds) const;
156 QPainterPath svgSilhouetteOutlinePath(QSvgRenderer* renderer, const QRectF& drawingBounds) const;
157
158 void paintSelectionOutline(QPainter* painter, const QPen& text, const QRectF& bounds) const;
159
160 QFont labelFont() const;
161 bool isLabelVisible() const;
162
169 virtual void setIcon(const QString& path, const QColor& iconColor);
170
177 virtual void setLabel(const QString& name, qreal fontSize);
178
184 virtual void setLabelName(const QString& name);
185
192 virtual void setLabelSize(qreal fontSize, const QSizeF& boundingSize);
193
200 virtual void paintLabel(QPainter* painter, const QRectF& area, const QPen& pen, bool elide = false) const;
201
205 virtual void initializeNodeSize();
206
207private:
208 const QString mId;
209 const QRectF mBounds;
210
211 QString mLabelText;
212 QFont mLabelFont = Fonts::Main;
213 bool mPaintLabel = true;
214 QRectF mScaledBounds;
215
221 qreal computeScaleFactor() const;
222};
static const QFont Main
Font constants for the application.
Definition app_configs.h:78
virtual void setLabelSize(qreal fontSize, const QSizeF &boundingSize)
Sets the font size and bounding size for the label.
Definition node_base.cpp:385
virtual void setIcon(const QString &path, const QColor &iconColor)
Sets the icon for the node.
Definition node_base.cpp:401
virtual QString nodeId() const
Retrieves the identifier of the node within its type.
Definition node_base.cpp:49
qreal computeScaleFactor() const
Scaled bounding rectangle of the node.
Definition node_base.cpp:437
virtual QPainterPath nodeShape(const QRectF &bounds) const
Returns the node shape as a QPainterPath.
Definition node_base.cpp:324
QString mLabelText
Bounding rectangle of the node.
Definition node_base.h:211
virtual QRectF drawingRect(const QRectF &input) const
Returns the drawing rectangle based on the input rectangle.
Definition node_base.cpp:93
virtual void setLabel(const QString &name, qreal fontSize)
Sets the label text and font size.
Definition node_base.cpp:371
virtual void settingsChanged(const AppearanceSettings &appearance)
Update the node on setting change.
Definition node_base.cpp:397
virtual QRectF labelBoundingRect() const
Returns the bounding rectangle of the label.
Definition node_base.cpp:79
virtual QString nodeIcon() const
Retrieves the icon path of the node.
Definition node_base.cpp:460
QGraphicsSvgItem * mIconItem
Path to the icon image.
Definition node_base.h:149
QSvgRenderer * mRenderer
Pointer to the SVG icon item.
Definition node_base.h:150
std::shared_ptr< NodeConfig > config() const
Retrieves the configuration settings for the node.
Definition node_base.cpp:54
NodeBase(const QString &id, const QString &nodeId, std::shared_ptr< NodeConfig > config, QGraphicsItem *parent)
Constructs a new NodeBase instance.
Definition node_base.cpp:16
QString id() const
Retrieves the unique identifier of the node.
Definition node_base.cpp:39
virtual QRectF scaledRect() const
Returns the scaled rectangle of the node.
Definition node_base.cpp:88
const QRectF mBounds
Unique identifier of the node.
Definition node_base.h:209
virtual QRectF boundingRect() const override
Returns the bounding rectangle of the node.
Definition node_base.cpp:59
virtual void toggleLabelVisibility(bool forceVisible=false)
Toggles the visibility of the label.
Definition node_base.cpp:391
virtual void setLabelName(const QString &name)
Sets the label text.
Definition node_base.cpp:379
virtual QPixmap nodePixmap() const
Retrieves the pixmap of the node.
Definition node_base.cpp:446
virtual int type() const override
Returns the type of the node.
Definition node_base.cpp:44
virtual void initializeNodeSize()
Called by children after setup to fix size.
Definition node_base.cpp:357
void paintNode(const QRectF &bounds, const QColor &background, const QPen &text, QPainter *painter)
Paints the node using the provided painter.
Definition node_base.cpp:129
virtual void paintLabel(QPainter *painter, const QRectF &area, const QPen &pen, bool elide=false) const
Paints the label using the provided painter.
Definition node_base.cpp:332
QString mIconPath
Configuration settings for the node.
Definition node_base.h:148
Holds appearance settings.
Definition settings_manager.h:50