tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CanvasData.h
Go to the documentation of this file.
1 // (c) 2017 Alex Nadzharov
2 // License: GPL3
3 
4 #ifndef CM_CANVAS_TYPES_H
5 #define CM_CANVAS_TYPES_H
6 
7 #include "Clipboard.h"
8 #include "UIPatchcord.h"
9 
10 class ServerCanvas;
11 
12 namespace tilde {
13 
14 class UIBox;
15 
16 typedef std::vector<UIObject*> objectVec;
17 typedef std::vector<UIPatchcord*> patchcordVec;
18 
21 
22 class CanvasData {
23 
24  objectVec _boxes;
25  patchcordVec _patchcords;
26 
27  objectVec _selectedBoxes;
28  patchcordVec _selectedPatchcords;
29 
30  objectVec _previouslySelectedBoxes;
31  patchcordVec _previouslySelectedPatchcords;
32 
33  Clipboard* _clipboard;
34 
35  portItemVec* _inlets;
36  portItemVec* _outlets;
37 
38  // new 0517
39  //ServerCanvas* _serverCanvas;
40 
41  QString _fileName;
42  QString _filePath;
43  bool _firstSave;
44 
45  PropertyList* _properties;
46 
47  // temporary - probably use properties later
48  QPoint _position;
49  QSize _size;
50 
51 public:
52  CanvasData();
53 
54  portItemVec* inlets() { return _inlets; }
55  portItemVec* outlets() { return _outlets; }
56 
57  void setInlets(portItemVec* inlets) { _inlets = inlets; }
58  void setOutlets(portItemVec* outlets) { _outlets = outlets; }
59 
60  void setFileName(QString fName) { _fileName = fName; }
61  QString fileName() { return _fileName; }
62 
63  void setFilePath(QString filePath) { _filePath = filePath; }
64  QString filePath() { return _filePath; };
65 
66  void setFirstSave(bool fs) { _firstSave = fs; }
67  bool firstSave() { return _firstSave; }
68 
69  PropertyList* properties() { return _properties; };
70  void setProperties(PropertyList* p) { _properties = p; };
71  //
72 
73  void setPosition(QPoint p) { _position = p; }
74  void setSize(QSize s) { _size = s; }
75 
76  //
77  bool hasObjects() { return ((_boxes.size() > 0) || (_patchcords.size() > 0)); }
78  bool hasSelectedObjects() { return ((_selectedBoxes.size() > 0) || (_selectedPatchcords.size() > 0)); }
79 
80  objectVec* boxes() { return &_boxes; }
81  patchcordVec* patchcords() { return &_patchcords; }
82  objectVec* selectedBoxes() { return &_selectedBoxes; }
83  patchcordVec* selectedPatchcords() { return &_selectedPatchcords; }
84 
85  // ------------------------------
86 
87  void addUniqueBox(objectVec* boxes, UIObject* box);
89  int findBox(objectVec* boxes, UIObject* box);
91 
92  //
93  void selectBoxesInFrame(QPoint start, QPoint end);
94  void moveSelectedBoxes(QPoint pos, bool gridSnap);
95 
96  // ------------------------------
97 
98  void addBox(UIObject* box) { addUniqueBox(&_boxes, box); }
99  void addPatchcord(UIPatchcord* pc) { addUniquePatchcord(&_patchcords, pc); }
100 
101  // ------------------------------
102 
103  void selectBox(UIObject* box);
104  void selectPatchcord(UIPatchcord* pc);
105  void deselectBoxes();
106  void deselectPatchcords();
107 
108  // ----------
109 
110  void deletePatchcord(UIPatchcord* pc);
111 
112  // ----------
113 
114  void cut();
115  void copy();
116  void paste();
117 
118  // -------
119 
120  int findObjectIndex(UIObject* obj);
121  UIObject* getObjectByIndex(int idx);
123 
124  // ------------------------------
125 
126  QStringList boxesAsPdFileStrings(objectVec* boxes);
127  std::string patchcordAsPdFileString(UIPatchcord* pcord);
130 
131  QStringList objectsAsPdFileStrings();
132  QString canvasAsPdFileString();
133  QStringList asPdFileStrings();
134 
135  // -------
136 };
137 }
138 
139 #endif // CM_CANVAS_TYPES_H
UIObject * getObjectByIndex(int idx)
Definition: CanvasData.cpp:187
int findPatchcord(patchcordVec *patchcords, UIPatchcord *pcord)
Definition: CanvasData.cpp:66
PropertyList * properties()
Definition: CanvasData.h:69
void setFileName(QString fName)
Definition: CanvasData.h:60
void addUniquePatchcord(patchcordVec *patchcords, UIPatchcord *pcord)
Definition: CanvasData.cpp:43
shared canvas data model - boxes, patchcords
Definition: CanvasData.h:22
patchcordVec * patchcords()
Definition: CanvasData.h:81
QString canvasAsPdFileString()
Definition: CanvasData.cpp:314
void selectPatchcord(UIPatchcord *pc)
Definition: CanvasData.cpp:109
int findBox(objectVec *boxes, UIObject *box)
Definition: CanvasData.cpp:55
void setFilePath(QString filePath)
Definition: CanvasData.h:63
t_patchcordAsNumbers patchcordAsNumbers(UIPatchcord *pcord)
Definition: CanvasData.cpp:276
std::vector< UIObject * > objectVec
Definition: ArrangeObjects.h:12
void deselectPatchcords()
Definition: CanvasData.cpp:131
std::string patchcordAsPdFileString(UIPatchcord *pcord)
Definition: CanvasData.cpp:232
QString filePath()
Definition: CanvasData.h:64
std::vector< Port * > portItemVec
Definition: UIObjectData.h:13
QStringList objectsAsPdFileStrings()
Definition: CanvasData.cpp:305
Patchcord QGraphicsObject class.
Definition: UIPatchcord.h:36
bool hasSelectedObjects()
Definition: CanvasData.h:78
void selectBoxesInFrame(QPoint start, QPoint end)
Definition: CanvasData.cpp:77
bool firstSave()
Definition: CanvasData.h:67
std::vector< UIPatchcord * > patchcordVec
Definition: CanvasData.h:17
QStringList boxesAsPdFileStrings(objectVec *boxes)
Definition: CanvasData.cpp:216
int findObjectIndex(UIObject *obj)
Definition: CanvasData.cpp:176
objectVec * boxes()
Definition: CanvasData.h:80
void cut()
Definition: CanvasData.cpp:154
void setProperties(PropertyList *p)
Definition: CanvasData.h:70
QString fileName()
Definition: CanvasData.h:61
void setOutlets(portItemVec *outlets)
Definition: CanvasData.h:58
QStringList patchcordsAsPdFileStrings(patchcordVec *patchcords)
Definition: CanvasData.cpp:256
patchcordVec patchcordsForObject(UIObject *obj)
Definition: CanvasData.cpp:198
void setFirstSave(bool fs)
Definition: CanvasData.h:66
void paste()
Definition: CanvasData.cpp:170
portItemVec * inlets()
Definition: CanvasData.h:54
void deletePatchcord(UIPatchcord *pc)
Definition: CanvasData.cpp:147
Property handling class for ui object - property list.
Definition: PropertyList.h:34
patchcordVec * selectedPatchcords()
Definition: CanvasData.h:83
The Clipboard class - just a QStringList with Pd strings for objects.
Definition: Clipboard.h:13
void setPosition(QPoint p)
Definition: CanvasData.h:73
patchcord as numbers
Definition: UIPatchcord.h:20
CanvasData()
Definition: CanvasData.cpp:10
void moveSelectedBoxes(QPoint pos, bool gridSnap)
void deselectBoxes()
Definition: CanvasData.cpp:115
void setSize(QSize s)
Definition: CanvasData.h:74
void selectBox(UIObject *box)
Definition: CanvasData.cpp:103
QStringList asPdFileStrings()
Definition: CanvasData.cpp:337
portItemVec * outlets()
Definition: CanvasData.h:55
void addPatchcord(UIPatchcord *pc)
Definition: CanvasData.h:99
void addBox(UIObject *box)
Definition: CanvasData.h:98
void copy()
Definition: CanvasData.cpp:163
void addUniqueBox(objectVec *boxes, UIObject *box)
Definition: CanvasData.cpp:31
Definition: UIObject.h:44
objectVec * selectedBoxes()
Definition: CanvasData.h:82
void setInlets(portItemVec *inlets)
Definition: CanvasData.h:57
bool hasObjects()
Definition: CanvasData.h:77