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