QElectroTech  0.8-dev
partarc.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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 
25 
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 };
48  int type() const override { return Type; }
49  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
50 
51  //Name and XML
52  QString name() const override { return(QObject::tr("arc", "element part name")); }
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;
59  void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}
60  void setStartAngle(const int &start_angle) override {AbstractPartEllipse::setStartAngle(start_angle); adjusteHandlerPos();}
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:
82  int m_resize_mode = 1,
84  QPointF m_span_point;
85  QVector<QetGraphicsHandlerItem *> m_handler_vector;
86 };
87 #endif
qetgraphicshandlerutility.h
QPropertyUndoCommand::enableAnimation
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
Definition: qpropertyundocommand.cpp:92
ElementScene::snapToGrid
QPointF snapToGrid(QPointF point)
ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point...
Definition: elementscene.cpp:1270
PartArc::addHandler
void addHandler()
PartArc::addHandler Add handlers for this item.
Definition: partarc.cpp:439
QetGraphicsHandlerItem::Type
@ Type
Definition: qetgraphicshandleritem.h:42
AbstractPartEllipse::setSpanAngle
virtual void setSpanAngle(const int &span_angle)
AbstractPartEllipse::setSpanAngle Returns the span angle of an ellipse segment in 16ths of a degree....
Definition: abstractpartellipse.cpp:163
PartArc::setStartAngle
void setStartAngle(const int &start_angle) override
AbstractPartEllipse::setStartAngle Sets the start angle for an ellipse segment to angle,...
Definition: partarc.h:60
PartArc::removeHandler
void removeHandler()
PartArc::removeHandler Remove the handlers of this item.
Definition: partarc.cpp:470
ElementScene::undoStack
QUndoStack & undoStack()
ElementScene::undoStack.
Definition: elementscene.cpp:603
PartArc::handlerMouseReleaseEvent
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartArc::handlerMouseReleaseEvent.
Definition: partarc.cpp:387
PartArc::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartArc::mouseReleaseEvent Handle mouse release event.
Definition: partarc.cpp:162
abstractpartellipse.h
CustomElementGraphicPart::drawCross
static void drawCross(const QPointF &center, QPainter *painter)
CustomElementGraphicPart::drawCross Draw a cross at pos center.
Definition: customelementgraphicpart.cpp:60
PartArc::~PartArc
~PartArc() override
PartArc::~PartArc Destructor.
Definition: partarc.cpp:42
PartArc::fromXml
void fromXml(const QDomElement &) override
PartArc::fromXml Import the properties of this arc from a xml element.
Definition: partarc.cpp:117
AbstractPartEllipse::m_start_angle
qreal m_start_angle
Definition: abstractpartellipse.h:82
PartArc::shadowShape
QPainterPath shadowShape() const override
Definition: partarc.cpp:145
PartArc::handlerMousePressEvent
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartArc::handlerMousePressEvent.
Definition: partarc.cpp:314
PartArc::adjusteHandlerPos
void adjusteHandlerPos()
PartArc::adjusteHandlerPos.
Definition: partarc.cpp:288
PartArc::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartArc::itemChange.
Definition: partarc.cpp:176
CustomElementGraphicPart::stylesToXml
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
Definition: customelementgraphicpart.cpp:162
PartArc::toXml
const QDomElement toXml(QDomDocument &) const override
PartArc::toXml Export this arc in xml.
Definition: partarc.cpp:98
QPropertyUndoCommand::setNewValue
void setNewValue(const QVariant &new_value)
QPropertyUndoCommand::setNewValue Set the new value of the property (set with redo) to new_value.
Definition: qpropertyundocommand.cpp:83
CustomElementGraphicPart::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: customelementgraphicpart.cpp:1318
AbstractPartEllipse::setRect
virtual void setRect(const QRectF &rect)
AbstractPartEllipse::setRect Sets the item's ellipse geometry to rect. The rectangle's left edge defi...
Definition: abstractpartellipse.cpp:119
PartArc
The PartArc class This class represents an elliptical arc primitive which may be used to compose the ...
Definition: partarc.h:32
PartArc::handlerMouseMoveEvent
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartArc::handlerMouseMoveEvent.
Definition: partarc.cpp:353
PartArc::paint
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartArc::paint Draw this arc.
Definition: partarc.cpp:55
PartArc::m_handler_vector
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition: partarc.h:85
PartArc::name
QString name() const override
Definition: partarc.h:52
CustomElementGraphicPart::stylesFromXml
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
Definition: customelementgraphicpart.cpp:508
QetGraphicsHandlerUtility::mirrorRectForPosAtIndex
static QRectF mirrorRectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::mirrorRectForPosAtIndex Return a rectangle after modification of the point...
Definition: qetgraphicshandlerutility.cpp:139
PartArc::setRect
void setRect(const QRectF &rect) override
AbstractPartEllipse::setRect Sets the item's ellipse geometry to rect. The rectangle's left edge defi...
Definition: partarc.h:59
AbstractPartEllipse::m_span_angle
qreal m_span_angle
Definition: abstractpartellipse.h:83
PartArc::m_span_point
QPointF m_span_point
Definition: partarc.h:84
partarc.h
PartArc::type
int type() const override
Definition: partarc.h:48
QetGraphicsHandlerUtility::pointsForArc
static QVector< QPointF > pointsForArc(const QRectF &rect, qreal start_angle, qreal span_angle)
QetGraphicsHandlerUtility::pointsForArc Return the points for the given arc. The first value in the v...
Definition: qetgraphicshandlerutility.cpp:79
QetGraphicsHandlerUtility::pointsForRect
static QVector< QPointF > pointsForRect(const QRectF &rect)
QetGraphicsHandlerUtility::pointsForRect Return the keys points of the rectangle, stored in a vector....
Definition: qetgraphicshandlerutility.cpp:36
AbstractPartEllipse::sceneTopLeft
virtual QPointF sceneTopLeft() const
AbstractPartEllipse::sceneTopLeft.
Definition: abstractpartellipse.cpp:98
PartArc::xmlName
QString xmlName() const override
Definition: partarc.h:53
elementscene.h
AbstractPartEllipse
The AbstractPartEllipse class This is the base class for all ellipse based item like ellipse,...
Definition: abstractpartellipse.h:40
PartArc::m_undo_command2
QPropertyUndoCommand * m_undo_command2
Definition: partarc.h:81
PartArc::m_undo_command
QPropertyUndoCommand * m_undo_command
Definition: partarc.h:80
qpropertyundocommand.h
PartArc::shape
QPainterPath shape() const override
PartArc::shape.
Definition: partarc.cpp:132
QetGraphicsHandlerUtility::rectForPosAtIndex
static QRectF rectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::rectForPosAtIndex Return a rectangle after modification of the point 'pos'...
Definition: qetgraphicshandlerutility.cpp:106
qetgraphicshandleritem.h
PartArc::PartArc
PartArc(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
PartArc::PartArc Constructor.
Definition: partarc.cpp:31
PartArc::setSpanAngle
void setSpanAngle(const int &span_angle) override
AbstractPartEllipse::setSpanAngle Returns the span angle of an ellipse segment in 16ths of a degree....
Definition: partarc.h:61
QetGraphicsHandlerItem
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition: qetgraphicshandleritem.h:37
CustomElementGraphicPart::m_hovered
bool m_hovered
Definition: customelementgraphicpart.h:323
PartArc::PartArc
PartArc(const PartArc &)
AbstractPartEllipse::rect
QRectF rect
Definition: abstractpartellipse.h:44
PartArc::m_resize_mode
int m_resize_mode
Definition: partarc.h:82
PartArc::m_vector_index
int m_vector_index
Definition: partarc.h:83
SHADOWS_HEIGHT
#define SHADOWS_HEIGHT
Definition: customelementgraphicpart.h:37
CustomElementGraphicPart::color
Color color
Definition: customelementgraphicpart.h:44
PartArc::switchResizeMode
void switchResizeMode()
PartArc::switchResizeMode.
Definition: partarc.cpp:253
CustomElementPart::elementScene
virtual ElementScene * elementScene() const
Definition: customelementpart.cpp:37
PartArc::sceneSelectionChanged
void sceneSelectionChanged()
PartArc::sceneSelectionChanged When the scene selection change, if there are several primitive select...
Definition: partarc.cpp:427
CustomElementGraphicPart::applyStylesToQPainter
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
Definition: customelementgraphicpart.cpp:885
CustomElementGraphicPart::penWeight
qreal penWeight() const
CustomElementGraphicPart::penWeight.
Definition: customelementgraphicpart.cpp:109
AbstractPartEllipse::m_rect
QRectF m_rect
Definition: abstractpartellipse.h:81
PartArc::Type
@ Type
Definition: partarc.h:43
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
QetGraphicsHandlerItem::handlerForPoint
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
Definition: qetgraphicshandleritem.cpp:87
AbstractPartEllipse::setStartAngle
virtual void setStartAngle(const int &start_angle)
AbstractPartEllipse::setStartAngle Sets the start angle for an ellipse segment to angle,...
Definition: abstractpartellipse.cpp:147
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
PartArc::sceneEventFilter
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartArc::sceneEventFilter.
Definition: partarc.cpp:216
QETElementEditor
Definition: qetelementeditor.h:33
CustomElementGraphicPart::drawShadowShape
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...
Definition: customelementgraphicpart.cpp:1240