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