Vuo  2.1.0
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 ensureSceneRectContainsRegion(const QList<QRectF> &region);
201  void updateRubberBandSelectionMode(QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint);
202 
203  void setPortConstant(VuoRendererPort *port, string value);
204  void showInputEditor(VuoRendererPort *port);
205  void showInputEditor(VuoRendererPort *port, bool forwardTabTraversal);
206  void showNodeTitleEditor(VuoRendererNode *node);
207  void showCommentEditor(VuoRendererComment *comment);
208  void showPublishedPortNameEditor(VuoRendererPublishedPort *port, bool useUndoStack);
209  void zoomToFitComment(VuoRendererComment *comment);
210  void createIsolatedExternalPublishedPort(string typeName, bool isInput);
211  void changePublishedPortName(VuoRendererPublishedPort *port, string newName, bool useUndoStack);
212  void changePublishedPortDetails(VuoRendererPublishedPort *port, json_object *newDetails);
213  void openEditableSourceForNode(VuoRendererNode *node);
214  void insertCommentAtPos(QPointF targetScenePos);
215  void insertSubcompositionAtPos(QPointF targetScenePos);
216  void refactorSelectedItems();
217  void restoreDefaultLeftDockedWidgetWidths();
218  void hideSelectedInternalCables();
219  void hideCables(set<VuoRendererCable *> cables);
220  void unhideCables(set<VuoRendererCable *> cables);
221  void updateGrid();
222  void updateCanvasOpacity();
223  void updateColor(bool isDark);
224  void coalescedUpdateRunningComposition();
225  void handlePendingProtocolComplianceReevaluationRequests();
226 
227 private:
228  friend class TestVuoEditor;
229 
230  static const qreal viewportStepRate;
231  static const qreal viewportStepRateMultiplier;
232  static const qreal zoomRate;
233  static const qreal pastedComponentOffset;
234  static const qreal compositionMargin;
235  VuoCompiler *compiler;
236 
237  // The node library owned by this window, which will be the library docked into this window
238  // when in docked-library mode, and which may also at times function as the floating node library.
239  VuoNodeLibrary *ownedNodeLibrary;
240 
241  // The node library currently active in association with this window, which may be the library owned
242  // by this window or a floating library associated with a different window or the top-level application.
243  VuoNodeLibrary *nl;
244 
245  string coalescedOldCompositionSnapshot;
246  string coalescedNewCompositionSnapshot;
247  vector<string> coalescedInternalPortConstantsToSync;
248  vector<string> coalescedPublishedPortConstantsToSync;
249  vector<string> coalescedNodesToUnlink;
250  vector<string> coalescedNodesToRelink;
251  VuoCompilerCompositionDiff *coalescedDiffInfo;
252 
253  VuoCompositionMetadataPanel *metadataPanel;
254  VuoPublishedPortSidebar *inputPortSidebar;
255  VuoPublishedPortSidebar *outputPortSidebar;
256  VuoInputEditorManager *inputEditorManager;
257  VuoInputEditorSession *inputEditorSession;
258  QMenu *menuNewCompositionWithTemplate;
259  QMenu *menuProtocols;
260  VuoRecentFileMenu *menuOpenRecent;
261  VuoExampleMenu *menuOpenExample;
262  QMenu *contextMenuTints;
263  QMenu *menuChangeNode;
264  QAction *raiseDocumentAction;
265  QAction *undoAction;
266  QAction *redoAction;
267  QAction *quitAction;
268  QUndoStack *undoStack;
269  QUndoView *undoView;
270  VuoMetadataEditor *metadataEditor;
271  VuoSearchBox *searchBox;
272  bool zoomOutToFitOnNextShowEvent;
273  bool compositionUpgradedSinceLastSave;
274  bool canvasDragEnabled;
275  bool canvasDragInProgress;
276  bool scrollInProgress;
277  double timeOfLastScroll;
278  bool consumeNextMouseReleaseToCanvas;
279  bool lastLeftMousePressHadOptionModifier;
280  bool rubberBandSelectionInProgress;
281  QPointF cursorPosAtLastComponentCopy;
282  QPoint canvasDragMinCursorPos;
283  QPoint canvasDragMaxCursorPos;
284  QPoint lastCursorLocationDuringCanvasDrag;
285  bool previousDragMoveWasOverSidebar;
286  bool itemDragMacroInProgress;
287  vector<QGraphicsItem *> itemsBeingDragged;
288  VuoRendererComment *commentBeingResized;
289  int itemDragDx;
290  int itemDragDy;
291  double latestDragTime;
292  bool commentResizeMacroInProgress;
293  int commentResizeDx;
294  int commentResizeDy;
295  bool duplicationMacroInProgress;
296  VuoEditorWindowToolbar *toolbar;
297  bool isZoomedToFit;
298  bool doneInitializing;
299  bool containedPrepopulatedContent;
300  bool includeInRecentFileMenu;
301  bool publishedPortNearCursorPreviously;
302 
303  bool forwardingEventsToCanvas;
304 
305  Ui::VuoEditorWindow *ui;
306  VuoEditorComposition *composition;
307 
308  int nodeLibraryMinimumWidth;
309  int nodeLibraryMaximumWidth;
310 
311  bool protocolComplianceReevaluationPending;
312  bool ignoreItemMoveSignals;
313  bool closing;
314 
315  bool saveFile(const QString & savePath, QString & existingPath);
316  bool saveFileAs(const QString & savePath);
317  QString saveCompositionAs();
318  void acceptCloseEvent();
319  string installSubcomposition(string parentCompositionPath);
320  bool ensureThisParentCompositionSaved();
321  string sanitizeSubcompositionName(string name);
322  void updateToolbarElementUI();
323  void populateProtocolsMenu(QMenu *m);
324  void updateProtocolsMenu(QMenu *m);
325  void toggleActiveStatusForProtocol(VuoProtocol *protocol);
326  void setPublishedPortSidebarVisibility(bool visible);
327  void registerProtocolComplianceEvaluationRequest();
328  void setCompositionModified(bool modified);
329  void initializeNodeLibrary(VuoCompiler *nodeLibraryCompiler, VuoNodeLibrary::nodeLibraryDisplayMode nodeLibraryDisplayMode, VuoNodeLibrary::nodeLibraryState nodeLibraryState, VuoNodeLibrary *floater=NULL);
330  void pasteCompositionComponents();
331  void componentsPasted(QList<QGraphicsItem *> components, string commandDescription="Paste");
332  bool containsLikelyVuoComposition(QString text);
333  string getMaximumSubcompositionFromSelection(bool includePublishedPorts, bool includeHeader);
334  bool isStrandedAttachment(VuoRendererInputAttachment *attachment, QList<QGraphicsItem *> selectedItems);
335  void instantiateNewCompositionComponentsFromString(string compositionText);
336  QList<QGraphicsItem *> mergeCompositionComponentsFromString(string compositionText, bool pasteAtCursorLoc, bool pasteWithOffset, string commandDescription="Paste");
337  void transitionNodeLibraryConnections(VuoNodeLibrary *oldLibrary, VuoNodeLibrary *newLibrary);
338  QList<QGraphicsItem *> createAnyNecessaryMakeListComponents(VuoPort *port);
339  VuoRendererNode * specializeSinglePort(VuoRendererPort *port, string specializedTypeName);
340  VuoRendererNode * unspecializeSingleNode(VuoRendererNode *node, string revertedNodeClassName);
341  void enableCanvasDrag();
342  void disableCanvasDrag();
343  void initiateCanvasDrag();
344  void concludeCanvasDrag();
345  void updateRefireAction();
346  void updateCursor();
347  string generateCurrentDefaultCopyright();
348  bool confirmReplacingFile(string path);
349  bool arePublishedPortSidebarsVisible();
350 
351 #ifdef VUO_PRO
352 #include "pro/VuoEditorWindow_Pro.hh"
353 #endif
354 };