1 /*
2  * Patchbay Canvas engine using QGraphicsView/Scene
3  * Copyright (C) 2010-2012 Filipe Coelho <falktx@falktx.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * For a full copy of the GNU General Public License see the COPYING file
16  */
17 
18 #ifndef CANVASPORT_H
19 #define CANVASPORT_H
20 
21 #include "patchcanvas.h"
22 
23 class QGraphicsSceneContextMenuEvent;
24 class QGraphicsSceneMouseEvent;
25 class QPainter;
26 
27 START_NAMESPACE_PATCHCANVAS
28 
29 class AbstractCanvasLineMov;
30 
31 class CanvasPort : public QGraphicsItem
32 {
33 public:
34     CanvasPort(int port_id, QString port_name, PortMode port_mode, PortType port_type, QGraphicsItem* parent);
35 
36     int getPortId();
37     PortMode getPortMode();
38     PortType getPortType();
39     QString getPortName();
40     QString getFullPortName();
41     int getPortWidth();
42     int getPortHeight();
43 
44     void setPortMode(PortMode port_mode);
45     void setPortType(PortType port_type);
46     void setPortName(QString port_name);
47     void setPortWidth(int port_width);
48 
49     virtual int type() const;
50 
51 private:
52     int m_port_id;
53     PortMode m_port_mode;
54     PortType m_port_type;
55     QString m_port_name;
56 
57     int m_port_width;
58     int m_port_height;
59     QFont m_port_font;
60 
61     AbstractCanvasLineMov* m_line_mov;
62     CanvasPort* m_hover_item;
63     bool m_last_selected_state;
64 
65     bool m_mouse_down;
66     bool m_cursor_moving;
67 
68     virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
69     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
70     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
71     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
72 
73     virtual QRectF boundingRect() const;
74     virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
75 };
76 
77 END_NAMESPACE_PATCHCANVAS
78 
79 #endif // CANVASPORT_H
80