2007-12-01 10:47:15 +00:00
|
|
|
/*
|
|
|
|
Copyright 2006-2007 Xavier Guerrin
|
|
|
|
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"
|
|
|
|
#include "ellipseeditor.h"
|
|
|
|
|
2007-08-25 03:43:05 +00:00
|
|
|
PartEllipse::PartEllipse(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart(editor) {
|
2007-06-30 17:41:07 +00:00
|
|
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
2007-08-25 03:43:05 +00:00
|
|
|
informations = new EllipseEditor(elementEditor(), this);
|
2007-11-07 20:23:24 +00:00
|
|
|
informations -> setElementTypeName(name());
|
2007-06-30 17:41:07 +00:00
|
|
|
style_editor -> appendWidget(informations);
|
2007-11-07 20:23:24 +00:00
|
|
|
style_editor -> setElementTypeName(name());
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
|
|
|
|
applyStylesToQPainter(*painter);
|
|
|
|
QPen t = painter -> pen();
|
|
|
|
if (isSelected()) {
|
|
|
|
t.setColor(Qt::red);
|
|
|
|
painter -> setPen(t);
|
|
|
|
}
|
|
|
|
painter -> drawEllipse(rect());
|
|
|
|
if (isSelected()) {
|
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
|
|
|
painter -> setPen((painter -> brush().color() == QColor(Qt::black) && painter -> brush().isOpaque()) ? Qt::yellow : Qt::blue);
|
|
|
|
QPointF center = rect().center();
|
|
|
|
painter -> drawLine(QLineF(center.x() - 2.0, center.y(), center.x() + 2.0, center.y()));
|
|
|
|
painter -> drawLine(QLineF(center.x(), center.y() - 2.0, center.x(), center.y() + 2.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const {
|
|
|
|
QDomElement xml_element = xml_document.createElement("ellipse");
|
|
|
|
QPointF top_left(sceneTopLeft());
|
|
|
|
xml_element.setAttribute("x", top_left.x());
|
|
|
|
xml_element.setAttribute("y", top_left.y());
|
|
|
|
xml_element.setAttribute("width", rect().width());
|
|
|
|
xml_element.setAttribute("height", rect().height());
|
|
|
|
stylesToXml(xml_element);
|
|
|
|
return(xml_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PartEllipse::fromXml(const QDomElement &qde) {
|
|
|
|
stylesFromXml(qde);
|
|
|
|
setRect(
|
|
|
|
QRectF(
|
|
|
|
mapFromScene(
|
|
|
|
qde.attribute("x", "0").toDouble(),
|
|
|
|
qde.attribute("y", "0").toDouble()
|
|
|
|
),
|
|
|
|
QSizeF(
|
|
|
|
qde.attribute("width", "0").toDouble(),
|
|
|
|
qde.attribute("height", "0").toDouble()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-08-25 03:43:05 +00:00
|
|
|
void PartEllipse::setProperty(const QString &property, const QVariant &value) {
|
|
|
|
CustomElementGraphicPart::setProperty(property, value);
|
|
|
|
if (!value.canConvert(QVariant::Double)) return;
|
|
|
|
if (property == "x") {
|
|
|
|
QRectF current_rect = rect();
|
|
|
|
QPointF current_pos = mapToScene(current_rect.center());
|
|
|
|
setRect(current_rect.translated(value.toDouble() - current_pos.x(), 0.0));
|
|
|
|
} else if (property == "y") {
|
|
|
|
QRectF current_rect = rect();
|
|
|
|
QPointF current_pos = mapToScene(current_rect.center());
|
|
|
|
setRect(current_rect.translated(0.0, value.toDouble() - current_pos.y()));
|
|
|
|
} else if (property == "diameter_h") {
|
|
|
|
qreal new_width = qAbs(value.toDouble());
|
|
|
|
QRectF current_rect = rect();
|
|
|
|
current_rect.translate((new_width - current_rect.width()) / -2.0, 0.0);
|
|
|
|
current_rect.setWidth(new_width);
|
|
|
|
setRect(current_rect);
|
|
|
|
} else if (property == "diameter_v") {
|
|
|
|
qreal new_height = qAbs(value.toDouble());
|
|
|
|
QRectF current_rect = rect();
|
|
|
|
current_rect.translate(0.0, (new_height - current_rect.height()) / -2.0);
|
|
|
|
current_rect.setHeight(new_height);
|
|
|
|
setRect(current_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant PartEllipse::property(const QString &property) {
|
|
|
|
// appelle la methode property de CustomElementGraphicpart pour les styles
|
|
|
|
QVariant style_property = CustomElementGraphicPart::property(property);
|
|
|
|
if (style_property != QVariant()) return(style_property);
|
|
|
|
|
|
|
|
if (property == "x") {
|
|
|
|
return(mapToScene(rect().center()).x());
|
|
|
|
} else if (property == "y") {
|
|
|
|
return(mapToScene(rect().center()).y());
|
|
|
|
} else if (property == "diameter_h") {
|
|
|
|
return(rect().width());
|
|
|
|
} else if (property == "diameter_v") {
|
|
|
|
return(rect().height());
|
|
|
|
}
|
|
|
|
return(QVariant());
|
|
|
|
}
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
QVariant PartEllipse::itemChange(GraphicsItemChange change, const QVariant &value) {
|
|
|
|
if (scene()) {
|
|
|
|
if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) {
|
|
|
|
informations -> updateForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(QGraphicsEllipseItem::itemChange(change, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF PartEllipse::sceneTopLeft() const {
|
|
|
|
return(mapToScene(rect().topLeft()));
|
|
|
|
}
|