mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@94 bfdf4180-ca20-0410-9c96-a3a8aa849046
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
#include "partellipse.h"
|
|
#include "ellipseeditor.h"
|
|
|
|
PartEllipse::PartEllipse(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart() {
|
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
informations = new EllipseEditor(this);
|
|
style_editor -> appendWidget(informations);
|
|
}
|
|
|
|
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()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
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()));
|
|
}
|