1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef NODEVIEW_H
5#define NODEVIEW_H
6
7#include <QtQuick/qquickitem.h>
8#include <QList>
9#include "nodesmodel.h"
10#include "arrowsmodel.h"
11
12class EffectManager;
13
14class NodeView : public QQuickItem
15{
16 Q_OBJECT
17 Q_PROPERTY(NodesModel *nodesModel READ nodesModel NOTIFY nodesModelChanged)
18 Q_PROPERTY(ArrowsModel *arrowsModel READ arrowsModel NOTIFY arrowsModelChanged)
19 Q_PROPERTY(QPointF activeArrowStartPoint READ activeArrowStartPoint NOTIFY activeArrowStartPointChanged)
20 Q_PROPERTY(QPointF activeArrowEndPoint READ activeArrowEndPoint NOTIFY activeArrowEndPointChanged)
21 Q_PROPERTY(bool activeArrowEnabled READ activeArrowEnabled NOTIFY activeArrowEnabledChanged)
22 Q_PROPERTY(bool nodeGraphComplete READ nodeGraphComplete NOTIFY nodeGraphCompleteChanged)
23 Q_PROPERTY(bool effectNodeSelected READ effectNodeSelected NOTIFY effectNodeSelectedChanged)
24 Q_PROPERTY(bool mainNodeSelected READ mainNodeSelected NOTIFY mainNodeSelectedChanged)
25 Q_PROPERTY(int selectedNodeId READ selectedNodeId NOTIFY selectedNodeIdChanged)
26 Q_PROPERTY(QString selectedNodeName READ selectedNodeName WRITE setSelectedNodeName NOTIFY selectedNodeNameChanged)
27 Q_PROPERTY(QString selectedNodeDescription READ selectedNodeDescription WRITE setSelectedNodeDescription NOTIFY selectedNodeDescriptionChanged)
28 Q_PROPERTY(QString selectedNodeFragmentCode READ selectedNodeFragmentCode WRITE setSelectedNodeFragmentCode NOTIFY selectedNodeFragmentCodeChanged)
29 Q_PROPERTY(QString selectedNodeVertexCode READ selectedNodeVertexCode WRITE setSelectedNodeVertexCode NOTIFY selectedNodeVertexCodeChanged)
30 Q_PROPERTY(QString selectedNodeQmlCode READ selectedNodeQmlCode WRITE setSelectedNodeQmlCode NOTIFY selectedNodeQmlCodeChanged)
31 Q_PROPERTY(QStringList codeSelectorModel READ codeSelectorModel NOTIFY codeSelectorModelChanged)
32 Q_PROPERTY(int codeSelectorIndex READ codeSelectorIndex NOTIFY codeSelectorIndexChanged)
33 QML_NAMED_ELEMENT(NodeViewItem)
34public:
35 explicit NodeView(QQuickItem *parent = nullptr);
36
37 NodesModel *nodesModel() const;
38 ArrowsModel *arrowsModel() const;
39
40 QPointF activeArrowStartPoint() const;
41
42 QPointF activeArrowEndPoint() const;
43
44 bool activeArrowEnabled() const;
45
46 QString selectedNodeName() const;
47 void setSelectedNodeName(const QString &name);
48 QString selectedNodeDescription() const;
49 void setSelectedNodeDescription(const QString &description);
50 QString selectedNodeFragmentCode() const;
51 void setSelectedNodeFragmentCode(const QString &newSelectedNodeFragmentCode);
52 QString selectedNodeVertexCode() const;
53 void setSelectedNodeVertexCode(const QString &newSelectedNodeVertexCode);
54 QString selectedNodeQmlCode() const;
55 void setSelectedNodeQmlCode(const QString &newSelectedNodeQmlCode);
56
57 bool nodeGraphComplete() const;
58 bool effectNodeSelected() const;
59 bool mainNodeSelected() const;
60 int selectedNodeId() const;
61 QStringList codeSelectorModel() const;
62 int codeSelectorIndex() const;
63
64 void setSelectedNode(NodesModel::Node *selectedNode);
65 void updateCodeSelectorModel();
66
67public Q_SLOTS:
68 void updateActiveNodesList();
69 void deleteSelectedNodes();
70 void layoutNodes(bool distribute);
71 void selectSingleNode(int nodeId);
72 void selectMainNode();
73 int getNodeIdWithName(const QString &name);
74 void toggleNodeDisabled();
75
76signals:
77 void nodesModelChanged();
78 void arrowsModelChanged();
79
80 void activeArrowStartPointChanged();
81
82 void activeArrowEndPointChanged();
83
84 void activeArrowEnabledChanged();
85 void activeNodesListChanged();
86
87 void selectedNodeNameChanged();
88 void selectedNodeDescriptionChanged();
89 void selectedNodeFragmentCodeChanged();
90 void selectedNodeVertexCodeChanged();
91 void selectedNodeQmlCodeChanged();
92
93 void nodeGraphCompleteChanged();
94 void effectNodeSelectedChanged();
95 void mainNodeSelectedChanged();
96 void selectedNodeIdChanged();
97
98 void codeSelectorModelChanged();
99 void codeSelectorIndexChanged();
100
101 // Other than changed singnals
102 void doubleClickNode();
103 void openDeleteNodeDialog();
104 void openNodeContextMenu();
105
106
107protected:
108 void mouseMoveEvent(QMouseEvent *event) override;
109 void mousePressEvent(QMouseEvent *event) override;
110 void mouseReleaseEvent(QMouseEvent *event) override;
111 void mouseDoubleClickEvent(QMouseEvent *event) override;
112 void hoverMoveEvent(QHoverEvent *event) override;
113 void keyPressEvent(QKeyEvent *event) override;
114 void keyReleaseEvent(QKeyEvent *event) override;
115
116private:
117 friend class EffectManager;
118
119 void updateArrowsPositions();
120 void updateCodeSelectorIndex();
121 int getUniqueNodeId();
122 void initializeNode(NodesModel::Node &node);
123 void initializeNodeSize(NodesModel::Node &node);
124 QString getUniqueNodeName(const QString &origName, int counter = 0);
125
126 bool m_mousePressed = false;
127 NodesModel *m_nodesModel = nullptr;
128 ArrowsModel *m_arrowsModel = nullptr;
129 QPointF m_pressPosition;
130 QPointF m_activeArrowStartPoint;
131 QPointF m_activeArrowEndPoint;
132 bool m_activeArrowEnabled;
133 ArrowsModel::Arrow m_activeArrow;
134 bool m_nodeGraphComplete = false;
135 bool m_effectNodeSelected = false;
136 bool m_mainNodeSelected = false;
137 int m_selectedNodeId = -1;
138 bool m_initialized = false;
139 EffectManager *m_effectManager = nullptr;
140 QList<NodesModel::Node *> m_activeNodesList;
141 // Ids of nodes currently connected and not disabled
142 QList<int> m_activeNodesIds;
143 QStringList m_codeSelectorModel;
144 int m_codeSelectorIndex = 0;
145};
146
147#endif // NODEVIEW_H
148

source code of qtquickeffectmaker/tools/qqem/nodeview.h