Maki
Formally verfied 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
16class NodeBase : public QGraphicsItem
17{
18public:
19 enum
20 {
21 Type = Types::BASE_NODE
22 };
23
32 NodeBase(const QString& id, const QString& nodeId, std::shared_ptr<NodeConfig> config, QGraphicsItem* parent);
33
37 virtual ~NodeBase();
38
44 QString id() const;
45
51 virtual int type() const override;
52
58 virtual QString nodeId() const;
59
65 virtual VoidResult start();
66
72 virtual std::shared_ptr<NodeConfig> config() const;
73
79 virtual QRectF boundingRect() const override;
80
86 virtual QRectF labelBoundingRect() const;
87
88 virtual QRectF nodeRect() const;
89
95 virtual QRectF scaledRect() const;
96
103 virtual QRectF drawingRect(const QRectF& input) const;
104
111 virtual QPainterPath nodeShape(const QRectF& bounds) const;
112
121 void paintNode(const QRectF& bounds, const QColor& background, const QPen& text, QPainter* painter);
122
128 virtual QPixmap nodePixmap() const;
129
135 virtual QString nodeIcon() const;
136
140 virtual void toggleLabelVisibility();
141
142protected:
143 std::shared_ptr<NodeConfig> mConfig;
144
145 QGraphicsPixmapItem* mPixmapItem = nullptr;
146 QString mIconPath = "";
147 QGraphicsSvgItem* mIconItem = nullptr;
148
154 virtual void setPixmap(const QPixmap& pixmap);
155
162 virtual void setIcon(const QString& path, const QColor& iconColor);
163
170 virtual void setLabel(const QString& name, qreal fontSize);
171
177 virtual void setLabelName(const QString& name);
178
185 virtual void setLabelSize(qreal fontSize, const QSizeF& boundingSize);
186
193 virtual void paintLabel(QPainter* painter, const QRectF& area, const QPen& pen) const;
194
200 virtual void paintPixmap(QPainter* painter) const;
201
202private:
203 const QString mId;
204 const QRectF mBounds;
205
206 QString mLabelText;
207 QFont mLabelFont = Fonts::Main;
208 bool mPaintLabel = true;
209 QRectF mScaledBounds;
210
216 qreal computeScaleFactor() const;
217};
static const QFont Main
Font constants for the application.
Definition app_configs.h:68
virtual void setLabelSize(qreal fontSize, const QSizeF &boundingSize)
Sets the font size and bounding size for the label.
Definition node_base.cpp:195
virtual void setIcon(const QString &path, const QColor &iconColor)
Sets the icon for the node.
Definition node_base.cpp:212
virtual QString nodeId() const
Retrieves the identifier of the node within its type.
Definition node_base.cpp:47
qreal computeScaleFactor() const
Scaled bounding rectangle of the node.
Definition node_base.cpp:248
virtual QPainterPath nodeShape(const QRectF &bounds) const
Returns the node shape as a QPainterPath.
Definition node_base.cpp:126
QString mLabelText
Bounding rectangle of the node.
Definition node_base.h:206
virtual void setPixmap(const QPixmap &pixmap)
Pointer to the SVG icon item.
Definition node_base.cpp:207
virtual QRectF drawingRect(const QRectF &input) const
Returns the drawing rectangle based on the input rectangle.
Definition node_base.cpp:87
virtual void setLabel(const QString &name, qreal fontSize)
Sets the label text and font size.
Definition node_base.cpp:181
virtual QRectF labelBoundingRect() const
Returns the bounding rectangle of the label.
Definition node_base.cpp:72
virtual QString nodeIcon() const
Retrieves the icon path of the node.
Definition node_base.cpp:275
virtual void toggleLabelVisibility()
Toggles the visibility of the label.
Definition node_base.cpp:201
QGraphicsSvgItem * mIconItem
Path to the icon image.
Definition node_base.h:147
virtual std::shared_ptr< NodeConfig > config() const
Retrieves the configuration settings for the node.
Definition node_base.cpp:57
NodeBase(const QString &id, const QString &nodeId, std::shared_ptr< NodeConfig > config, QGraphicsItem *parent)
Constructs a new NodeBase instance.
Definition node_base.cpp:19
QString id() const
Retrieves the unique identifier of the node.
Definition node_base.cpp:37
virtual QRectF scaledRect() const
Returns the scaled rectangle of the node.
Definition node_base.cpp:82
const QRectF mBounds
Unique identifier of the node.
Definition node_base.h:204
virtual QRectF boundingRect() const override
Returns the bounding rectangle of the node.
Definition node_base.cpp:62
virtual VoidResult start()
Starts the node.
Definition node_base.cpp:52
virtual void paintPixmap(QPainter *painter) const
Paints the pixmap using the provided painter.
Definition node_base.cpp:170
virtual void setLabelName(const QString &name)
Sets the label text.
Definition node_base.cpp:189
virtual void paintLabel(QPainter *painter, const QRectF &area, const QPen &pen) const
Paints the label using the provided painter.
Definition node_base.cpp:155
virtual QPixmap nodePixmap() const
Retrieves the pixmap of the node.
Definition node_base.cpp:261
virtual int type() const override
Returns the type of the node.
Definition node_base.cpp:42
QGraphicsPixmapItem * mPixmapItem
Configuration settings for the node.
Definition node_base.h:145
void paintNode(const QRectF &bounds, const QColor &background, const QPen &text, QPainter *painter)
Paints the node using the provided painter.
Definition node_base.cpp:92
QString mIconPath
Pointer to the pixmap item.
Definition node_base.h:146