tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CanvasView.h
Go to the documentation of this file.
1 // (c) 2017 Alex Nadzharov
2 // License: GPL3
3 
4 #ifndef CM_CANVAS_H
5 #define CM_CANVAS_H
6 
7 #include <QWidget>
8 #include <QtGui>
9 #include <QtWidgets>
10 
11 #include "UIPatchcord.h"
12 
13 #include "ObjectMaker.h"
14 
15 #include "ObjectLoader.h"
16 
17 #include "Grid.h"
18 #include "SelectionRect.h"
19 #include "UINewPatchcord.h"
20 
21 #include "CanvasData.h"
22 
23 #include "Clipboard.h"
24 
25 #include <QMenu>
26 
27 //class QMenu;
28 
29 using namespace std;
30 
31 namespace tilde {
32 
36 class CanvasView : public QGraphicsView {
37 private:
38  UIObject* _connectionStartObject;
39  UIObject* _connectionStartOutlet;
40  UIObject* _replaceObject;
41 
42  QPoint _newObjectPos;
43  QPoint _dragPrevPos;
44 
45  bool _gridSnap;
46 
47  QSize _windowSize;
48 
49  ObjectMaker* _objectMaker;
50 
51  bool _keepPdObject;
52  bool _readOnly;
53 
54  t_editMode* _canvasEditMode;
55 
56  Grid* _grid;
57  SelectionRect* _selectionRect;
58  UINewPatchcord* _newPatchcord;
59 
60  UIObject* _dragObject;
61 
62  float _zoom;
63 
64  QTransform* _transformMatrix;
65 
66  QMenu _popupMenu;
67  QAction* _pmProperties;
68 
69  PatchWindowController* _controller;
70 
71  Q_OBJECT
72 
73 public:
74  explicit CanvasView(QGraphicsView* parent = 0);
75 
76  // todo fix
77  QPoint newObjectPos();
78 
79  UIObject* dragObject();
80  void setDragObject(UIObject* object);
81 
82  void setController(PatchWindowController* c);
83 
84  void setZoom(float zoomDirection);
85  float getZoom();
86 
87  virtual t_editMode getEditMode();
88  virtual t_editMode* getEditModeRef();
89 
90  void setEditMode(t_editMode mode);
91  void setGridEnabled(bool val);
92  void setGridSnap(bool val);
93 
94  bool gridSnap();
95  int gridStep();
96 
97  void setKeepPdObject(bool v);
98  bool keepPdObject();
99 
100  void setReadOnly(bool val);
101 
102  bool readOnly();
103 
104  QSize minimumCanvasSize();
105 
106  void setWindowSize(QSize wsize);
107 
108  void setReplaceObject(UIObject* obj);
109  UIObject* replaceObject();
110 
111  // -------------------------------------------------------
112 
113  void addInlet();
114  void addOutlet();
115 
116  // -------------------------------------------------------
117 
118  void mouseMoveEvent(QMouseEvent* ev);
119  void mousePressEvent(QMouseEvent* ev);
120  void mouseReleaseEvent(QMouseEvent* ev);
121 
122  // -------------------------------------------------------
123 
124  void resizeToObjects();
125 
126  Q_SLOT void slotSelectBox(UIItem* box, QGraphicsSceneMouseEvent* ev);
127 
128  Q_SLOT void slotMoveBox(UIItem* box, QGraphicsSceneMouseEvent* event);
129 
130  void cancelPatchcord();
131 
132  ObjectMaker* objectMaker();
133 
134  void portLocalCountUpdated();
135 
136  void showNewObjectMaker();
137 
138  void canvasFromPdStrings(QStringList strings);
139 
140  // -- NEW ---------------------------------------
141 
142  void resizeEvent(QResizeEvent*);
143  void createContextMenu();
144 
145  //SizeBox* sizeBox();
146 
147 private slots:
148 
149  void slotPopupMenu();
150 
151 public slots:
152 
153  void slotInletMousePress(UIItem* obj, QGraphicsSceneMouseEvent* ev);
154  void slotInletMouseRelease(UIItem* obj, QGraphicsSceneMouseEvent* ev);
155 
156  void slotInletMouseEnter(UIItem* obj, QGraphicsSceneHoverEvent* ev);
157  void slotInletMouseLeave(UIItem* obj, QGraphicsSceneHoverEvent* ev);
158 
159  void slotOutletMousePressed(UIItem* obj, QGraphicsSceneMouseEvent*);
160  void slotOutletMouseReleased(UIItem*, QGraphicsSceneMouseEvent*);
161 
165  void slotPortCountUpdated();
166 
172  void slotObjectStartsEdit(void* obj);
173 
174 signals:
175  pair<QMainWindow*, tilde::UIObject*> createSubpatchWindow();
176  void signalUpdatePortCount();
177 
178  // new 0617
179  void signalSelectObject(UIObject* object);
180  void signalPatchcord(UIObject* src, int nOut, UIObject* dest, int nIn);
181 
182  void signalMousePress(QPoint pos);
183  void signalMouseMove(QPoint pos);
184  void signalMouseRelease(QPoint pos);
185 
186  void signalDeselectObjects();
187 
188  void signalSelectionFrame(QPoint start, QPoint end);
189  void signalMoveSelectedBoxes(QPoint eventPos);
190 
191  void signalPopupMenu();
192 };
193 }
194 
195 #endif // CM_CANVAS_H
selection rectangle QGraphicsObject (UIItem)
Definition: SelectionRect.h:17
UIItem QGraphicsObject class.
Definition: UIItem.h:15
New patchcord - dashed line.
Definition: UINewPatchcord.h:13
The Patch window controller.
Definition: PatchWindowController.h:48
creates QLineEdit box for new object
Definition: ObjectMaker.h:18
Grid for the canvas.
Definition: Grid.h:14
t_editMode
edit mode types
Definition: CommonTypes.h:13
Definition: UIObject.h:44
Canvas View - used by Patch window controller.
Definition: CanvasView.h:36