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 PATCHCANVAS_H 19 #define PATCHCANVAS_H 20 21 #include <QtGui/QGraphicsItem> 22 23 #include "../patchcanvas.h" 24 25 #define foreach2(var, list) \ 26 for (int i=0; i < list.count(); i++) { var = list[i]; 27 28 class QSettings; 29 class QTimer; 30 31 class CanvasObject : public QObject { 32 Q_OBJECT 33 34 public: 35 CanvasObject(QObject* parent=0); 36 37 public slots: 38 void AnimationIdle(); 39 void AnimationHide(); 40 void AnimationDestroy(); 41 void CanvasPostponedGroups(); 42 void PortContextMenuDisconnect(); 43 }; 44 45 START_NAMESPACE_PATCHCANVAS 46 47 class AbstractCanvasLine; 48 class CanvasFadeAnimation; 49 class CanvasBox; 50 class CanvasPort; 51 class Theme; 52 53 // object types 54 enum CanvasType { 55 CanvasBoxType = QGraphicsItem::UserType + 1, 56 CanvasIconType = QGraphicsItem::UserType + 2, 57 CanvasPortType = QGraphicsItem::UserType + 3, 58 CanvasLineType = QGraphicsItem::UserType + 4, 59 CanvasBezierLineType = QGraphicsItem::UserType + 5, 60 CanvasLineMovType = QGraphicsItem::UserType + 6, 61 CanvasBezierLineMovType = QGraphicsItem::UserType + 7 62 }; 63 64 // object lists 65 struct group_dict_t { 66 int group_id; 67 QString group_name; 68 bool split; 69 Icon icon; 70 CanvasBox* widgets[2]; 71 }; 72 73 struct port_dict_t { 74 int group_id; 75 int port_id; 76 QString port_name; 77 PortMode port_mode; 78 PortType port_type; 79 CanvasPort* widget; 80 }; 81 82 struct connection_dict_t { 83 int connection_id; 84 int port_in_id; 85 int port_out_id; 86 AbstractCanvasLine* widget; 87 }; 88 89 struct animation_dict_t { 90 CanvasFadeAnimation* animation; 91 QGraphicsItem* item; 92 }; 93 94 // Main Canvas object 95 class Canvas { 96 public: 97 Canvas(); 98 ~Canvas(); 99 100 PatchScene* scene; 101 Callback callback; 102 bool debug; 103 unsigned long last_z_value; 104 int last_connection_id; 105 QPointF initial_pos; 106 QRectF size_rect; 107 QList<group_dict_t> group_list; 108 QList<port_dict_t> port_list; 109 QList<connection_dict_t> connection_list; 110 QList<animation_dict_t> animation_list; 111 CanvasObject* qobject; 112 QSettings* settings; 113 Theme* theme; 114 bool initiated; 115 }; 116 117 const char* bool2str(bool check); 118 const char* port_mode2str(PortMode port_mode); 119 const char* port_type2str(PortType port_type); 120 const char* icon2str(Icon icon); 121 const char* split2str(SplitOption split); 122 123 QString CanvasGetGroupName(int group_id); 124 int CanvasGetGroupPortCount(int group_id); 125 QPointF CanvasGetNewGroupPos(bool horizontal=false); 126 QString CanvasGetFullPortName(int port_id); 127 QList<int> CanvasGetPortConnectionList(int port_id); 128 int CanvasGetConnectedPort(int connection_id, int port_id); 129 void CanvasRemoveAnimation(CanvasFadeAnimation* f_animation); 130 void CanvasPostponedGroups(); 131 void CanvasCallback(CallbackAction action, int value1, int value2, QString value_str); 132 void CanvasItemFX(QGraphicsItem* item, bool show, bool destroy=false); 133 void CanvasRemoveItemFX(QGraphicsItem* item); 134 135 // global objects 136 extern Canvas canvas; 137 extern options_t options; 138 extern features_t features; 139 140 END_NAMESPACE_PATCHCANVAS 141 142 #endif // PATCHCANVAS_H 143