tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatchWindowController.h
Go to the documentation of this file.
1 // (c) 2017 Alex Nadzharov
2 // License: GPL3
3 
4 #ifndef PATCHWINDOWCONTROLLER
5 #define PATCHWINDOWCONTROLLER
6 
7 // TODO
8 //#include <pdServer.hpp>
9 
10 #include <QObject>
11 #include <QPoint>
12 #include <QUndoStack>
13 
14 class QGraphicsScene;
15 class QGraphicsSceneMouseEvent;
16 
17 
19 
20 //namespace xpd{
21 //class Observer;
22 //class Canvas;
23 //typedef void* ProcessPtr;
24 //class Object;
25 //}
26 
27 using namespace xpd;
28 
29 using namespace std;
30 
31 namespace tilde {
32 
33 class CanvasView;
34 class CanvasData;
35 class PatchWindow;
36 class UIObject;
37 class UIPatchcord;
38 class ApplicationController;
39 
40 class UIItem;
41 class PatchWindowController;
42 
43 class UIBox;
44 
48 class PatchWindowController : public QObject {
49  Q_OBJECT
50 
51 private:
52  ApplicationController* _appController;
53 
54  CanvasData* _canvasData;
55  ObserverPtr _observer; //ControllerObserver
56 
57  //ServerInstance* _serverInstance;
58  CanvasPtr _serverCanvas;
59 
60  vector<PatchWindow*> _windows;
61  QGraphicsScene* _scene;
62 
63  // reserved
64  // vector<QGraphicsScene*> _scenes;
65 
66  // temporary
67  void doSave(QString fileName);
68  void doCreateObject(UIObject* uiObject);
69 
70  CanvasView* _boxOnlyCanvas;
71  QGraphicsScene* _boxOnlyScene;
72  UIObject* _parentObject;
73 
74  //TODO
75  CanvasView* _activeCanvasView;
76 
77  QUndoStack* _undoStack;
78 
79 public:
81  PatchWindowController(ApplicationController* appController, CanvasPtr canvas);
82 
83  // ----------------------
84 
85  ProcessPtr serverInstance();
86  ObjectId serverCanvasAsObject();
87  CanvasPtr serverCanvas();
88 
89  void setAppController(ApplicationController* a);
90  ApplicationController* appController() { return _appController; }
91 
92  CanvasData* canvasData() { return _canvasData; };
93 
94  PatchWindow* mainWindow();
95 
96  vector<PatchWindow*> windows();
97  PatchWindow* newWindow();
98 
99  // ----------------------
100 
101  UIObject* createObject(string name, QPoint pos);
102  UIObject* createObjectWithoutUndo(string name, QPoint pos);
103 
104  void restoreUIBoxForSubpatch(PatchWindowController* controller, QString data, QPoint pos);
105 
106  void createPatchcord(UIObject* src, int out, UIObject* dest, int in);
107  UIPatchcord* createPatchcordWithoutUndo(UIObject* src, int out, UIObject* dest, int in);
108 
109  // ------------
110 
111  void syncObjectsOnParent();
112  UIObject* copyObject(UIObject* src);
113  void addObjectToParent(UIObject* src);
114 
115  UIBox* asUIBox();
116 
117  void enableObjectsOnParent(UIObject* parentObject); // for GOP functionality
118  void disableObjectsOnParent();
119 
120  // ----------------------
121 
122  QUndoStack* undoStack();
123 
124  // ----------------------
125 
126  void openFile(QString fileName);
127  void saveFile(QString fileName);
128  void saveFileDialog();
129 
130  void deleteSelectedPatchcords();
131  void deletePatchcordsFor(UIItem* obj);
132  void deletePatchcordsForObject(UIObject* o);
133 
134  void deleteObject(UIObject* o);
135  void deleteObjectWithoutUndo(UIObject* o);
136 
137  void deleteSelectedObjects(vector<UIObject*>);
138  void deleteSelectedObjects(); //
139 
140  void deleteSinglePatchcord(UIPatchcord* p);
141  void deleteSelectedPatchcords(vector<UIPatchcord*>);
142 
143  void selectPatchcordsForSelectedBoxes();
144 
145  // ------------
146  void dataCut();
147  void dataCopy();
148  void dataDuplicate();
149  void dataPaste();
150  void dataSelectAllObjects();
151 
152  // -----------------------
153  void updateViewports();
154 
155  // =======================
156  void setFileName(QString fname);
157  void setNewFileName(QString fname);
158 
159  // moved from canvas-view
160  void selectBox(UIItem* box);
161  void moveSelectedBoxes(QPoint eventPos);
162 
163  void sizeBoxShow(UIObject* object);
164  void sizeBoxHide();
165 
166  void enableUndo(bool v);
167 
168  //
169 
170  void sendMessageToObject(ObjectId object, QString msg);
171 
172 public slots:
173  void menuSave();
174  void menuSaveAs();
175 
176  void menuCut();
177  void menuCopy();
178  void menuPaste();
179  void menuDuplicate();
180  void menuDelete();
181  void menuSelectAll();
182 
183  void menuUndo();
184  void menuRedo();
185 
186  void openPropertiesWindow();
187 
188  //
189  void slotAlignLeft();
190  void slotAlignRight();
191 
192  void slotAlignTop();
193  void slotAlignBottom();
194 
195  void slotAlignCenter();
196 
197  void slotHDistribute();
198  void slotVDistribute();
199 
200  void slotRecentMenuAction();
201 
202  void slotObjectHoverEnter();
203  void slotObjectHoverLeave();
204 
205 private slots:
206 
207  void slotSelectObject(UIObject* object);
208  void slotPatchcord(UIObject* src, int nOut, UIObject* dest, int nIn);
209 
210  void slotMousePress(QPoint pos);
211  void slotMouseMove(QPoint pos);
212  void slotMouseRelease(QPoint pos);
213 
214  void slotDeselectObjects();
215 
216  void slotSelectionFrame(QPoint start, QPoint end);
217  void slotMoveSelectedBoxes(QPoint eventPos);
218 
219  void slotResizeBoxes(int dx, int dy);
220 
221 signals:
222 
223  Object* signalCreateObject(Canvas* canvas, string name); // check that
224 
225  void signalEnableUndo(bool v);
226  void signalEnableRedo(bool v);
227 };
228 }
229 
230 #endif // CM_PDLINK_H
CanvasData * canvasData()
Definition: PatchWindowController.h:92
shared canvas data model - boxes, patchcords
Definition: CanvasData.h:22
Patch window. Creates scroll view and cm_canvas; Creates menu commands, forwards them to cm_canvas...
Definition: PatchWindow.h:14
The Application Controller class.
Definition: ApplicationController.h:44
UIItem QGraphicsObject class.
Definition: UIItem.h:15
Patchcord QGraphicsObject class.
Definition: UIPatchcord.h:36
ApplicationController * appController()
Definition: PatchWindowController.h:90
The Patch window controller.
Definition: PatchWindowController.h:48
Definition: UIObject.h:44
Canvas View - used by Patch window controller.
Definition: CanvasView.h:36
gui object: standard object box
Definition: UIBox.h:46