tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UISignal.h
Go to the documentation of this file.
1 // (c) 2017 Alex Nadzharov
2 // License: GPL3
3 
4 #ifndef UI_SIGNAL_H
5 #define UI_SIGNAL_H
6 
7 #include <QLineEdit>
8 #include <QMainWindow>
9 #include <QtGui>
10 
11 #include "Port.h"
12 
13 #include "UIObject.h"
14 
15 #include "OOPDHeaders.h"
16 
17 #include <QGraphicsView>
18 
19 #include "Preferences.h"
20 #include "PropertyList.h"
21 
22 #include "UIObjectData.h"
23 
24 namespace tilde {
25 
29 class UISignal : public UIObject {
30 
31  Q_OBJECT
32 
33 private:
34  // for abstracions
35  bool _isAbstraction;
36  QString _abstractionPath;
37 
38  OPClass* _opClass;
39  OPInstance* _opInstance;
40 
41  std::string _signalName;
42 
43  std::string _signalSendName;
44  std::string _signalReceiveName;
45  t_object* _pdsend_object;
46  t_object* _pdreceive_object;
47 
48 public:
49  explicit UISignal(); //UIObject* parent = 0);
50  //~UISignal();
51 
52  static UIObject* createObject(QString asQString, t_canvas* pdCanvas, QGraphicsView* parent = 0);
53 
57  virtual void paint(QPainter* p, const QStyleOptionGraphicsItem*, QWidget*)
58  {
59  QBrush brush(bgColor());
60  p->setBrush(brush);
61  p->drawRect(boundingRect());
62  p->setBrush(QBrush());
63 
64  //QPainter p(viewport());
65  p->setRenderHint(QPainter::HighQualityAntialiasing, true);
66  p->scale(scale(), scale());
67 
68  //remove this later
69 // if (subpatchWindow()) {
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 (subpatchWindow()) {
118 // subpatchWindow()->show();
119 // }
120 // }
121 
122  //abstraction opening. Fix
123  // if (getEditMode() != em_Unlocked) {
124  // if (_isAbstraction) {
125  // OpenFileProxy::openAbstraction(_abstractionPath);
126  // }
127  // }
128 
129  if ((getEditMode() == em_Unlocked) && isSelected()) {
130  // editor_->setText(QString(_objectDataModel.objectData()));
131  // editor_->show();
132 
133  emit signalEditObject(this);
134  return;
135  }
136 
137  emit selectBox(this, ev);
138  dragOffset = ev->pos().toPoint();
139  }
140 
144  void mouseReleaseEvent(QGraphicsSceneMouseEvent*)
145  {
146  update();
147  }
148 
153  void mouseMoveEvent(QGraphicsSceneMouseEvent* event)
154  {
155  if (event->buttons() & Qt::LeftButton) {
156  emit moveBox(this, event);
157  }
158  event->ignore();
159 
160  if ((getEditMode() != em_Unlocked) ) {
161  setCursor(QCursor(Qt::PointingHandCursor));
162  } else {
163  setCursor(QCursor(Qt::ArrowCursor));
164  }
165  }
166 
167  void setPdMessage(QString message)
168  {
169  // XPD-TODO
170  /*
171  fromQString(message);
172  autoResize();
173 
174  QFont myFont(PREF_QSTRING("Font"), 11);
175  QFontMetrics fm(myFont);
176  int new_w = fm.width(QString(objectData()->toQString())) + 10;
177  new_w = (new_w < 25) ? 25 : new_w;
178  setWidth(new_w);
179  //editor_->setFixedWidth(width() - 5);
180 
181  //todo: del object and create new + patchcords
182 
183  //
184  setInletsPos();
185  setOutletsPos();
186  */
187  }
188 
189  static void updateUI(void* uiobj, PdArguments msg)
190  {
191  // XPD-TODO
192  /*
193  UISignal* b = (UISignal*)uiobj;
194 
195  //qDebug() << "method out";
196 
197  if (b->_opInstance) {
198  AtomList fullMsg(gensym(b->_signalName.c_str()));
199  fullMsg.append(msg);
200  b->_opInstance->multipleOutput(fullMsg);
201  }
202 
203  emit b->updateUISignal();
204  */
205  }
206 
207 signals:
208 
209  void mouseMoved();
210  void rightClicked();
211 
212  void updateUISignal();
213 
214 private slots:
215  void updateUISlot()
216  {
217  update();
218  }
219 };
220 }
221 
222 #endif // CM_BOX_H
float height()
Definition: UIItem.h:43
void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
mouse up
Definition: UISignal.h:144
Property * get(QString pName)
Definition: PropertyList.cpp:22
QColor asQColor()
Definition: Property.cpp:229
void mousePressEvent(QGraphicsSceneMouseEvent *ev)
mouse down
Definition: UISignal.h:94
float width()
Definition: UIItem.h:42
gui object: oop signal box (pdsignal~)
Definition: UISignal.h:29
QPoint dragOffset
Definition: UIItem.h:31
QString toQString()
sets object text data
Definition: UIObject.cpp:509
void updateUISignal()
#define t_canvas
Definition: m_pd.h:205
QColor bgColor()
Definition: UIItem.h:49
PropertyList * properties()
>init properties for the class - called from constructor
Definition: UIObject.cpp:215
UIObjectData * objectData()
Definition: UIObject.cpp:101
Definition: CommonTypes.h:14
#define PREF_QSTRING(x)
Definition: Preferences.h:17
void moveBox(UIItem *box, QGraphicsSceneMouseEvent *event)
virtual void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
paint event
Definition: UISignal.h:57
void showPopupMenu(QPoint pos)
createContextMenu
Definition: UIObject.cpp:243
QRectF boundingRect() const
get edit mode flag value
Definition: UIItem.h:71
t_editMode getEditMode()
get edit mode pointer - for inlets/outlets
Definition: UIItem.cpp:54
void setPdMessage(QString message)
Definition: UISignal.h:167
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mouse move
Definition: UISignal.h:153
void signalEditObject(void *box)
basic update - calls update() probably remove later
UISignal()
Definition: UISignal.cpp:11
bool errorBox()
Definition: UIObject.cpp:522
OOPD class structure.
Definition: OPClass.h:38
void selectBox(UIItem *box, QGraphicsSceneMouseEvent *event)
Definition: m_pd.h:222
bool isSelected()
deselect object
Definition: UIItem.cpp:40
The OOPD class instance.
Definition: OPInstance.h:44
Definition: UIObject.h:44
static UIObject * createObject(QString asQString, t_canvas *pdCanvas, QGraphicsView *parent=0)
Definition: UISignal.cpp:25
static void updateUI(void *uiobj, PdArguments msg)
Definition: UISignal.h:189