tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UIItem.h
Go to the documentation of this file.
1 // (c) 2017 Alex Nadzharov
2 // License: GPL3
3 
4 #ifndef UIITEM_H
5 #define UIITEM_H
6 
7 #include "CommonTypes.h"
8 #include <QGraphicsObject>
9 
10 namespace tilde {
11 
15 class UIItem : public QGraphicsObject {
16  Q_OBJECT
17 
18 private:
19  bool _selected;
20  bool _hover;
21 
22  t_editMode* _editMode;
23 
24  QSize _size;
25  QSize _minSize;
26 
27  QPoint _pos; //?
28  QColor _bgColor;
29 
30 public:
31  QPoint dragOffset;
32 
33  explicit UIItem(QGraphicsObject* parent = 0);
34 
35  void setSize(QSize size) { _size = size; }
36  void setSize(float w, float h) { _size = QSize(w, h); }
37  void setWidth(float w) { _size.setWidth(w); }
38  void setHeight(float h) { _size.setHeight(h); }
39  void setMinWidth(float w) { _minSize.setWidth(w); }
40  void setMinHeight(float h) { _minSize.setHeight(h); }
41 
42  float width() { return _size.width(); }
43  float height() { return _size.height(); }
44  float minWidth() { return _minSize.width(); }
45  float minHeight() { return _minSize.height(); }
46 
47  QSize size() { return _size; }
48 
49  QColor bgColor() { return _bgColor; }
50  void setBgColor(QColor bgc) { _bgColor = bgc; }
51 
52  bool hover() { return _hover; }
53  void setHover(bool h) { _hover = h; }
54 
55  void select();
56  void deselect();
57  bool isSelected();
58 
65  virtual void setEditModeRef(t_editMode* canvasEditModeRef);
66 
67  virtual t_editMode* getEditModeRef();
68 
70 
71  QRectF boundingRect() const { return QRectF(0, 0, _size.width(), _size.height()); }
72  QPainterPath shape() const;
73 
74  virtual void move(float x, float y);
75  virtual void move(QPoint pos);
76  virtual void move(QPointF pos);
77 
78  void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*){};
79 
80  virtual void resizeEvent() {}
81 
82 signals:
83 
84  void mousePressed(UIItem* obj, QGraphicsSceneMouseEvent* ev);
85  void mouseReleased(UIItem* obj, QGraphicsSceneMouseEvent* ev);
86 
87  void mouseEntered(UIItem* obj, QGraphicsSceneHoverEvent* ev);
88  void mouseLeaved(UIItem* obj, QGraphicsSceneHoverEvent* ev);
89 
90  void selectBox(UIItem* box, QGraphicsSceneMouseEvent* event);
91  void moveBox(UIItem* box, QGraphicsSceneMouseEvent* event);
92 
93 public slots:
94 };
95 }
96 
97 #endif //
virtual void resizeEvent()
Definition: UIItem.h:80
float height()
Definition: UIItem.h:43
void setHeight(float h)
Definition: UIItem.h:38
void setHover(bool h)
Definition: UIItem.h:53
void mouseEntered(UIItem *obj, QGraphicsSceneHoverEvent *ev)
void setSize(float w, float h)
Definition: UIItem.h:36
float width()
Definition: UIItem.h:42
void mousePressed(UIItem *obj, QGraphicsSceneMouseEvent *ev)
UIItem(QGraphicsObject *parent=0)
Definition: UIItem.cpp:10
QPoint dragOffset
Definition: UIItem.h:31
virtual void move(float x, float y)
Definition: UIItem.cpp:67
UIItem QGraphicsObject class.
Definition: UIItem.h:15
QColor bgColor()
Definition: UIItem.h:49
void moveBox(UIItem *box, QGraphicsSceneMouseEvent *event)
void setMinHeight(float h)
Definition: UIItem.h:40
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 setMinWidth(float w)
Definition: UIItem.h:39
float minHeight()
Definition: UIItem.h:45
void deselect()
select object
Definition: UIItem.cpp:35
void setBgColor(QColor bgc)
Definition: UIItem.h:50
virtual void setEditModeRef(t_editMode *canvasEditModeRef)
get object's selected flag
Definition: UIItem.cpp:42
float minWidth()
Definition: UIItem.h:44
void mouseLeaved(UIItem *obj, QGraphicsSceneHoverEvent *ev)
QPainterPath shape() const
Definition: UIItem.cpp:60
void mouseReleased(UIItem *obj, QGraphicsSceneMouseEvent *ev)
void select()
Definition: UIItem.cpp:30
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
Definition: UIItem.h:78
t_editMode
edit mode types
Definition: CommonTypes.h:13
void selectBox(UIItem *box, QGraphicsSceneMouseEvent *event)
QSize size()
Definition: UIItem.h:47
bool isSelected()
deselect object
Definition: UIItem.cpp:40
virtual t_editMode * getEditModeRef()
Definition: UIItem.cpp:49
void setSize(QSize size)
Definition: UIItem.h:35
bool hover()
Definition: UIItem.h:52
void setWidth(float w)
Definition: UIItem.h:37