roviz  0.7
Code Documentation of roviz
item_scene.h
1 #ifndef ITEM_SCENE_H
2 #define ITEM_SCENE_H
3 
4 #include <QGraphicsScene>
5 #include <QDomDocument>
6 
7 #include "appcore.h"
8 
9 class ProjectGui;
10 class ItemOutput;
11 class ItemInput;
12 
13 class ITEMFRAMEWORK_TEST_EXPORT ItemScene : public QGraphicsScene
14 {
15  Q_OBJECT
16 
17 public:
18  explicit ItemScene(QSharedPointer<ProjectGui> projectGui, QObject* parent = 0);
19  ~ItemScene();
20 
26  bool loadFromXml(QDomElement& dom);
27 
34  bool saveToXml(QDomDocument& document, QDomElement& xml) const;
35 
39  void resetBounding();
40 
44  void paste();
45 
50  QList<QGraphicsItem*> copyableItems() const;
51 
57  static QList<QGraphicsItem*> copyableItems(QList<QGraphicsItem*> itms);
58 
62  void cut();
63 
67  void copy() const;
68 
72  void createTemplate();
73 
78  void copy(QList<QGraphicsItem*> itms) const;
79 
83  QSharedPointer<ProjectGui> projectGui() const;
84 
89  QPixmap createPixmap(QDomDocument const& itemsDocument);
90 
96  QPixmap createPixmap(QList<QGraphicsItem*> items, const QRectF& bounding) const;
97 
98 protected:
99  void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent);
100  void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent);
101  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent);
102  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
103  void keyPressEvent(QKeyEvent* event);
104  void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
105  void dropEvent(QGraphicsSceneDragDropEvent* event);
106  void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
107 
108 signals:
109  void sceneRealChanged();
110  void loadingProgress(const int progress, const QString& loadcomment = "", const QString& loadinfo = "Loading Project");
111 
112 private:
113  bool notesInInsertMode();
114  void deleteItems(QList<QGraphicsItem*> items);
115  void insertItem(QString const& name, QPointF const& position);
116 
117  void updateConnectionLine();
118  void updateBoundingRect();
119 
120  bool startMove(QGraphicsSceneMouseEvent* event);
121  bool startConnection(QGraphicsSceneMouseEvent* mouseEvent);
122  qreal distance(const QPointF& a, const QPointF& b) const;
123 
124  void paintItem(QGraphicsItem* item, QPainter& painter, QStyleOptionGraphicsItem& options) const;
125 
126  QRectF calculateBoundingBox(QList<QGraphicsItem const*> items, bool ignoreConnectors = false) const;
127  QList<QGraphicsItem*> readItems(QDomDocument const& document, bool shouldConnectIO = true);
128  QList<QGraphicsItem*> readItems(class QMimeData const& mimeData, char const* const mimeType, char const* const docType);
129 
130  void insertItems(QList<QGraphicsItem*> items, const QPointF& scenePos, const QRectF& boundingBox);
131  void insertTemplate(class QMimeData const* const mimeData, QPointF const& position = {});
132 
133  QHash<QString, int> _copyCountHash;
134  QSharedPointer<ProjectGui> _projectGui;
135  QPointF _startPoint;
136  QPointF _endPoint;
137  bool _inConnectionMode = false;
138  bool _startItemIsInput;
139  bool _recalculateBoundingRect = true;
140  bool _inMovingMode = false;
141 
142  bool _reversed = false;
143  ItemInput* _input = nullptr;
144  ItemOutput* _output = nullptr;
145 
146  QGraphicsLineItem* _connectionLine = nullptr;
147  int _type;
148  QRectF _sceneRect;
149  QPointF _mouseItemDiff;
150 };
151 
152 #endif // ITEM_SCENE_H
The ItemOutput class represents an output that belongs to an item.
Definition: item_output.h:28
The ItemInput class represents an input that belongs to an item.
Definition: item_input.h:28
Definition: item_scene.h:13
Definition: project_gui.h:22