Vuo  2.1.0
VuoNodeLibrary.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "VuoHeap.h"
13 
14 class VuoCompiler;
17 class VuoNodeClass;
18 class VuoNodePopover;
19 
20 namespace Ui
21 {
22  class VuoNodeLibrary;
23 }
24 
28 class VuoNodeLibrary : public QDockWidget
29 {
30  Q_OBJECT
31 
32 public:
37  {
38  displayByClass,
39  displayByName
40  };
41 
46  {
47  nodeLibraryHidden,
48  nodeLibraryDocked,
49  nodeLibraryFloating
50  };
51 
52  explicit VuoNodeLibrary(VuoCompiler *compiler, QWidget *parent = 0,
53  VuoNodeLibrary::nodeLibraryDisplayMode displayMode = VuoNodeLibrary::displayByClass);
54  void setCompiler(VuoCompiler *compiler);
55  static void cullHiddenNodeClasses(vector<VuoCompilerNodeClass *> &nodeClasses);
56  void prepareAndMakeVisible();
57  void fixWidth(bool fix);
59  bool eventFilter(QObject *object, QEvent *event) VuoWarnUnusedResult;
60  ~VuoNodeLibrary();
61  static QStringList tokenizeNodeName(QString nodeName, QString className);
62  static bool isStopWord(QString word);
63  bool getHumanReadable();
64  void focusTextFilter();
65  void searchForText(QString text);
66  void getState(QString &filterText, set<string> &selectedNodeClasses, string &documentedNodeClass);
67  void setState(QString filterText, set<string> selectedNodeClasses, string documentedNodeClass);
69  void emitNodeLibraryHiddenOrUnhidden(bool unhidden);
71  void clearNodeClassList();
72  void updateNodeClassList(const vector<string> &nodeClassesToRemove, const vector<VuoCompilerNodeClass *> &nodeClassesToAdd);
73  void highlightNodeClass(string targetNodeClassName, bool highlightAsNewlyInstalled=true, bool resetPreviousSelection=true);
74  void prepareAndDisplayNodePopoverForClass(string nodeClassName);
75 
76 signals:
77  void componentsAdded(QList<QGraphicsItem *> addedComponents, VuoEditorComposition *target);
78  void changedIsHumanReadable(bool humanReadable);
79  void nodeLibraryHiddenOrUnhidden(bool unhidden);
81  void nodeLibraryMoved(QPoint newPos);
82  void nodeLibraryWidthChanged(int);
83  void nodeLibraryHeightChanged(int);
87  void aboutToBeDestroyed();
88 
89 public slots:
90  void clickedNamesButton();
92  void setHumanReadable(bool humanReadable);
94  void displayPopoverInPane(QWidget *panelContentWidget, QString resourceDir="");
95  void updateUI();
96 
97 protected:
98  void moveEvent(QMoveEvent *event);
99  void resizeEvent(QResizeEvent *event);
100  void showEvent(QShowEvent *event);
101  void closeEvent(QCloseEvent *event);
102  void keyPressEvent(QKeyEvent *event);
103 
104 private slots:
105  void updateListViewForNewFilterTextOnTimer();
106  void updateListViewForNewFilterTextNow();
107  void emitNodeDocumentationPanelHeightChanged();
108  void updateColor(bool isDark);
109 
110 private:
111  friend class TestVuoEditor;
112 
113  Ui::VuoNodeLibrary *ui;
114  VuoCompiler *compiler;
115  vector<VuoCompilerNodeClass *> loadedNodeClasses;
116  static map<VuoCompilerNodeClass *, int> newlyInstalledNodeClasses;
117  map<string, VuoNodePopover *> popoverForNodeClass;
118  map<string, string> capitalizationForNodeClass;
119  static map<pair<QString, QString>, QStringList> tokensForNodeClass;
120  static map<string, int> nodeClassFrequency;
121  static set<string> stopWords;
122  int preferredNodeDocumentationPanelHeight;
123  int preferredNodeLibraryWidth;
124  bool hasBeenShown;
125  int defaultMinimumWidth;
126  int defaultMaximumWidth;
127  QTimer *updateListViewTimer;
128 
129  void populateList(vector<VuoCompilerNodeClass *> nodeClasses, bool resetSelection);
130  static bool nodeHasPortMatchingString(VuoCompilerNodeClass *cnc, string needle, bool isInput);
131  static bool nodeHasSourceType(VuoCompilerNodeClass *cnc, string sourceType);
132  void updateListView(bool resetSelection);
133  vector<VuoCompilerNodeClass *> getMatchingNodeClassesForSearchTerms(QStringList rawTermList);
134  void updateListViewForNewDisplayMode();
135  VuoNodePopover * initializeNodePopoverForClass(VuoNodeClass *nodeClass, VuoCompiler *compiler);
136  VuoNodePopover * getNodePopoverForClass(VuoNodeClass *nodeClass, VuoCompiler *compiler);
137  void updateSplitterPosition();
138  static bool nodeClassLessThan(VuoCompilerNodeClass *nodeClass1, VuoCompilerNodeClass *nodeClass2);
139  QStringList applyFilterTransformations(QStringList filterTokenList);
140  void populateNodeClassFrequencyMap();
141  void populateStopWordList();
142  void recordNodeClassCapitalizations();
143  void releaseNodePopovers();
144 
145 #ifdef VUO_PRO
146 #include "pro/VuoNodeLibrary_Pro.hh"
147 #endif
148 };