00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef SLATEWINDOW_H
00022 #define SLATEWINDOW_H
00023 
00024 #include <QMainWindow>
00025 #include <QCloseEvent>
00026 #include <QPair>
00027 #include <QAction>
00028 #include <iostream>
00029 
00030 
00031 class QGraphicsItem;
00032 class QGraphicsScene;
00033 class QGraphicsView;
00034 class Link;
00035 class Node;
00036 class GroupNode;
00037 class ItemNode;
00038 class ItemProperties;
00039 class SlateView;
00040 class QVDesignerGUI;
00041 
00042 #ifndef DOXYGEN_IGNORE_THIS
00043 
00044 
00045 class LinkInfo
00046 {
00047 public:
00049         LinkInfo(): node(0), prop(""), input(false) {  }
00050 
00051         LinkInfo(uint _node, QString _prop, bool _input): node(_node), prop(_prop), input(_input) { }
00052 
00053         bool operator==(const LinkInfo &other) const { return (node == other.getNode() && prop == other.getProp() && input == other.getInput()); }
00054 
00055         uint getNode() const { return node; }
00056 
00057         void setNode(uint _node) { node = _node; }
00058 
00059         QString getProp() const { return prop; }
00060 
00061         void setProp(QString _prop) { prop = _prop; }
00062 
00063         bool getInput() const { return input; }
00064 
00065         void setInput(bool _input) { input = _input; }
00066 
00067 protected:
00068         uint node;
00069         QString prop;
00070         bool input;
00071 };
00072 
00073 class GroupInfo
00074 {
00075 public:
00076         GroupInfo(): id(0), name(""), nodes(), subgroups(), visibleNodeLinks(), visibleSubgroupLinks(), pos(0.0, 0.0) { }
00077 
00078         GroupInfo(uint _id, QString _name): id(_id), name(_name), nodes(), subgroups(), visibleNodeLinks(), visibleSubgroupLinks(), pos(0.0, 0.0) { }
00079 
00080         uint getId() const { return id; }
00081 
00082         QString getName() const { return name; }
00083 
00084         void addNode(uint node) { if (!nodes.contains(node)) nodes.append(node); }
00085 
00086         void addSubgroup(uint subgroup) { if (!subgroups.contains(subgroup)) subgroups.append(subgroup); }
00087 
00088         void delSubgroup(uint subgroup) { subgroups.removeAll(subgroup); }
00089 
00090         void addNodeLink(LinkInfo link) { if (!visibleNodeLinks.contains(link)) visibleNodeLinks.append(link); }
00091 
00092         void addSubgroupLink(LinkInfo link) { if (!visibleSubgroupLinks.contains(link)) visibleSubgroupLinks.append(link); }
00093 
00094         void delNode(uint node) {
00095                 int pos = nodes.indexOf(node);
00096                 if (pos > 0) nodes.removeAt(pos);
00097         }
00098 
00099         void delNodeLink(LinkInfo link) {
00100                 int pos = visibleNodeLinks.indexOf(link);
00101                 if (pos > 0) visibleNodeLinks.removeAt(pos);
00102         }
00103 
00104         void delSubgroupLink(LinkInfo link) {
00105                 int pos = visibleSubgroupLinks.indexOf(link);
00106                 if (pos > 0) visibleSubgroupLinks.removeAt(pos);
00107         }
00108 
00109         QList<uint> getNodes() const { return nodes; }
00110 
00111         QList<uint> getSubgroups() const { return subgroups; }
00112 
00113         QList<LinkInfo> getNodeLinks() const { return visibleNodeLinks; }
00114 
00115         QList<LinkInfo> getSubgroupLinks() const { return visibleSubgroupLinks; }
00116 
00117         void setPos(QPointF _pos) { pos = _pos; }
00118 
00119         void setName(QString _name) { name = _name; }
00120 
00121         QPointF getPos() const { return pos; }
00122 
00123         void setAbstract(bool abs) { abstract = abs; }
00124 
00125         bool getAbstract() const {  return abstract; }
00126 
00127         void updateNodeId(uint oldId, uint newId) {
00128                 int pos = nodes.indexOf(oldId);
00129                 if (pos >= 0) {
00130                         nodes.removeAt(pos);
00131                         nodes.append(newId);
00132                 }
00133                 for (QList<LinkInfo>::iterator it = visibleNodeLinks.begin(); it != visibleNodeLinks.end(); it++) { 
00134                         if ((*it).getNode() == oldId)
00135                                 (*it).setNode(newId);
00136                 }
00137         }
00138 
00139         void updateSubgroupId(uint oldId, uint newId) {
00140                 int pos = subgroups.indexOf(oldId);
00141                 if (pos >= 0) {
00142                         subgroups.removeAt(pos);
00143                         subgroups.append(newId);
00144                 }
00145                 for (QList<LinkInfo>::iterator it = visibleSubgroupLinks.begin(); it != visibleSubgroupLinks.end(); it++) { 
00146                         if ((*it).getNode() == oldId)
00147                                 (*it).setNode(newId);
00148                 }
00149         }
00150 
00151 protected:
00152         uint id;
00153         QString name;
00154         QList<uint> nodes;
00155         QList<uint> subgroups;
00156         QList<LinkInfo> visibleNodeLinks;
00157         QList<LinkInfo> visibleSubgroupLinks;
00158         QPointF pos;
00159         bool abstract;
00160 };
00161 
00162 
00163 
00164 class SlateWindow : public QMainWindow
00165 {
00166     Q_OBJECT
00167 
00168 public:
00169     SlateWindow(QVDesignerGUI *desig, QWidget * parent = 0);
00170         bool createLink(Node *fromNode, int fromPoint, Node *toNode, int toPoint);
00171         void addLinkLine(uint fromId, QString fromProp, uint toId, QString toProp, bool sinc, bool sequential);
00172         void delLinkLine(uint fromId, QString fromProp, uint toId, QString toProp);
00173         void addItemNode(QString type, QString name, uint id, ItemProperties *item, uint lastId = 0);
00174         void delItemNode(uint id);
00175         void addProperty(uint id, QString propName, int type, bool in, bool out);
00176         void delProperty(uint id, QString propName);
00177         void closeEvent(QCloseEvent *event);
00178         void includeItemType(QString itemType);
00179         void arrangeItems();
00180         void clearSelection();
00181         bool isSelected(QGraphicsItem *item);
00182         void setName(Node *item, QString name);
00183         void setItemName(uint id, QString name);
00184         QPointF getNodePos(uint id) const;
00185         bool moveNode(uint id, QPointF pos);
00186         QList<GroupInfo> getGroups();
00187         void eraseGroups();
00188         uint createGroup(GroupInfo group); 
00189 
00190 public slots:
00191     void showProperties();
00192         void showProperties(Node *node);
00193         void showMessage(QString message);
00194 
00195 private slots:
00196     void del();
00197         void join();
00198     void bringToFront();
00199     void sendToBack();
00200     void updateActions();
00201         void insertItem(QString type);
00202         void run();
00203         void stop();
00204         bool saveAs();
00205         bool open();
00206         bool exportAs();
00207 
00208 signals:
00210         void closed();
00211 
00212 private:
00213     typedef QPair<Node *, Node *> NodePair;
00214 
00215     QPoint startPos;
00216 
00217     void createMenus();
00218     void createToolBars();
00219     void setZValue(int z);
00220     void setupNode(Node *node);
00221     Node *selectedNode() const;
00222     Link *selectedLink() const;
00223     NodePair selectedNodePair() const;
00224     QList<QGraphicsItem *> selectedNodeGroup() const;
00225         QList<QGraphicsItem *> onlyParents(QList<QGraphicsItem *> items) const;
00226     bool saveFile(const QString &fileName, bool xmlFile);
00227     bool exportFile(const QString &fileName);
00228         int precursors(Node *node);
00229 
00230     QMenu *fileMenu;
00231     QMenu *editMenu;
00232         QMenu *insertMenu;
00233         QMenu *insertUserSubmenu;
00234         QList<QMenu *> insertSubmenus;
00235     QToolBar *editToolBar;
00236     QAction *exitAction;
00237     QAction *addSLinkAction;
00238     QAction *addALinkAction;
00239     QAction *addQLinkAction;
00240         QActionGroup *linkGroup;
00241     QAction *joinAction;
00242     QAction *deleteAction;
00243     QAction *bringToFrontAction;
00244     QAction *sendToBackAction;
00245     QAction *propertiesAction;
00246         QAction *runAction;
00247         QAction *stopAction;
00248         QAction *exportAction;
00249         QAction *saveAsAction;
00250         QAction *openAction;
00251 
00252         QStatusBar *statusbar;
00253 
00254     QGraphicsScene *scene;
00255     SlateView *view;
00256         QVDesignerGUI *designer;
00257 
00258     int minZ;
00259     int maxZ;
00260     int seqNumber;
00261 
00262         QMap<uint, Node *> insertNodes;
00263         QMap<uint, QPointF> insertNodesPos;
00264         QMap<QString, Link *> insertLinks;
00265 
00266         QMap<Node *, GroupInfo> createdGroupInfos;
00267         QMap<uint, GroupNode *> createdGroups;
00268 };
00269 
00270 #endif
00271 #endif