1 // Thomas Nagy 2007-2021 GPLV3
2 
3 
4 #ifndef BOX_VIEW_H
5 #define BOX_VIEW_H
6 
7 #include <QUrl>
8 #include <QGraphicsView>
9 #include <QList>
10 #include <QPoint>
11 #include "data_item.h"
12 #include "con.h"
13 
14 class QActionGroup;
15 class QMenu;
16 class connectable;
17 class box_item;
18 class box_link;
19 class data_link;
20 class data_box;
21 class diagram_item;
22 class sem_mediator;
23 class box_view : public QGraphicsView
24 {
25 	Q_OBJECT
26 	public:
27 		box_view(QWidget*, sem_mediator *);
28 		~box_view();
29 
30 		void clear_diagram();
31 
32 		QList<box_link*> m_oLinks;
33 
34 		QMap<int, connectable*> m_oItems;
35 
36 
37 		QPointF m_oLastPoint;
38 		QPointF m_oLastMovePoint;
39 		QPoint m_oScrollPoint;
40 		bool m_bPressed;
41 
42 		QPointF m_oOffsetPoint;
43 
44 		void check_canvas_size();
45 
46 		QMenu* m_oMenu;
47 		//QMenu* m_oWidthMenu;
48 		//QMenu* m_oStyleMenu;
49 		QMenu* m_oAddBoxMenu;
50 		QMenu* m_oTextAlignMenu;
51 		QMenu* m_oAlignMenu;
52 		QMenu* m_oSizeMenu;
53 		QMenu* m_oFileMenu;
54 		QMenu* m_oColorMenu;
55 
56 		QAction *m_oAddItemAction;
57 		QAction *m_oAddLabel;
58 		QAction *m_oAddComponent;
59 		QAction *m_oAddRectangle;
60 		QAction *m_oAddActor;
61 		QAction *m_oAddCloud;
62 		QAction *m_oAddUsecase;
63 		QAction *m_oAddNode;
64 		QAction *m_oAddDotStart;
65 		QAction *m_oAddDotEnd;
66 		QAction *m_oAddDecision;
67 		QAction *m_oAddParallelHorizontal;
68 		QAction *m_oAddParallelVertical;
69 		QAction *m_oAddMatrix;
70 		QAction *m_oAddFrame;
71 		QAction *m_oAddClass;
72 		QAction *m_oAddEntity;
73 		QAction *m_oAddDatabase;
74 		QAction *m_oAddSequence;
75 		QAction *m_oAddPipe;
76 		QAction *m_oFileExport;
77 		QAction *m_oFileImport;
78 		QAction *m_oCopyToClipboard;
79 
80 		QAction *m_oPropertiesAction;
81 		QAction *m_oDeleteAction;
82 		QAction *m_oColorAction;
83 		QAction *m_oMoveUpAction;
84 		QAction *m_oMoveDownAction;
85 
86 		void focusInEvent(QFocusEvent *);
87 		void focusOutEvent(QFocusEvent *);
88 
89 		void enable_menu_actions(); // like check_actions, but only for the popup menu
90 
91 		int m_iId; // the item this diagram belongs to
92 
93 		void sync_view();
94 		void from_string(const QString &);
95 		void resizeEvent(QResizeEvent*);
96 
97 		sem_mediator *m_oMediator;
98 
99 		box_link *m_oCurrent;
100 
101 		int m_bScroll;
102 
103 		QActionGroup *m_oWidthGroup;
104 		QActionGroup *m_oStyleGroup;
105 		QActionGroup *m_oTextAlignGroup;
106 		QActionGroup *m_oAlignGroup;
107 		QActionGroup *m_oSizeGroup;
108 
109 		void keyPressEvent(QKeyEvent *i_oEvent);
110 		void keyReleaseEvent(QKeyEvent *i_oEvent);
111 
112 		void mousePressEvent(QMouseEvent *);
113 		void mouseMoveEvent(QMouseEvent*);
114 		void mouseReleaseEvent(QMouseEvent*);
115 		void mouseDoubleClickEvent(QMouseEvent*);
116 		void wheelEvent(QWheelEvent*);
117 
118 		//void edit_off();
119 
120 		int next_seq();
121 		int num_seq;
122 
123 		const QPixmap getPix(int i_iId);
124 		QRectF drawThumb(QPainter* i_oPainter, QRectF& l_o, int m_iId);
125 
126 		void message(const QString &, int);
127 		bool m_bDisableGradient;
128 		bool m_bShowFileMenu;
129 		void init_menu();
130 		QUrl m_oCurrentUrl;
131 
132 		int batch_print_map(const QUrl& i_oUrl, QPair<int, int> & p);
133 		bool import_from_file(const QUrl& l_o);
134 		void export_fig_size();
135 		QRectF visibleRect();
136 
137 	public slots:
138 		void change_colors(QAction* i_oAct);
139 		void enable_actions(); // used on focus in
140 		void fit_zoom();
141 		void slot_delete();
142 		void slot_add_item();
143 		void slot_edit_properties();
144 		void slot_text_align();
145 		void slot_align();
146 		void slot_size();
147 
148 		void slot_move_up();
149 		void slot_move_down();
150 
151 		void slot_penstyle();
152 		void slot_penwidth();
153 
154 		void slot_add_element();
155 		void slot_print();
156 
157 		void notify_focus(void* ptr);
158 		void notify_add_item(int);
159 		void notify_add_box(int, int);
160 		void notify_del_box(int, int);
161 		void notify_edit_box(int, int);
162 		void notify_link_box(int id, data_link *link);
163 		void notify_unlink_box(int id, data_link* link);
164 		void notify_box_props(int id, const QList<diagram_item*>&);
165 		void notify_pos_box(int, const QList<data_box*>&);
166 		void notify_size_box(int, const QList<data_box*>&);
167 		void notify_text_align(int, const QList<data_box>&);
168 		void notify_change_link_box(int id, data_link*link);
169 		void notify_change_properties(void *);
170 		void notify_sequence_box(int, int);
171 
172 		void notify_select(const QList<int>& unsel, const QList<int>& sel);
173 		void notify_export_item(int);
174 
175 		bool slot_import_from_file();
176 		bool slot_export_to_file();
177 		bool slot_save();
178 		void slot_copy_picture();
179 
180 	signals:
181 		void sig_message(const QString &, int);
182 		void sig_Url(const QUrl&);
183 };
184 
185 #endif
186 
187