QElectroTech  0.70
abstractpartellipse.cpp
Go to the documentation of this file.
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 #include "abstractpartellipse.h"
19 
27  CustomElementGraphicPart(editor, parent),
28  m_rect (QRectF(0, 0, 0, 0)),
29  m_start_angle (0),
30  m_span_angle (5760)
31 {}
32 
38 
45 void AbstractPartEllipse::startUserTransformation(const QRectF &initial_selection_rect)
46 {
47  Q_UNUSED(initial_selection_rect)
48  // we keep track of our own rectangle at the moment in scene coordinates too
49  saved_points_.clear();
50  saved_points_ << mapToScene(rect().topLeft()) << mapToScene(rect().bottomRight());
51 }
52 
59 void AbstractPartEllipse::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect)
60 {
61  QList<QPointF> mapped_points = mapPoints(initial_selection_rect, new_selection_rect, saved_points_);
62  setRect(QRectF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1))));
63 }
64 
71 {
72  qreal adjust = (SHADOWS_HEIGHT + penWeight()) / 2;
73  //We add 0.5 because CustomElementGraphicPart::drawShadowShape
74  //draw a shape bigger of 0.5 when pen weight is to 0.
75  if (penWeight() == 0) adjust += 0.5;
76  QRectF r(m_rect.normalized());
77  r.adjust(-adjust, -adjust, adjust, adjust);
78  return(r);
79 }
80 
89  return(mapToScene(rect()).boundingRect());
90 }
91 
97  return(mapToScene(rect().topLeft()));
98 }
99 
104 QRectF AbstractPartEllipse::rect() const {
105  return m_rect;
106 }
107 
116 void AbstractPartEllipse::setRect(const QRectF &rect)
117 {
118  if (rect == m_rect) return;
119  prepareGeometryChange();
120  m_rect = rect;
121 
122  emit rectChanged();
123 }
124 
131  return(rect().isNull());
132 }
133 
141 void AbstractPartEllipse::setStartAngle(const int &start_angle)
142 {
143  if (m_start_angle == start_angle) return;
144  prepareGeometryChange();
145  m_start_angle = start_angle;
146  emit startAngleChanged();
147 }
148 
156 void AbstractPartEllipse::setSpanAngle(const int &span_angle)
157 {
158  if (m_span_angle == span_angle) return;
159  prepareGeometryChange();
160  m_span_angle = span_angle;
161  emit spanAngleChanged();
162 }
QRectF sceneGeometricRect() const override
AbstractPartEllipse::sceneGeometricRect.
void handleUserTransformation(const QRectF &, const QRectF &) override
AbstractPartEllipse::handleUserTransformation Handle the user-induced transformation from initial_sel...
QRectF rect() const
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
virtual void setStartAngle(const int &start_angle)
AbstractPartEllipse::setStartAngle Sets the start angle for an ellipse segment to angle...
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
bool isUseless() const override
AbstractPartEllipse::isUseless.
virtual QPointF sceneTopLeft() const
AbstractPartEllipse::sceneTopLeft.
virtual void setSpanAngle(const int &span_angle)
AbstractPartEllipse::setSpanAngle Returns the span angle of an ellipse segment in 16ths of a degree...
AbstractPartEllipse(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
AbstractPartEllipse::AbstractPartEllipse Constructor.
virtual void setRect(const QRectF &rect)
AbstractPartEllipse::setRect Sets the item&#39;s ellipse geometry to rect. The rectangle&#39;s left edge defi...
~AbstractPartEllipse() override
AbstractPartEllipse::~AbstractPartEllipse Destructor.
QRectF boundingRect() const override
AbstractPartEllipse::boundingRect Bounding rectangle this part can fit into.
#define SHADOWS_HEIGHT
QList< QPointF > saved_points_
qreal penWeight() const
CustomElementGraphicPart::penWeight.
void startUserTransformation(const QRectF &) override
AbstractPartEllipse::startUserTransformation Start the user-induced transformation, provided this primitive is contained within the initial_selection_rect bounding rectangle.