1 /*
2 	Copyright 2006-2019 The QElectroTech Team
3 	This file is part of QElectroTech.
4 
5 	QElectroTech 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 	(at your option) any later version.
9 
10 	QElectroTech 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 	You should have received a copy of the GNU General Public License
16 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ELEMENT_VIEW_H
19 #define ELEMENT_VIEW_H
20 #include <QGraphicsView>
21 #include "elementscene.h"
22 
23 /**
24 	This class provides a widget to render an ElementScene instance, i.e. the
25 	edition class for electrical elements.
26 */
27 class ElementView : public QGraphicsView {
28 	Q_OBJECT
29 	friend class PastePartsCommand;
30 
31 	// constructors, destructor
32 	public:
33 	ElementView(ElementScene *, QWidget * = nullptr);
34 	~ElementView() override;
35 
36 	private:
37 	ElementView(const ElementView &);
38 
39 	// methods
40 	public:
41 	ElementScene *scene() const;
42 	void setScene(ElementScene *);
43 	QRectF viewedSceneRect() const;
44 
45 	protected:
46 	void mousePressEvent(QMouseEvent *) override;
47 	void mouseMoveEvent(QMouseEvent *) override;
48 	void mouseReleaseEvent(QMouseEvent *) override;
49 	bool gestureEvent(QGestureEvent *event);
50 	bool event(QEvent *event) override;
51 	void wheelEvent(QWheelEvent *) override;
52 	void drawBackground(QPainter *, const QRectF &) override;
53 
54 	private:
55 	QRectF applyMovement(const QRectF &, const QPointF &);
56 
57 	public slots:
58 	void setVisualisationMode();
59 	void setSelectionMode();
60 	void zoomIn();
61 	void zoomOut();
62 	void zoomInSlowly();
63 	void zoomOutSlowly();
64 	void zoomFit();
65 	void zoomReset();
66 	void adjustSceneRect();
67 	void resetSceneRect ();
68 	void cut();
69 	void copy();
70 	void paste();
71 	void pasteInArea();
72 
73 	signals:
74 	/// Signal emitted after the mode changed
75 	void modeChanged();
76 
77 	private slots:
78 	void getPasteArea(const QRectF &);
79 	ElementContent pasteAreaDefined(const QRectF &);
80 	ElementContent paste(const QPointF &);
81 	ElementContent paste(const QDomDocument &, const QPointF &);
82 	ElementContent pasteWithOffset(const QDomDocument &);
83 
84 	// attributes
85 	private:
86 	ElementScene *m_scene;
87 	QString to_paste_in_area_;
88 	int offset_paste_count_;
89 	QPointF start_top_left_corner_;
90 	QPointF reference_view_;
91 	bool gestures() const;
92 };
93 #endif
94