tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UIProperty.h
Go to the documentation of this file.
1 // (c) 2017 Alex Nadzharov
2 // License: GPL3
3 
4 #ifndef UI_PROPERTY
5 #define UI_PROPERTY
6 
7 #include <QLineEdit>
8 #include <QMainWindow>
9 #include <QtGui>
10 
11 #include "Port.h"
12 
13 #include "UIBox.h"
14 #include "UIObject.h"
15 
16 //#include "cm_pdlink.h"
17 
18 #include "OOPDHeaders.h"
19 
20 #include <QGraphicsView>
21 
22 #include "PatchWindow.h"
23 #include "PatchWindowController.h"
24 
25 #include "Preferences.h"
26 #include "PropertyList.h"
27 
28 #include "UIObjectData.h"
29 
30 namespace tilde {
31 
35 class UIProperty : public UIBox {
36 
37  Q_OBJECT
38 
39 private:
40  // for abstracions
41  bool _isAbstraction;
42  QString _abstractionPath;
43 
44  OPClass* _opClass;
45  OPInstance* _opInstance;
46 
47  std::string _propertyName;
48 
49 public:
50  explicit UIProperty(); //UIObject* parent = 0);
51  //~UIProperty();
52 
53  static UIObject* createObject(QString asQString, t_canvas* pdCanvas, QGraphicsView* parent = 0);
54 
58  virtual void paint(QPainter* p, const QStyleOptionGraphicsItem*, QWidget*)
59  {
60  QBrush brush(bgColor());
61  p->setBrush(brush);
62  p->drawRect(boundingRect());
63  p->setBrush(QBrush());
64 
65  p->setRenderHint(QPainter::HighQualityAntialiasing, true);
66  p->scale(scale(), scale());
67 
68  //remove this later
69  if (subpatchController()) {
70  p->setPen(QPen(QColor(192, 192, 192), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
71  p->drawRect(0, 2, width(), height() - 4);
72  }
73 
74  QColor rectColor = (errorBox()) ? QColor(255, 0, 0) : properties()->get("BorderColor")->asQColor(); //QColor(128, 128, 128);
75  p->setPen(QPen(rectColor, 1 + _isAbstraction, (errorBox()) ? Qt::DashLine : Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
76  p->drawRect(0, 0, width(), height());
77  QTextOption* op = new QTextOption;
78  op->setAlignment(Qt::AlignLeft);
79  p->setPen(QPen(QColor(0, 0, 0), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
80 
81  p->setFont(QFont(PREF_QSTRING("Font"), properties()->get("FontSize")->asFontSize(), 0, false));
82  p->drawText(2, 3, width() - 2, height() - 3, 0, objectData()->toQString(), 0);
83 
84  if (isSelected()) {
85  p->setPen(QPen(QColor(0, 192, 255), 1, (errorBox()) ? Qt::DashLine : Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
86  p->drawRect(0, 0, width(), height());
87  }
88  }
89 
94  void mousePressEvent(QGraphicsSceneMouseEvent* ev)
95  {
96  //context menu
97  if (ev->button() == Qt::RightButton) {
98 
99  if (scene()
100  && !scene()->views().isEmpty()
101  && scene()->views().first()
102  && scene()->views().first()->viewport()) {
103 
104  QGraphicsView* v = scene()->views().first();
105  QPoint pos = v->viewport()->mapToGlobal(ev->pos().toPoint());
106 
107  // TODO
108  showPopupMenu(pos + this->pos().toPoint());
109  ev->accept();
110  }
111 
112  return;
113  }
114 
115  //open canvas for subpatch
116  if (getEditMode() != em_Unlocked) {
117  if (subpatchController()) {
118  subpatchController()->mainWindow()->show();
119  }
120  }
121 
122  if ((getEditMode() == em_Unlocked) && isSelected()) {
123 
124  emit signalEditObject(this);
125  return;
126  }
127 
128  emit selectBox(this, ev);
129  dragOffset = ev->pos().toPoint();
130  }
131 
135  void mouseReleaseEvent(QGraphicsSceneMouseEvent*) {}
136 
141  void mouseMoveEvent(QGraphicsSceneMouseEvent* event)
142  {
143  if (event->buttons() & Qt::LeftButton) {
144  emit moveBox(this, event);
145  }
146  event->ignore();
147 
148  if ((getEditMode() != em_Unlocked) && (subpatchController())) {
149  setCursor(QCursor(Qt::PointingHandCursor));
150  } else {
151  setCursor(QCursor(Qt::ArrowCursor));
152  }
153  }
154 
155  void setPdMessage(QString message)
156  {
157  //XPD-TODO
158  /*
159  fromQString(message);
160  autoResize();
161 
162  QFont myFont(PREF_QSTRING("Font"), 11);
163  QFontMetrics fm(myFont);
164  int new_w = fm.width(QString(objectData()->toQString())) + 10;
165  new_w = (new_w < 25) ? 25 : new_w;
166  setWidth(new_w);
167  //editor_->setFixedWidth(width() - 5);
168 
169  //
170  setInletsPos();
171  setOutletsPos();
172 */
173  }
174 
175  static void updateUI(void* uiobj, PdArguments msg)
176  {
177  //XPD-TODO
178  /*
179 
180  UIProperty* b = (UIProperty*)uiobj;
181 
182  //qDebug() << "method out";
183 
184  if (b->_opInstance) {
185  if (msg.at(0).asSymbol() == gensym("bang")) {
187 
188  AtomList _prop = b->_opInstance->getPdArgumentsProperty(gensym(b->_propertyName.c_str()));
189  QStringList list1;
190  for (size_t i = 0; i < _prop.size(); i++) {
191  list1.append(_prop.at(i).asString().c_str());
192  }
193 
194  // TODO-PD_OBJECT
195 // cmp_sendstring((t_pd*)b->pdObject(), (std::string) "__output " + list1.join(" ").toStdString());
196 
197  } else if (msg.at(0).asSymbol() == gensym("set")) {
198  // TODO
199  // /* TODO * / //cmp_post("set!");
200 
201  //AtomList msg2 = msg;
202  //msg2.at(0) = gensym(b->_propertyName.c_str());
203  b->_opInstance->setPdArgumentsProperty(gensym(b->_propertyName.c_str()), msg); //.subList(1,msg.size()-1));
204  //b->_opInstance->callSetter(msg2);
205 
206  } else {
207  AtomList fullMsg(gensym(b->_propertyName.c_str()));
208  fullMsg.append(msg);
209  b->_opInstance->multipleOutput(fullMsg);
210  }
211  }
212 
213  emit b->updateUISignal();
214 
215 */
216  }
217 
218 signals:
219 
220  void mouseMoved();
221  void rightClicked();
222 
223  void updateUISignal();
224 
225 private slots:
226  void updateUISlot()
227  {
228  update();
229  }
230 };
231 }
232 
233 #endif // CM_BOX_H
#define t_canvas
Definition: m_pd.h:205
Definition: CommonTypes.h:14
#define PREF_QSTRING(x)
Definition: Preferences.h:17
Definition: oop_common.h:352
Definition: oop_common.h:81