Vuo  2.3.2
VuoEditorWindow.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "VuoEditorComposition.hh"
13 #include "VuoMainWindow.hh"
14 #include "VuoNode.hh"
15 #include "VuoNodeLibrary.hh"
16 #include "VuoPortClass.hh"
17 class VuoCompiler;
20 class VuoExampleMenu;
21 class VuoExportMovieDialog;
24 class VuoMetadataEditor;
25 class VuoPort;
26 class VuoProtocol;
27 class VuoPublishedPort;
29 class VuoRecentFileMenu;
30 class VuoRendererCable;
31 class VuoRendererComment;
33 class VuoRendererNode;
34 class VuoRendererPort;
36 class VuoSearchBox;
37 
38 namespace Ui
39 {
40  class VuoEditorWindow;
41 }
42 
47 {
48  Q_OBJECT
49 
50 public:
51  explicit VuoEditorWindow(QString documentIdentifier="", QString compositionPath="",
52  const string &compositionAsString="",
53  VuoNodeLibrary::nodeLibraryDisplayMode nodeLibraryDisplayMode=VuoNodeLibrary::displayByClass,
54  VuoNodeLibrary::nodeLibraryState nodeLibraryState=VuoNodeLibrary::nodeLibraryHidden,
55  VuoNodeLibrary *floater=NULL,
56  VuoProtocol *activeProtocol=NULL,
57  string nodeClassToHighlight="");
58  ~VuoEditorWindow();
59 
61  bool isScrollInProgress();
62  bool isItemDragInProgress();
63  double getLatestDragTime();
64  void highlightNodeClass(string nodeClass);
65  static bool containsLikelyVuoComposition(QString text);
67  static QString getNodeClassNameForDisplayNameAndCategory(QString compositionName, QString category, QString defaultCompositionName, QString defaultCategory);
71  void releaseSurrogateNodeLibrary(bool previousFloaterDestroyed);
72  QMenu * getFileMenu();
74  void setIncludeInRecentFileMenu(bool include);
76  QPointF getCursorScenePos();
78  QPointF getFittedScenePos(QPointF origPos, int leftMargin=50, int topMargin=50, int rightMargin=175, int bottomMargin=75);
80  void resetCompositionWithSnapshot(string snapshot);
81  void zoomOutToFit();
82 
83  static QString untitledComposition;
85 
86 public slots:
87  void updateLatestDragTime();
88  void updateUI();
89  void itemsMoved(set<VuoRendererNode *> nodes, set<VuoRendererComment *> comments, qreal dx, qreal dy, bool movedByDragging);
90  void commentResized(VuoRendererComment *comment, qreal dx, qreal dy);
91  void connectionCompleted(VuoRendererCable *cableInProgress, VuoRendererPort *targetPort, pair<VuoRendererCable *, VuoRendererCable *> cableArgs, VuoRendererNode *typecastNodeToDelete, pair<string, string> typeArgs, pair<VuoRendererPort *, VuoRendererPort *> portArgs);
92  void setTriggerThrottling(VuoPort *triggerPort, enum VuoPortClass::EventThrottling eventThrottling);
93  void adjustInputPortCountForNode(VuoRendererNode *node, int inputPortCountDelta, bool adjustmentRequestedByDragging);
94  void swapNodes(VuoRendererNode *node, string newNodeClass);
95  VuoRendererNode * specializePortNetwork(VuoRendererPort *port, string specializedTypeName);
96  VuoRendererNode * specializePortNetwork(VuoRendererPort *port, string specializedTypeName, bool encapsulateInMacro);
98  VuoRendererNode * unspecializePortNetwork(VuoRendererPort *port, bool encapsulateInMacro);
99  VuoRendererNode * respecializePortNetwork(VuoRendererPort *port, string specializedTypeName);
100  VuoRendererNode * respecializePortNetwork(VuoRendererPort *port, string specializedTypeName, bool encapsulateInMacro);
101  void tintSelectedItems(VuoNode::TintColor tintColor);
102  void internalExternalPortPairPublished(VuoPort *internalPort, VuoPublishedPort *externalPort, bool forceEventOnlyPublication, VuoPort *portToSpecialize=NULL, string specializedTypeName="", string typecastToInsert="", bool useUndoStackMacro=true);
103  void internalPortPublishedViaDropBox(VuoPort *port, bool forceEventOnlyPublication, bool useUndoStackMacro);
104  void internalPortPublished(VuoPort *port, bool forceEventOnlyPublication, string name="", bool merge=false, VuoPort *portToSpecialize=NULL, string specializedTypeName="", string typecastToInsert="", bool useUndoStackMacro=true);
106  void internalPortUnpublished(VuoPort *port);
107  void makeProtocolPortChanges(map<VuoPublishedPort *, string> publishedPortsToRename, set<VuoPublishedPort *> publishedPortsToRemove, vector<VuoPublishedPort *> publishedPortsToAdd, bool beginUndoStackMacro, bool endUndoStackMacro);
108  void componentsRemoved(QList<QGraphicsItem *> components, string commandDescription);
109  void componentsAdded(QList<QGraphicsItem *> components, VuoEditorComposition *target);
115  void conformToGlobalNodeLibraryVisibility(VuoNodeLibrary::nodeLibraryState visibility, VuoNodeLibrary *floater, bool previousFloaterDestroyed);
117  QAction *getRaiseDocumentAction() const;
118  QAction *getShowEventsAction() const;
119  QAction *getZoomOutAction() const;
120  QAction *getZoom11Action() const;
121  QAction *getZoomToFitAction() const;
122  QAction *getZoomInAction() const;
123  void on_zoomToFit_triggered();
124  void setAsActiveWindow();
131  void on_find_triggered();
132  void on_findNext_triggered();
134  void coalesceSnapshots(string oldCompositionSnapshot, string newCompositionSnapshot, VuoCompilerCompositionDiff *diffInfo=nullptr);
135  void coalesceInternalPortConstantsToSync(string portID);
136  void coalescePublishedPortConstantsToSync(string portID);
137  void coalesceNodesToUnlink(string nodeID);
138  void coalesceNodesToRelink(string nodeID);
139  void beginUndoStackMacro(QString commandName);
140  void endUndoStackMacro();
141  static string deriveBaseNodeClassNameFromDisplayName(string displayName);
142 
143 signals:
146 
147 protected:
148  bool event(QEvent *event) VuoWarnUnusedResult;
149  bool eventFilter(QObject *object, QEvent *event) VuoWarnUnusedResult;
150  void keyPressEvent(QKeyEvent *event);
151  void keyReleaseEvent(QKeyEvent *event);
152  void mouseMoveEvent(QMouseEvent *event);
153  void closeEvent(QCloseEvent *event);
154  void moveEvent(QMoveEvent *event);
155  void resizeEvent(QResizeEvent *event);
156 
157 private slots:
158  void showUpdateHelpDialog();
159 
160  void toggleNodeLibraryDockedState();
161  void on_zoom11_triggered();
162  void on_zoomIn_triggered();
163  void on_zoomOut_triggered();
164  void viewportFitReset();
165 
166  void on_saveComposition_triggered();
167  bool saveFile(const QString &file);
168  void changeActiveProtocol(void);
169  void updateActiveProtocolDisplay(void);
170  void evaluateCompositionForProtocolPromotion(void);
171  void on_saveCompositionAs_triggered();
172  void on_insertComment_triggered();
173  void on_insertSubcomposition_triggered();
174  string on_installSubcomposition_triggered();
175  void on_compositionInformation_triggered();
176  void editMetadata(int dialogResult);
177  void undoStackCleanStateChanged(bool clean);
178 
179  void duplicateSelectedCompositionComponentsByMenuItem();
180 
181  void showBuildActivityIndicator();
182  void hideBuildActivityIndicator(QString buildError);
183  void hideStopActivityIndicator();
184 
185  void on_openUserModulesFolder_triggered();
186  void on_openSystemModulesFolder_triggered();
187 
188  void on_showPublishedPorts_triggered();
189  void on_showHiddenCables_triggered();
190  void on_showEvents_triggered();
191  void closePublishedPortSidebars();
192  void conditionallyShowPublishedPortSidebars(bool visible);
193  void updatePublishedCableGeometry();
194  void updatePublishedPortOrder(vector<VuoPublishedPort *> ports, bool isInput);
195  void updateWindowForNewCableDrag();
196  void displayDockedNodeLibrary();
197 
198  void resetUndoStackMacros();
199  void updateSelectedComponentMenuItems();
200  void updateChangeNodeMenu();
201  void updateSceneRect();
202  void ensureSceneRectContainsRegion(const QList<QRectF> &region);
203  void updateRubberBandSelectionMode(QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint);
204 
205  void setPortConstant(VuoRendererPort *port, string value);
206  void showInputEditor(VuoRendererPort *port);
207  void showInputEditor(VuoRendererPort *port, bool forwardTabTraversal);
208  void showNodeTitleEditor(VuoRendererNode *node);
209  void showCommentEditor(VuoRendererComment *comment);
210  void showPublishedPortNameEditor(VuoRendererPublishedPort *port, bool useUndoStack);
211  void zoomToFitComment(VuoRendererComment *comment);
212  void createIsolatedExternalPublishedPort(string typeName, bool isInput);
213  void changePublishedPortName(VuoRendererPublishedPort *port, string newName, bool useUndoStack);
214  void changePublishedPortDetails(VuoRendererPublishedPort *port, json_object *newDetails);
215  void openEditableSourceForNode(VuoRendererNode *node);
216  void insertCommentAtPos(QPointF targetScenePos);
217  void insertSubcompositionAtPos(QPointF targetScenePos);
218  void refactorSelectedItems();
219  void restoreDefaultLeftDockedWidgetWidths();
220  void hideSelectedInternalCables();
221  void hideCables(set<VuoRendererCable *> cables);
222  void unhideCables(set<VuoRendererCable *> cables);
223  void updateGrid();
224  void updateCanvasOpacity();
225  void updateColor(bool isDark);
226  void coalescedUpdateRunningComposition();
227  void handlePendingProtocolComplianceReevaluationRequests();
228 
229 private:
230  friend class TestVuoEditor;
231  friend class TestEditorCommands;
232 
233  static const qreal viewportStepRate;
234  static const qreal viewportStepRateMultiplier;
235  static const qreal zoomRate;
236  static const qreal pastedComponentOffset;
237  static const qreal compositionMargin;
238  VuoCompiler *compiler;
239 
240  // The node library owned by this window, which will be the library docked into this window
241  // when in docked-library mode, and which may also at times function as the floating node library.
242  VuoNodeLibrary *ownedNodeLibrary;
243 
244  // The node library currently active in association with this window, which may be the library owned
245  // by this window or a floating library associated with a different window or the top-level application.
246  VuoNodeLibrary *nl;
247 
248  string coalescedOldCompositionSnapshot;
249  string coalescedNewCompositionSnapshot;
250  vector<string> coalescedInternalPortConstantsToSync;
251  vector<string> coalescedPublishedPortConstantsToSync;
252  vector<string> coalescedNodesToUnlink;
253  vector<string> coalescedNodesToRelink;
254  VuoCompilerCompositionDiff *coalescedDiffInfo;
255 
256  VuoCompositionMetadataPanel *metadataPanel;
257  VuoPublishedPortSidebar *inputPortSidebar;
258  VuoPublishedPortSidebar *outputPortSidebar;
259  VuoInputEditorManager *inputEditorManager;
260  VuoInputEditorSession *inputEditorSession;
261  QMenu *menuNewCompositionWithTemplate;
262  QMenu *menuProtocols;
263  VuoRecentFileMenu *menuOpenRecent;
264  VuoExampleMenu *menuOpenExample;
265  QMenu *contextMenuTints;
266  QMenu *menuChangeNode;
267  QAction *raiseDocumentAction;
268  QAction *undoAction;
269  QAction *redoAction;
270  QAction *quitAction;
271  QUndoStack *undoStack;
272  QUndoView *undoView;
273  VuoMetadataEditor *metadataEditor;
274  VuoSearchBox *searchBox;
275  bool zoomOutToFitOnNextShowEvent;
276  bool compositionUpgradedSinceLastSave;
277  bool canvasDragEnabled;
278  bool canvasDragInProgress;
279  bool scrollInProgress;
280  double timeOfLastScroll;
281  bool consumeNextMouseReleaseToCanvas;
282  bool lastLeftMousePressHadOptionModifier;
283  bool rubberBandSelectionInProgress;
284  QPointF cursorPosAtLastComponentCopy;
285  QPoint canvasDragMinCursorPos;
286  QPoint canvasDragMaxCursorPos;
287  QPoint lastCursorLocationDuringCanvasDrag;
288  bool previousDragMoveWasOverSidebar;
289  bool itemDragMacroInProgress;
290  vector<QGraphicsItem *> itemsBeingDragged;
291  VuoRendererComment *commentBeingResized;
292  int itemDragDx;
293  int itemDragDy;
294  double latestDragTime;
295  bool commentResizeMacroInProgress;
296  int commentResizeDx;
297  int commentResizeDy;
298  bool duplicationMacroInProgress;
299  VuoEditorWindowToolbar *toolbar;
300  bool isZoomedToFit;
301  bool doneInitializing;
302  bool containedPrepopulatedContent;
303  bool includeInRecentFileMenu;
304  bool publishedPortNearCursorPreviously;
305 
306  bool forwardingEventsToCanvas;
307 
308  Ui::VuoEditorWindow *ui;
309  VuoEditorComposition *composition;
310 
311  int nodeLibraryMinimumWidth;
312  int nodeLibraryMaximumWidth;
313 
314  bool protocolComplianceReevaluationPending;
315  bool ignoreItemMoveSignals;
316  bool closing;
317 
318  bool saveFile(const QString & savePath, QString & existingPath);
319  bool saveFileAs(const QString & savePath);
320  QString saveCompositionAs();
321  void acceptCloseEvent();
322  string installSubcomposition(string parentCompositionPath);
323  bool ensureThisParentCompositionSaved();
324  string sanitizeSubcompositionName(string name);
325  void updateToolbarElementUI();
326  void populateProtocolsMenu(QMenu *m);
327  void updateProtocolsMenu(QMenu *m);
328  void toggleActiveStatusForProtocol(VuoProtocol *protocol);
329  void setPublishedPortSidebarVisibility(bool visible);
330  void registerProtocolComplianceEvaluationRequest();
331  void setCompositionModified(bool modified);
332  void initializeNodeLibrary(VuoCompiler *nodeLibraryCompiler, VuoNodeLibrary::nodeLibraryDisplayMode nodeLibraryDisplayMode, VuoNodeLibrary::nodeLibraryState nodeLibraryState, VuoNodeLibrary *floater=NULL);
333  void pasteCompositionComponents();
334  void componentsPasted(QList<QGraphicsItem *> components, string commandDescription="Paste");
335  string getMaximumSubcompositionFromSelection(bool includePublishedPorts, bool includeHeader);
336  bool isStrandedAttachment(VuoRendererInputAttachment *attachment, QList<QGraphicsItem *> selectedItems);
337  void instantiateNewCompositionComponentsFromString(string compositionText);
338  QList<QGraphicsItem *> mergeCompositionComponentsFromString(string compositionText, bool pasteAtCursorLoc, bool pasteWithOffset, string commandDescription="Paste");
339  void transitionNodeLibraryConnections(VuoNodeLibrary *oldLibrary, VuoNodeLibrary *newLibrary);
340  QList<QGraphicsItem *> createAnyNecessaryMakeListComponents(VuoPort *port);
341  VuoRendererNode * specializeSinglePort(VuoRendererPort *port, string specializedTypeName);
342  VuoRendererNode * unspecializeSingleNode(VuoRendererNode *node, string revertedNodeClassName);
343  void enableCanvasDrag();
344  void disableCanvasDrag();
345  void initiateCanvasDrag();
346  void concludeCanvasDrag();
347  void updateRefireAction();
348  void updateCursor();
349  string generateCurrentDefaultCopyright();
350  bool confirmReplacingFile(string path);
351  bool arePublishedPortSidebarsVisible();
352 
353 #ifdef VUO_PRO
354 #include "pro/VuoEditorWindow_Pro.hh"
355 #endif
356 };