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 PART_ELLIPSE_H
19 #define PART_ELLIPSE_H
20 
21 #include "abstractpartellipse.h"
22 
23 class QPropertyUndoCommand;
24 
25 /**
26  * @brief The PartEllipse class
27  * This class represents an ellipse primitive which may be used to compose the
28  * drawing of an electrical element within the element editor.
29  */
30 class PartEllipse : public  AbstractPartEllipse
31 {
32 		Q_OBJECT
33 
34 		// constructors, destructor
35 	public:
36 		PartEllipse(QETElementEditor *editor, QGraphicsItem * parent = nullptr);
37 		~PartEllipse() override;
38 
39 	private:
40 		PartEllipse(const PartEllipse &);
41 
42 		// methods
43 	public:
44 		enum { Type = UserType + 1103 };
45 			/**
46 			 * Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartEllipse.
47 			 * @return the QGraphicsItem type
48 			 */
type()49 		int type() const override { return Type; }
50 		void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
51 
52 			//Name and XML
name()53 		QString name()    const override { return(QObject::tr("ellipse", "element part name")); }
xmlName()54 		QString xmlName() const override { return(QString("ellipse")); }
55 		const QDomElement toXml   (QDomDocument &) const override;
56 		void              fromXml (const QDomElement &) override;
57 		QPainterPath shape() const override;
58 		QPainterPath shadowShape() const override;
setRect(const QRectF & rect)59 		void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}
60 
61 	protected:
62 		void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
63 		QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
64 		bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
65 
66 	private:
67 		void switchResizeMode();
68 		void adjusteHandlerPos();
69 		void handlerMousePressEvent   (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
70 		void handlerMouseMoveEvent    (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
71 		void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
72 		void sceneSelectionChanged ();
73 
74 		void addHandler();
75 		void removeHandler();
76 
77 	private:
78 		QPropertyUndoCommand *m_undo_command;
79 		int m_resize_mode = 1,
80 			m_vector_index = -1;
81 };
82 #endif
83