1 #pragma once
2 
3 #ifndef FXSCHEMATICNODE_H
4 #define FXSCHEMATICNODE_H
5 
6 // TnzQt includes
7 #include "fxtypes.h"
8 
9 #include "schematicnode.h"
10 
11 // Qt includes
12 #include <QGraphicsItem>
13 #include <QList>
14 
15 //==============================================================
16 
17 //    Forward declarations
18 
19 class TFx;
20 class TOutputFx;
21 class TXsheetFx;
22 class TZeraryColumnFx;
23 class TPaletteColumnFx;
24 class TLevelColumnFx;
25 class TStageObjectId;
26 
27 class FxSchematicNode;
28 class FxSchematicScene;
29 class FxSchematicDock;
30 class FxSchematicColumnNode;
31 class FxSchematicPaletteNode;
32 class FxSchematicNormalFxNode;
33 class FxSchematicXSheetNode;
34 class FxSchematicOutputNode;
35 
36 //*****************************************************
37 //    FxColumnPainter
38 //*****************************************************
39 
40 class FxColumnPainter final : public QObject, public QGraphicsItem {
41   Q_OBJECT
42   Q_INTERFACES(QGraphicsItem)
43 
44   FxSchematicColumnNode *m_parent;
45   double m_width, m_height;
46   QString m_name;
47   int m_type;
48   bool m_isReference = false;
49 
50 public:
51   FxColumnPainter(FxSchematicColumnNode *parent, double width, double height,
52                   const QString &name);
53   virtual ~FxColumnPainter();
54 
55   QRectF boundingRect() const override;
56   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
57              QWidget *widget = 0) override;
setName(const QString & name)58   void setName(const QString &name) { m_name = name; }
59   void setIsReference(bool ref = true) { m_isReference = ref; }
60 
61 public slots:
62 
63   void onIconGenerated();
64 
65 protected:
66   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
67 };
68 
69 //*****************************************************
70 //    FxPalettePainter
71 //*****************************************************
72 
73 class FxPalettePainter final : public QObject, public QGraphicsItem {
74   Q_OBJECT
75   FxSchematicPaletteNode *m_parent;
76   double m_width, m_height;
77   QString m_name;
78 
79 public:
80   FxPalettePainter(FxSchematicPaletteNode *parent, double width, double height,
81                    const QString &name);
82   ~FxPalettePainter();
83 
84   QRectF boundingRect() const override;
85   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
86              QWidget *widget = 0) override;
setName(const QString & name)87   void setName(const QString &name) { m_name = name; }
88 
89 protected:
90   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
91 };
92 
93 //*****************************************************
94 //    FxPainter
95 //*****************************************************
96 
97 class FxPainter final : public QObject, public QGraphicsItem {
98   Q_OBJECT
99   Q_INTERFACES(QGraphicsItem)
100 
101   FxSchematicNode *m_parent;
102   double m_width, m_height;
103   QString m_name, m_label;
104   eFxType m_type;
105 
106   // to obtain the fx icons for zoom out view of the schematic
107   std::string m_fxType;
108 
109   void paint_small(QPainter *painter);
110 
111 public:
112   FxPainter(FxSchematicNode *parent, double width, double height,
113             const QString &name, eFxType type, std::string fxType);
114   ~FxPainter();
115 
116   QRectF boundingRect() const override;
117   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
118              QWidget *widget = 0) override;
setName(const QString & name)119   void setName(const QString &name) { m_name = name; }
120 
121 protected:
122   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
123 };
124 
125 //*****************************************************
126 //    FxXSheetPainter
127 //*****************************************************
128 
129 class FxXSheetPainter final : public QObject, public QGraphicsItem {
130   Q_OBJECT
131   Q_INTERFACES(QGraphicsItem)
132 
133   double m_width, m_height;
134 
135   FxSchematicXSheetNode *m_parent;
136 
137 public:
138   FxXSheetPainter(FxSchematicXSheetNode *parent, double width, double height);
139   ~FxXSheetPainter();
140 
141   QRectF boundingRect() const override;
142   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
143              QWidget *widget = 0) override;
144 
145 protected:
146   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
147 };
148 
149 //*****************************************************
150 //    FxOutputPainter
151 //*****************************************************
152 
153 class FxOutputPainter final : public QObject, public QGraphicsItem {
154   Q_OBJECT
155   Q_INTERFACES(QGraphicsItem)
156 
157   double m_width, m_height;
158   bool m_isActive;
159   FxSchematicOutputNode *m_parent;
160 
161 public:
162   FxOutputPainter(FxSchematicOutputNode *parent, double width, double height);
163   ~FxOutputPainter();
164 
165   QRectF boundingRect() const override;
166   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
167              QWidget *widget = 0) override;
168 
169 protected:
170   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
171 };
172 
173 //*****************************************************
174 //    FxSchematicLink
175 //*****************************************************
176 
177 class FxSchematicLink final : public SchematicLink {
178   Q_OBJECT
179 
180 public:
181   FxSchematicLink(QGraphicsItem *parent, QGraphicsScene *scene);
182   ~FxSchematicLink();
183 
184 protected:
185   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
186 };
187 
188 //*****************************************************
189 //    FxSchematicPort
190 //*****************************************************
191 
192 class FxSchematicPort final : public SchematicPort {
193   Q_OBJECT
194   TFx *m_ownerFx;
195   FxSchematicPort *m_currentTargetPort;
196   QList<SchematicLink *> m_hiddenLinks;
197   QList<SchematicLink *> m_ghostLinks;
198 
199 public:
200   FxSchematicPort(FxSchematicDock *parent, int type);
201   ~FxSchematicPort();
202 
203   QRectF boundingRect() const override;
204   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
205              QWidget *widget = 0) override;
206   bool linkTo(SchematicPort *port, bool checkOnly = false) override;
207   FxSchematicDock *getDock() const;
208   SchematicLink *makeLink(SchematicPort *port) override;
209 
210 protected:
211   void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
212   void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
213   void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
214   TFx *getOwnerFx() const;
215 
216 private:
217   void linkEffects(TFx *inputFx, TFx *fx, int inputId);
218   SchematicPort *searchPort(const QPointF &scenePos) override;
219 
220   //! Handles hiding of existing link and showing of ghost links for snapping
221   //! after creation link only for fx having
222   //! dynamic ports.
223   //! If \b secondIndex is -1 consider the last port in the groupedPorts of the
224   //! node.
225   void handleSnappedLinksOnDynamicPortFx(
226       const std::vector<TFxPort *> &groupedPorts, int targetIndex,
227       int startIndex = -1);
228 
229   void resetSnappedLinksOnDynamicPortFx();
230 
231   void hideSnappedLinks(SchematicPort *) override;
232   void showSnappedLinks(SchematicPort *) override;
233 };
234 
235 //*****************************************************
236 //    FxSchematicDock
237 //*****************************************************
238 
239 class FxSchematicDock final : public QGraphicsItem, public QObject {
240   QString m_name;
241   double m_width;
242   FxSchematicPort *m_port;
243 
244 public:
245   FxSchematicDock(FxSchematicNode *parent, const QString &string, double width,
246                   eFxSchematicPortType type);
247   ~FxSchematicDock();
248 
249   QRectF boundingRect() const override;
250   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
251              QWidget *widget = 0) override;
252   FxSchematicNode *getNode();
getPort()253   FxSchematicPort *getPort() { return m_port; }
254 };
255 
256 //*****************************************************
257 //    FxSchematicNode
258 //*****************************************************
259 
260 class FxSchematicNode : public SchematicNode {
261   Q_OBJECT
262 
263 protected:
264   enum eDropActionMode { eShift, eNone };
265 
266 protected:
267   QString m_name;  //!< Node's name (displayed on top, editable)
268   TFxP
269       m_fx;  //!< The node's associated fx (could be a wrapper to the actual fx)
270   TFxP m_actualFx;  //!< The actual node's associated fx
271 
272   FxSchematicNode *m_linkedNode;
273   QList<FxSchematicDock *> m_inDocks;
274   FxSchematicDock *m_outDock;
275   FxSchematicDock *m_linkDock;
276   SchematicName *m_nameItem;
277   eFxType m_type;
278   bool m_isCurrentFxLinked;
279 
280   bool m_isNormalIconView;
281 
282 protected:
283   //! If the fx has dynamic port groups, ensures that each group always has at
284   //! least one unlinked port
285   //! that users can attach to, while keeping the number of unlinked ports to
286   //! the minimum allowed by the
287   //! group's specifics.
288   virtual void checkDynamicInputPortSize() const;
289 
290   //! Adds a dynamic group port to the associated fx.
291   void addDynamicInputPort(int groupIndex) const;
292 
293   //! Removes the port with specified name from the associated fx. Returns false
294   //! (ie operation refused)
295   //! if the specified port does not exists, is connected, or is not in a
296   //! dynamic port group.
297   bool removeDynamicInputPort(const std::string &name) const;
298 
299   //! Moves the port group links to the front ports.
300   void shiftLinks() const;
301 
302   void updateOutputDockToolTips(const QString &name);
303 
304 public:
305   FxSchematicNode(FxSchematicScene *parent, TFx *fx, qreal width, qreal height,
306                   eFxType type);
307 
setWidth(const qreal & width)308   void setWidth(const qreal &width) { m_width = width; }
setHeight(const qreal & height)309   void setHeight(const qreal &height) { m_height = height; }
310   void setSchematicNodePos(const QPointF &pos) const override;
311 
getFx()312   TFx *getFx() const { return m_fx.getPointer(); }
isA(eFxType type)313   bool isA(eFxType type) { return m_type == type; }
314 
getInputPortCount()315   int getInputPortCount() { return m_inDocks.size(); }
316   int getInputDockId(FxSchematicDock *dock);
317 
getInputPort(int i)318   FxSchematicPort *getInputPort(int i) {
319     return m_inDocks[i] ? m_inDocks[i]->getPort() : 0;
320   }
getOutputPort()321   FxSchematicPort *getOutputPort() {
322     return m_outDock ? m_outDock->getPort() : 0;
323   }
getLinkPort()324   FxSchematicPort *getLinkPort() {
325     return m_linkDock ? m_linkDock->getPort() : 0;
326   }
327 
isNameEditing()328   bool isNameEditing() { return m_nameItem->isVisible(); }
329   void onClicked() override;
isCurrentFxLinked(SchematicNode * comingNode)330   bool isCurrentFxLinked(SchematicNode *comingNode) {
331     return m_isCurrentFxLinked;
332   }
333   void setIsCurrentFxLinked(bool value, FxSchematicNode *comingNode);
334   void setPosition(const QPointF &newPos) override;
335 
336   void updatePortsPosition();
337 
isOpened()338   virtual bool isOpened() { return true; }
339   virtual bool isEnabled() const;
340   virtual bool isCached() const;
resize(bool maximizeNode)341   virtual void resize(bool maximizeNode) {}
342 
toggleNormalIconView()343   void toggleNormalIconView() { m_isNormalIconView = !m_isNormalIconView; }
isNormalIconView()344   bool isNormalIconView() { return m_isNormalIconView; }
345 signals:
346 
347   void switchCurrentFx(TFx *fx);
348   void currentColumnChanged(int index);
349 
350   void fxNodeDoubleClicked();
351 };
352 
353 //*****************************************************
354 //    FxSchematicOutputNode
355 //*****************************************************
356 
357 class FxSchematicOutputNode final : public FxSchematicNode {
358   Q_OBJECT
359 
360   FxOutputPainter *m_outputPainter;
361 
362 public:
363   FxSchematicOutputNode(FxSchematicScene *scene, TOutputFx *fx);
364   ~FxSchematicOutputNode();
365 
366   QRectF boundingRect() const override;
367   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
368              QWidget *widget = 0) override;
369 
370 protected:
371   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
372   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
373 };
374 
375 //*****************************************************
376 //    FxSchematicXSheetNode
377 //*****************************************************
378 
379 class FxSchematicXSheetNode final : public FxSchematicNode {
380   Q_OBJECT
381 
382   FxXSheetPainter *m_xsheetPainter;
383 
384 public:
385   FxSchematicXSheetNode(FxSchematicScene *scene, TXsheetFx *fx);
386   ~FxSchematicXSheetNode();
387 
388   QRectF boundingRect() const override;
389   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
390              QWidget *widget = 0) override;
391 
392 protected:
393   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
394   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
395 };
396 
397 //*****************************************************
398 //    FxSchematicNormalFxNode
399 //*****************************************************
400 
401 class FxSchematicNormalFxNode final : public FxSchematicNode {
402   Q_OBJECT
403 
404   FxPainter *m_painter;
405   SchematicToggle *m_renderToggle;
406 
407 public:
408   FxSchematicNormalFxNode(FxSchematicScene *scene, TFx *fx);
409   ~FxSchematicNormalFxNode();
410 
411   QRectF boundingRect() const override;
412   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
413              QWidget *widget = 0) override;
414 
415   void resize(bool maximizeNode) override;
416 
417 protected:
418   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
419   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
420 
421 protected slots:
422 
423   void onNameChanged();
424   void onRenderToggleClicked(bool);
425 };
426 
427 //*****************************************************
428 //    FxSchematicZeraryNode
429 //*****************************************************
430 
431 class FxSchematicZeraryNode final : public FxSchematicNode {
432   Q_OBJECT
433 
434   FxPainter *m_painter;
435   int m_columnIndex;
436   SchematicToggle *m_renderToggle, *m_cameraStandToggle;
437 
438 public:
439   FxSchematicZeraryNode(FxSchematicScene *scene, TZeraryColumnFx *fx);
440   ~FxSchematicZeraryNode();
441 
442   QRectF boundingRect() const override;
443   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
444              QWidget *widget = 0) override;
445 
446   void resize(bool maximizeNode) override;
447 
getColumnIndex()448   int getColumnIndex() { return m_columnIndex; }
449   bool isCached() const override;
450 
451 protected:
452   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
453   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
454 
455 protected slots:
456 
457   void onRenderToggleClicked(bool);
458   void onCameraStandToggleClicked(int);
459   void onNameChanged();
460 };
461 
462 //*****************************************************
463 //    FxSchematicColumnNode
464 //*****************************************************
465 
466 class FxSchematicColumnNode final : public FxSchematicNode {
467   Q_OBJECT
468 
469   SchematicThumbnailToggle *m_resizeItem;
470   SchematicToggle *m_renderToggle, *m_cameraStandToggle;
471   FxColumnPainter *m_columnPainter;
472   int m_columnIndex;
473   bool m_isOpened;
474 
475 public:
476   FxSchematicColumnNode(FxSchematicScene *scene, TLevelColumnFx *fx);
477   ~FxSchematicColumnNode();
478 
479   QRectF boundingRect() const override;
480   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
481              QWidget *widget = 0) override;
482   QPixmap getPixmap();
isOpened()483   bool isOpened() override { return m_isOpened; }
484 
485   void getLevelTypeAndName(int &, QString &);
486 
487   void resize(bool maximizeNode) override;
getColumnIndex()488   int getColumnIndex() { return m_columnIndex; }
489 
490 protected:
491   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
492   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
493 
494 private:
495   void renameObject(const TStageObjectId &id, std::string name);
496 
497 protected slots:
498 
499   void onRenderToggleClicked(bool);
500   void onCameraStandToggleClicked(int);
501   void onChangedSize(bool);
502   void onNameChanged();
503 };
504 
505 //*****************************************************
506 //    FxSchematicPaletteNode
507 //*****************************************************
508 
509 class FxSchematicPaletteNode final : public FxSchematicNode {
510   Q_OBJECT
511 
512   SchematicToggle *m_renderToggle;
513   FxPalettePainter *m_palettePainter;
514   int m_columnIndex;
515 
516 public:
517   FxSchematicPaletteNode(FxSchematicScene *scene, TPaletteColumnFx *fx);
518   ~FxSchematicPaletteNode();
519 
520   QRectF boundingRect() const override;
521   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
522              QWidget *widget = 0) override;
523   QPixmap getPixmap();
isOpened()524   bool isOpened() override { return false; }
getColumnIndex()525   int getColumnIndex() { return m_columnIndex; }
526 
527   QString getPaletteName();
528 
529 protected:
530   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
531   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
532 
533 protected slots:
534 
535   void onRenderToggleClicked(bool);
536   void onNameChanged();
537 
538 private:
539   void renameObject(const TStageObjectId &id, std::string name);
540 };
541 
542 //*****************************************************
543 //    FxGroupNode
544 //*****************************************************
545 
546 class FxGroupNode final : public FxSchematicNode {
547   Q_OBJECT
548 
549   QList<TFxP> m_groupedFxs;
550   QList<TFxP> m_roots;
551   int m_groupId;
552   FxPainter *m_painter;
553   SchematicToggle *m_renderToggle;
554   bool m_isOpened;
555 
556 public:
557   FxGroupNode(FxSchematicScene *scene, const QList<TFxP> &groupedFx,
558               const QList<TFxP> &roots, int groupId,
559               const std::wstring &groupName);
560   ~FxGroupNode();
561 
562   QRectF boundingRect() const override;
563   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
564              QWidget *widget = 0) override;
565 
getOutputPort()566   FxSchematicPort *getOutputPort() const {
567     return m_outDock ? m_outDock->getPort() : 0;
568   }
isNameEditing()569   bool isNameEditing() const { return m_nameItem->isVisible(); }
getRootFxs()570   QList<TFxP> getRootFxs() const { return m_roots; }
getRootCount()571   int getRootCount() { return m_roots.size(); }
getFxCount()572   int getFxCount() const { return m_groupedFxs.size(); }
getFx(int i)573   TFx *getFx(int i) const {
574     return 0 <= i && i < m_groupedFxs.size() ? m_groupedFxs[i].getPointer() : 0;
575   }
576 
getGroupedFxs()577   QList<TFxP> getGroupedFxs() const { return m_groupedFxs; }
578   void updateFxsDagPosition(const TPointD &pos) const;
isOpened()579   bool isOpened() override { return m_isOpened; }
580   void resize(bool maximized) override;
581   bool contains(TFxP fx);
582   // returns the number of ports that take the group in input... it consider
583   // also the node xsheet
584   int getOutputConnectionsCount() const;
585   bool isEnabled() const override;
586   bool isCached() const override;
587 
588 protected:
589   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *me) override;
590   void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
591   QPointF computePos() const;
592 
593 protected slots:
594 
595   void onNameChanged();
596   void onRenderToggleClicked(bool);
597 };
598 
599 #endif  // FXSCHEMATICNODE_H
600