2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2015-02-20 14:56:22 +00:00
|
|
|
Copyright 2006-2015 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "partellipse.h"
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2015-02-09 08:57:40 +00:00
|
|
|
* @brief PartEllipse::PartEllipse
|
|
|
|
* Constructor
|
|
|
|
* @param editor : QETElementEditor of this part
|
|
|
|
* @param parent : parent item
|
|
|
|
*/
|
|
|
|
PartEllipse::PartEllipse(QETElementEditor *editor, QGraphicsItem *parent) :
|
|
|
|
AbstractPartEllipse(editor, parent)
|
|
|
|
{}
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2015-02-09 08:57:40 +00:00
|
|
|
/**
|
|
|
|
* @brief PartEllipse::~PartEllipse
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
PartEllipse::~PartEllipse() {}
|
2007-12-05 21:16:01 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-09 08:57:40 +00:00
|
|
|
* @brief PartEllipse::paint
|
|
|
|
* Draw this ellpise
|
|
|
|
* @param painter
|
|
|
|
* @param options
|
|
|
|
* @param widget
|
|
|
|
*/
|
|
|
|
void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
|
|
|
|
{
|
2009-11-22 16:12:22 +00:00
|
|
|
Q_UNUSED(widget);
|
2007-06-30 17:41:07 +00:00
|
|
|
applyStylesToQPainter(*painter);
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
QPen t = painter -> pen();
|
2009-04-18 18:54:25 +00:00
|
|
|
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
2015-02-09 08:57:40 +00:00
|
|
|
|
|
|
|
if (isSelected())
|
2007-06-30 17:41:07 +00:00
|
|
|
t.setColor(Qt::red);
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2009-04-18 18:54:25 +00:00
|
|
|
painter -> setPen(t);
|
2007-06-30 17:41:07 +00:00
|
|
|
painter -> drawEllipse(rect());
|
2015-02-09 08:57:40 +00:00
|
|
|
|
|
|
|
if (m_hovered)
|
|
|
|
drawShadowShape(painter);
|
|
|
|
|
|
|
|
if (isSelected())
|
|
|
|
drawCross(m_rect.center(), painter);
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2015-02-09 08:57:40 +00:00
|
|
|
* @brief PartEllipse::toXml
|
|
|
|
* Export this ellipse in xml
|
|
|
|
* @param xml_document : Xml document to use for create the xml element.
|
|
|
|
* @return : an xml element that describe this ellipse
|
|
|
|
*/
|
|
|
|
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
|
|
|
|
{
|
2013-02-11 21:45:51 +00:00
|
|
|
QDomElement xml_element;
|
2015-02-09 08:57:40 +00:00
|
|
|
if (qFuzzyCompare(rect().width(), rect().height()))
|
|
|
|
{
|
2013-02-11 21:45:51 +00:00
|
|
|
xml_element = xml_document.createElement("circle");
|
|
|
|
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
|
2015-02-09 08:57:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 21:45:51 +00:00
|
|
|
xml_element = xml_document.createElement("ellipse");
|
|
|
|
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
|
|
|
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
|
|
|
}
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
QPointF top_left(sceneTopLeft());
|
2008-08-23 19:27:14 +00:00
|
|
|
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
|
|
|
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
stylesToXml(xml_element);
|
2015-02-09 08:57:40 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
return(xml_element);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2015-02-09 08:57:40 +00:00
|
|
|
* @brief PartEllipse::fromXml
|
|
|
|
* Import the properties of this ellipse from a xml element.
|
|
|
|
* @param qde : Xml document to use.
|
|
|
|
*/
|
|
|
|
void PartEllipse::fromXml(const QDomElement &qde)
|
|
|
|
{
|
2007-06-30 17:41:07 +00:00
|
|
|
stylesFromXml(qde);
|
2013-02-11 21:45:51 +00:00
|
|
|
qreal width, height;
|
2015-02-09 08:57:40 +00:00
|
|
|
|
|
|
|
if (qde.tagName() == "ellipse")
|
|
|
|
{
|
2013-02-11 21:45:51 +00:00
|
|
|
width = qde.attribute("width", "0").toDouble();
|
|
|
|
height = qde.attribute("height", "0").toDouble();
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
2015-02-09 08:57:40 +00:00
|
|
|
else
|
|
|
|
width = height = qde.attribute("diameter", "0").toDouble();
|
2013-02-08 22:05:12 +00:00
|
|
|
|
2015-02-09 08:57:40 +00:00
|
|
|
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
|
|
|
|
qde.attribute("y", "0").toDouble()),
|
|
|
|
QSizeF(width, height));
|
2013-02-08 22:05:12 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 19:40:08 +00:00
|
|
|
/**
|
2015-02-09 08:57:40 +00:00
|
|
|
* @brief PartEllipse::shape
|
|
|
|
* @return the shape of this item
|
|
|
|
*/
|
|
|
|
QPainterPath PartEllipse::shape() const
|
|
|
|
{
|
|
|
|
QPainterPath shape;
|
|
|
|
shape.addEllipse(m_rect);
|
|
|
|
|
|
|
|
QPainterPathStroker pps;
|
|
|
|
pps.setWidth(penWeight());
|
|
|
|
|
|
|
|
return (pps.createStroke(shape));
|
2008-01-07 19:40:08 +00:00
|
|
|
}
|