mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-24 03:10:52 +01:00
Element editor : add rounded rect
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5444 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -67,6 +67,7 @@ ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
|
|||||||
|
|
||||||
v_layout -> addWidget(style_);
|
v_layout -> addWidget(style_);
|
||||||
v_layout -> addLayout(grid);
|
v_layout -> addLayout(grid);
|
||||||
|
v_layout->addStretch();
|
||||||
|
|
||||||
updateForm();
|
updateForm();
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ EllipseEditor::EllipseEditor(QETElementEditor *editor, PartEllipse *ellipse, QWi
|
|||||||
|
|
||||||
v_layout -> addWidget(style_);
|
v_layout -> addWidget(style_);
|
||||||
v_layout -> addLayout(grid);
|
v_layout -> addLayout(grid);
|
||||||
|
v_layout->addStretch();
|
||||||
|
|
||||||
activeConnections(true);
|
activeConnections(true);
|
||||||
updateForm();
|
updateForm();
|
||||||
|
|||||||
@@ -28,16 +28,13 @@
|
|||||||
* @param parent parent item
|
* @param parent parent item
|
||||||
*/
|
*/
|
||||||
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
|
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||||
CustomElementGraphicPart(editor, parent),
|
CustomElementGraphicPart(editor, parent)
|
||||||
m_undo_command(nullptr)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartRectangle::~PartRectangle
|
* @brief PartRectangle::~PartRectangle
|
||||||
*/
|
*/
|
||||||
PartRectangle::~PartRectangle()
|
PartRectangle::~PartRectangle() {
|
||||||
{
|
|
||||||
if(m_undo_command) delete m_undo_command;
|
|
||||||
removeHandler();
|
removeHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +61,8 @@ void PartRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
|||||||
if (!rect().width() || !rect().height())
|
if (!rect().width() || !rect().height())
|
||||||
t.setWidth(0);
|
t.setWidth(0);
|
||||||
|
|
||||||
painter -> setPen(t);
|
painter->setPen(t);
|
||||||
painter -> drawRect(rect());
|
painter->drawRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||||
|
|
||||||
if (m_hovered)
|
if (m_hovered)
|
||||||
drawShadowShape(painter);
|
drawShadowShape(painter);
|
||||||
@@ -88,6 +85,20 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
|
|||||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||||
xml_element.setAttribute("width", QString("%1").arg(m_rect.width()));
|
xml_element.setAttribute("width", QString("%1").arg(m_rect.width()));
|
||||||
xml_element.setAttribute("height", QString("%1").arg(m_rect.height()));
|
xml_element.setAttribute("height", QString("%1").arg(m_rect.height()));
|
||||||
|
|
||||||
|
QRectF rect = m_rect.normalized();
|
||||||
|
qreal x = m_xRadius;
|
||||||
|
if (x > rect.width()/2) {
|
||||||
|
x = rect.width()/2;
|
||||||
|
}
|
||||||
|
qreal y = m_yRadius;
|
||||||
|
if (y > rect.height()/2) {
|
||||||
|
y = rect.height()/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
xml_element.setAttribute("rx", QString::number(m_xRadius));
|
||||||
|
xml_element.setAttribute("ry", QString::number(m_yRadius));
|
||||||
|
|
||||||
stylesToXml(xml_element);
|
stylesToXml(xml_element);
|
||||||
return(xml_element);
|
return(xml_element);
|
||||||
}
|
}
|
||||||
@@ -107,6 +118,8 @@ void PartRectangle::fromXml(const QDomElement &qde)
|
|||||||
qde.attribute("height", "0").toDouble()));
|
qde.attribute("height", "0").toDouble()));
|
||||||
|
|
||||||
setRect(rect.normalized());
|
setRect(rect.normalized());
|
||||||
|
setXRadius(qde.attribute("rx", "0").toDouble());
|
||||||
|
setYRadius(qde.attribute("ry", "0").toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,6 +144,22 @@ void PartRectangle::setRect(const QRectF &rect)
|
|||||||
emit rectChanged();
|
emit rectChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartRectangle::setXRadius(qreal X)
|
||||||
|
{
|
||||||
|
m_xRadius = X;
|
||||||
|
update();
|
||||||
|
adjusteHandlerPos();
|
||||||
|
emit XRadiusChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartRectangle::setYRadius(qreal Y)
|
||||||
|
{
|
||||||
|
m_yRadius = Y;
|
||||||
|
update();
|
||||||
|
adjusteHandlerPos();
|
||||||
|
emit YRadiusChanged();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartRectangle::sceneGeometricRect
|
* @brief PartRectangle::sceneGeometricRect
|
||||||
* @return the minimum, margin-less rectangle this part can fit into, in scene
|
* @return the minimum, margin-less rectangle this part can fit into, in scene
|
||||||
@@ -157,7 +186,7 @@ QPointF PartRectangle::sceneTopLeft() const {
|
|||||||
QPainterPath PartRectangle::shape() const
|
QPainterPath PartRectangle::shape() const
|
||||||
{
|
{
|
||||||
QPainterPath shape;
|
QPainterPath shape;
|
||||||
shape.addRect(m_rect);
|
shape.addRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||||
@@ -169,7 +198,7 @@ QPainterPath PartRectangle::shape() const
|
|||||||
QPainterPath PartRectangle::shadowShape() const
|
QPainterPath PartRectangle::shadowShape() const
|
||||||
{
|
{
|
||||||
QPainterPath shape;
|
QPainterPath shape;
|
||||||
shape.addRect(m_rect);
|
shape.addRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(penWeight());
|
pps.setWidth(penWeight());
|
||||||
@@ -333,11 +362,25 @@ void PartRectangle::switchResizeMode()
|
|||||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||||
qghi->setColor(Qt::darkGreen);
|
qghi->setColor(Qt::darkGreen);
|
||||||
}
|
}
|
||||||
else
|
else if (m_resize_mode == 2)
|
||||||
|
{
|
||||||
|
m_resize_mode = 3;
|
||||||
|
qDeleteAll(m_handler_vector);
|
||||||
|
m_handler_vector.clear();
|
||||||
|
addHandler();
|
||||||
|
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||||
|
qghi->setColor(Qt::magenta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_resize_mode == 3)
|
||||||
{
|
{
|
||||||
m_resize_mode = 1;
|
m_resize_mode = 1;
|
||||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
qDeleteAll(m_handler_vector);
|
||||||
|
m_handler_vector.clear();
|
||||||
|
addHandler();
|
||||||
|
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||||
qghi->setColor(Qt::blue);
|
qghi->setColor(Qt::blue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,10 +389,18 @@ void PartRectangle::switchResizeMode()
|
|||||||
*/
|
*/
|
||||||
void PartRectangle::adjusteHandlerPos()
|
void PartRectangle::adjusteHandlerPos()
|
||||||
{
|
{
|
||||||
if (m_handler_vector.isEmpty())
|
if (m_handler_vector.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QVector <QPointF> points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
QVector <QPointF> points_vector;
|
||||||
|
|
||||||
|
if(m_resize_mode != 3) {
|
||||||
|
points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
points_vector = QetGraphicsHandlerUtility::pointForRadiusRect(m_rect, m_xRadius, m_yRadius);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_handler_vector.size() == points_vector.size())
|
if (m_handler_vector.size() == points_vector.size())
|
||||||
{
|
{
|
||||||
@@ -357,6 +408,12 @@ void PartRectangle::adjusteHandlerPos()
|
|||||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDeleteAll(m_handler_vector);
|
||||||
|
m_handler_vector.clear();
|
||||||
|
addHandler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -366,13 +423,15 @@ void PartRectangle::adjusteHandlerPos()
|
|||||||
*/
|
*/
|
||||||
void PartRectangle::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
void PartRectangle::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(qghi);
|
Q_UNUSED(qghi)
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event)
|
||||||
|
|
||||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
m_old_rect = m_rect;
|
||||||
m_undo_command->setText(tr("Modifier un rectangle"));
|
m_old_xRadius = m_xRadius;
|
||||||
m_undo_command->enableAnimation();
|
m_old_yRadius = m_yRadius;
|
||||||
return;
|
if(m_xRadius == 0 && m_yRadius == 0) {
|
||||||
|
m_modifie_radius_equaly = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -382,7 +441,7 @@ void PartRectangle::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphi
|
|||||||
*/
|
*/
|
||||||
void PartRectangle::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
void PartRectangle::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(qghi);
|
Q_UNUSED(qghi)
|
||||||
|
|
||||||
QPointF new_pos = event->scenePos();
|
QPointF new_pos = event->scenePos();
|
||||||
if (event->modifiers() != Qt::ControlModifier)
|
if (event->modifiers() != Qt::ControlModifier)
|
||||||
@@ -391,20 +450,48 @@ void PartRectangle::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphic
|
|||||||
|
|
||||||
if (m_resize_mode == 1)
|
if (m_resize_mode == 1)
|
||||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||||
else
|
else if (m_resize_mode == 2)
|
||||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qreal radius = QetGraphicsHandlerUtility::radiusForPosAtIndex(m_rect, new_pos, m_vector_index);
|
||||||
|
if(m_modifie_radius_equaly) {
|
||||||
|
setXRadius(radius);
|
||||||
|
setYRadius(radius);
|
||||||
|
}
|
||||||
|
else if(m_vector_index == 0) {
|
||||||
|
setXRadius(radius);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setYRadius(radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
adjusteHandlerPos();
|
adjusteHandlerPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartRectangle::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
void PartRectangle::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(qghi);
|
Q_UNUSED(qghi)
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event)
|
||||||
|
|
||||||
m_undo_command->setNewValue(QVariant(m_rect));
|
m_modifie_radius_equaly = false;
|
||||||
elementScene()->undoStack().push(m_undo_command);
|
|
||||||
m_undo_command = nullptr;
|
QUndoCommand *undo = new QUndoCommand("Modifier un rectangle");
|
||||||
|
if (m_old_rect != m_rect) {
|
||||||
|
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "rect", QVariant(m_old_rect.normalized()), QVariant(m_rect.normalized()), undo);
|
||||||
|
u->setAnimated(true, false);
|
||||||
|
}
|
||||||
|
if (m_old_xRadius != m_xRadius) {
|
||||||
|
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "xRadius", QVariant(m_old_xRadius), QVariant(m_xRadius), undo);
|
||||||
|
u->setAnimated();
|
||||||
|
}
|
||||||
|
if (m_old_yRadius != m_yRadius) {
|
||||||
|
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "yRadius", QVariant(m_old_yRadius), QVariant(m_yRadius), undo);
|
||||||
|
u->setAnimated();
|
||||||
|
}
|
||||||
|
|
||||||
|
elementScene()->undoStack().push(undo);
|
||||||
m_vector_index = -1;
|
m_vector_index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,14 +514,20 @@ void PartRectangle::sceneSelectionChanged()
|
|||||||
void PartRectangle::addHandler()
|
void PartRectangle::addHandler()
|
||||||
{
|
{
|
||||||
if (m_handler_vector.isEmpty() && scene())
|
if (m_handler_vector.isEmpty() && scene())
|
||||||
{
|
{
|
||||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
if (m_resize_mode != 3) {
|
||||||
|
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointForRadiusRect(m_rect, m_xRadius, m_yRadius)));
|
||||||
|
}
|
||||||
|
|
||||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
for (QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||||
{
|
{
|
||||||
QColor color = Qt::blue;
|
QColor color;
|
||||||
if (m_resize_mode == 2)
|
if(m_resize_mode == 1) {color = Qt::blue;}
|
||||||
color = Qt::darkGreen;
|
else if (m_resize_mode == 2) {color = Qt::darkGreen;}
|
||||||
|
else {color = Qt::magenta;}
|
||||||
|
|
||||||
handler->setColor(color);
|
handler->setColor(color);
|
||||||
scene()->addItem(handler);
|
scene()->addItem(handler);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "customelementgraphicpart.h"
|
#include "customelementgraphicpart.h"
|
||||||
|
|
||||||
class QPropertyUndoCommand;
|
|
||||||
class QetGraphicsHandlerItem;
|
class QetGraphicsHandlerItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +32,8 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
||||||
|
Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
|
||||||
|
Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
|
||||||
|
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
@@ -44,6 +45,8 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void rectChanged();
|
void rectChanged();
|
||||||
|
void XRadiusChanged();
|
||||||
|
void YRadiusChanged();
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
@@ -62,6 +65,10 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
|
|
||||||
QRectF rect() const;
|
QRectF rect() const;
|
||||||
void setRect(const QRectF &rect);
|
void setRect(const QRectF &rect);
|
||||||
|
qreal XRadius() const {return m_xRadius;}
|
||||||
|
void setXRadius(qreal X);
|
||||||
|
qreal YRadius() const {return m_yRadius;}
|
||||||
|
void setYRadius(qreal Y);
|
||||||
|
|
||||||
QRectF sceneGeometricRect() const override;
|
QRectF sceneGeometricRect() const override;
|
||||||
virtual QPointF sceneTopLeft() const;
|
virtual QPointF sceneTopLeft() const;
|
||||||
@@ -91,11 +98,16 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
void removeHandler();
|
void removeHandler();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRectF m_rect;
|
QRectF m_rect,
|
||||||
|
m_old_rect;
|
||||||
QList<QPointF> saved_points_;
|
QList<QPointF> saved_points_;
|
||||||
QPropertyUndoCommand *m_undo_command;
|
|
||||||
int m_resize_mode = 1,
|
int m_resize_mode = 1,
|
||||||
m_vector_index = -1;
|
m_vector_index = -1;
|
||||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||||
|
qreal m_xRadius = 0,
|
||||||
|
m_yRadius = 0,
|
||||||
|
m_old_xRadius,
|
||||||
|
m_old_yRadius;
|
||||||
|
bool m_modifie_radius_equaly = false;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ LineEditor::LineEditor(QETElementEditor *editor, PartLine *line, QWidget *parent
|
|||||||
v_layout -> addWidget(style_);
|
v_layout -> addWidget(style_);
|
||||||
v_layout -> addLayout(grid);
|
v_layout -> addLayout(grid);
|
||||||
v_layout -> addLayout(grid2);
|
v_layout -> addLayout(grid2);
|
||||||
|
v_layout->addStretch();
|
||||||
updateForm();
|
updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ PolygonEditor::PolygonEditor(QETElementEditor *editor, PartPolygon *p, QWidget *
|
|||||||
layout -> addWidget(new QLabel(tr("Points du polygone :")));
|
layout -> addWidget(new QLabel(tr("Points du polygone :")));
|
||||||
layout -> addWidget(&points_list);
|
layout -> addWidget(&points_list);
|
||||||
layout -> addWidget(&close_polygon);
|
layout -> addWidget(&close_polygon);
|
||||||
|
layout->addStretch();
|
||||||
|
|
||||||
updateForm();
|
updateForm();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,29 +486,30 @@ void QETElementEditor::slot_updateTitle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met en place l'interface
|
* @brief QETElementEditor::setupInterface
|
||||||
*/
|
*/
|
||||||
void QETElementEditor::setupInterface() {
|
void QETElementEditor::setupInterface()
|
||||||
// editeur
|
{
|
||||||
|
// editeur
|
||||||
m_elmt_scene = new ElementScene(this, this);
|
m_elmt_scene = new ElementScene(this, this);
|
||||||
m_view = new ElementView(m_elmt_scene, this);
|
m_view = new ElementView(m_elmt_scene, this);
|
||||||
slot_setRubberBandToView();
|
slot_setRubberBandToView();
|
||||||
setCentralWidget(m_view);
|
setCentralWidget(m_view);
|
||||||
|
|
||||||
// widget par defaut dans le QDockWidget
|
// widget par defaut dans le QDockWidget
|
||||||
m_default_informations = new QLabel();
|
m_default_informations = new QLabel();
|
||||||
|
|
||||||
// ScrollArea pour accueillir un widget d'edition (change a la volee)
|
// ScrollArea pour accueillir un widget d'edition (change a la volee)
|
||||||
m_tools_dock_scroll_area = new QScrollArea();
|
// m_tools_dock_scroll_area = new QScrollArea();
|
||||||
m_tools_dock_scroll_area -> setFrameStyle(QFrame::NoFrame);
|
// m_tools_dock_scroll_area -> setFrameStyle(QFrame::NoFrame);
|
||||||
m_tools_dock_scroll_area -> setAlignment(Qt::AlignHCenter|Qt::AlignTop);
|
// m_tools_dock_scroll_area -> setAlignment(Qt::AlignHCenter|Qt::AlignTop);
|
||||||
|
|
||||||
// Pile de widgets pour accueillir les deux widgets precedents
|
// Pile de widgets pour accueillir les deux widgets precedents
|
||||||
m_tools_dock_stack = new QStackedWidget();
|
m_tools_dock_stack = new QStackedWidget();
|
||||||
m_tools_dock_stack -> insertWidget(0, m_default_informations);
|
m_tools_dock_stack -> insertWidget(0, m_default_informations);
|
||||||
m_tools_dock_stack -> insertWidget(1, m_tools_dock_scroll_area);
|
// m_tools_dock_stack -> insertWidget(1, m_tools_dock_scroll_area);
|
||||||
|
|
||||||
// widgets d'editions pour les parties
|
// widgets d'editions pour les parties
|
||||||
m_editors["arc"] = new ArcEditor(this);
|
m_editors["arc"] = new ArcEditor(this);
|
||||||
m_editors["ellipse"] = new EllipseEditor(this);
|
m_editors["ellipse"] = new EllipseEditor(this);
|
||||||
m_editors["line"] = new LineEditor(this);
|
m_editors["line"] = new LineEditor(this);
|
||||||
@@ -609,7 +610,7 @@ void QETElementEditor::slot_updateInformations()
|
|||||||
QGraphicsItem *qgi = selected_qgis.first();
|
QGraphicsItem *qgi = selected_qgis.first();
|
||||||
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
|
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
{
|
{
|
||||||
if (QWidget *widget = m_tools_dock_scroll_area->widget())
|
if (QWidget *widget = m_tools_dock_stack->widget(1))
|
||||||
{
|
{
|
||||||
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
|
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
|
||||||
{
|
{
|
||||||
@@ -627,7 +628,7 @@ void QETElementEditor::slot_updateInformations()
|
|||||||
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
|
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
{
|
{
|
||||||
//The current editor already edit the selected part
|
//The current editor already edit the selected part
|
||||||
if (QWidget *widget = m_tools_dock_scroll_area->widget())
|
if (QWidget *widget = m_tools_dock_stack->widget(1))
|
||||||
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
|
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
|
||||||
if(editor->currentPart() == selection)
|
if(editor->currentPart() == selection)
|
||||||
return;
|
return;
|
||||||
@@ -640,7 +641,7 @@ void QETElementEditor::slot_updateInformations()
|
|||||||
{
|
{
|
||||||
if (selection_editor->setPart(selection))
|
if (selection_editor->setPart(selection))
|
||||||
{
|
{
|
||||||
m_tools_dock_scroll_area -> setWidget(selection_editor);
|
m_tools_dock_stack->insertWidget(1, selection_editor);
|
||||||
m_tools_dock_stack -> setCurrentIndex(1);
|
m_tools_dock_stack -> setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -659,7 +660,7 @@ void QETElementEditor::slot_updateInformations()
|
|||||||
{
|
{
|
||||||
if (selection_editor -> setParts(cep_list))
|
if (selection_editor -> setParts(cep_list))
|
||||||
{
|
{
|
||||||
m_tools_dock_scroll_area -> setWidget(selection_editor);
|
m_tools_dock_stack->insertWidget(1, selection_editor);
|
||||||
m_tools_dock_stack -> setCurrentIndex(1);
|
m_tools_dock_stack -> setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1267,7 +1268,9 @@ bool QETElementEditor::canClose() {
|
|||||||
@return le widget enleve, ou 0 s'il n'y avait pas de widget a enlever
|
@return le widget enleve, ou 0 s'il n'y avait pas de widget a enlever
|
||||||
*/
|
*/
|
||||||
QWidget *QETElementEditor::clearToolsDock() {
|
QWidget *QETElementEditor::clearToolsDock() {
|
||||||
if (QWidget *previous_widget = m_tools_dock_scroll_area -> takeWidget()) {
|
if (QWidget *previous_widget = m_tools_dock_stack->widget(1))
|
||||||
|
{
|
||||||
|
m_tools_dock_stack->removeWidget(previous_widget);
|
||||||
previous_widget -> setParent(nullptr);
|
previous_widget -> setParent(nullptr);
|
||||||
previous_widget -> hide();
|
previous_widget -> hide();
|
||||||
return(previous_widget);
|
return(previous_widget);
|
||||||
@@ -1574,7 +1577,7 @@ void QETElementEditor::updateCurrentPartEditor() {
|
|||||||
if (!m_tools_dock_stack -> currentIndex()) return;
|
if (!m_tools_dock_stack -> currentIndex()) return;
|
||||||
|
|
||||||
// s'il y a un widget d'edition affiche, on le met a jour
|
// s'il y a un widget d'edition affiche, on le met a jour
|
||||||
if (ElementItemEditor *current_editor = dynamic_cast<ElementItemEditor *>(m_tools_dock_scroll_area -> widget())) {
|
if (ElementItemEditor *current_editor = dynamic_cast<ElementItemEditor *>(m_tools_dock_stack->widget(1))) {
|
||||||
current_editor -> updateForm();
|
current_editor -> updateForm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef CUSTOM_ELEMENT_EDITOR_H
|
#ifndef CUSTOM_ELEMENT_EDITOR_H
|
||||||
#define CUSTOM_ELEMENT_EDITOR_H
|
#define CUSTOM_ELEMENT_EDITOR_H
|
||||||
#include <QtWidgets>
|
|
||||||
#include "qetmainwindow.h"
|
#include "qetmainwindow.h"
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
@@ -62,8 +61,6 @@ class QETElementEditor : public QETMainWindow {
|
|||||||
QLabel *m_default_informations;
|
QLabel *m_default_informations;
|
||||||
/// Hash associating primitive names with their matching edition widget
|
/// Hash associating primitive names with their matching edition widget
|
||||||
QHash<QString, ElementItemEditor *> m_editors;
|
QHash<QString, ElementItemEditor *> m_editors;
|
||||||
/// ScrollArea for the tools_dock DockWidget
|
|
||||||
QScrollArea *m_tools_dock_scroll_area;
|
|
||||||
/// container for the undo list
|
/// container for the undo list
|
||||||
QDockWidget *m_undo_dock;
|
QDockWidget *m_undo_dock;
|
||||||
/// Container for the list of existing primitives
|
/// Container for the list of existing primitives
|
||||||
|
|||||||
@@ -1,181 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2017 The QElectroTech Team
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
#include "rectangleeditor.h"
|
|
||||||
#include "partrectangle.h"
|
|
||||||
#include "styleeditor.h"
|
|
||||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
|
||||||
#include "elementscene.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
Constructeur
|
|
||||||
@param editor L'editeur d'element concerne
|
|
||||||
@param rect Le rectangle a editer
|
|
||||||
@param parent le Widget parent
|
|
||||||
*/
|
|
||||||
RectangleEditor::RectangleEditor(QETElementEditor *editor, PartRectangle *rect, QWidget *parent) :
|
|
||||||
ElementItemEditor(editor, parent),
|
|
||||||
part(rect),
|
|
||||||
m_locked(false)
|
|
||||||
{
|
|
||||||
style_ = new StyleEditor(editor);
|
|
||||||
|
|
||||||
x = new QDoubleSpinBox();
|
|
||||||
y = new QDoubleSpinBox();
|
|
||||||
w = new QDoubleSpinBox();
|
|
||||||
h = new QDoubleSpinBox();
|
|
||||||
|
|
||||||
x->setRange(-5000, 5000);
|
|
||||||
y->setRange(-5000, 5000);
|
|
||||||
w->setRange(-5000, 5000);
|
|
||||||
h->setRange(-5000, 5000);
|
|
||||||
|
|
||||||
QVBoxLayout *v_layout = new QVBoxLayout(this);
|
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout();
|
|
||||||
grid -> addWidget(new QLabel(tr("Coin supérieur gauche : ")), 0, 0, 1, 4);
|
|
||||||
grid -> addWidget(new QLabel("x"), 1, 0, Qt::AlignRight);
|
|
||||||
grid -> addWidget(x, 1, 1);
|
|
||||||
grid -> addWidget(new QLabel("y"), 1, 2);
|
|
||||||
grid -> addWidget(y, 1, 3);
|
|
||||||
grid -> addWidget(new QLabel(tr("Dimensions : ")), 2, 0, 1, 4);
|
|
||||||
grid -> addWidget(new QLabel(tr("Largeur :")), 3, 0);
|
|
||||||
grid -> addWidget(w, 3, 1);
|
|
||||||
grid -> addWidget(new QLabel(tr("Hauteur :")), 4, 0);
|
|
||||||
grid -> addWidget(h, 4, 1);
|
|
||||||
|
|
||||||
v_layout -> addWidget(style_);
|
|
||||||
v_layout -> addLayout(grid);
|
|
||||||
|
|
||||||
activeConnections(true);
|
|
||||||
updateForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destructeur
|
|
||||||
RectangleEditor::~RectangleEditor() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief RectangleEditor::setPart
|
|
||||||
* Specifie to this editor the part to edit.
|
|
||||||
* Note that an editor can accept or refuse to edit a part. This editor accept only partRectangle.
|
|
||||||
* @param new_part
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
bool RectangleEditor::setPart(CustomElementPart *new_part)
|
|
||||||
{
|
|
||||||
if (!new_part)
|
|
||||||
{
|
|
||||||
if (part)
|
|
||||||
disconnect(part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm);
|
|
||||||
part = nullptr;
|
|
||||||
style_ -> setPart(nullptr);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PartRectangle *part_rectangle = dynamic_cast<PartRectangle *>(new_part))
|
|
||||||
{
|
|
||||||
if (part == part_rectangle) return true;
|
|
||||||
if (part)
|
|
||||||
disconnect(part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm);
|
|
||||||
part = part_rectangle;
|
|
||||||
style_ -> setPart(part);
|
|
||||||
updateForm();
|
|
||||||
connect(part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief RectangleEditor::currentPart
|
|
||||||
* @return the curent edited part, or 0 if there is no edited part
|
|
||||||
*/
|
|
||||||
CustomElementPart *RectangleEditor::currentPart() const {
|
|
||||||
return(part);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief RectangleEditor::topLeft
|
|
||||||
* @return The edited topLeft already mapped to part coordinate
|
|
||||||
*/
|
|
||||||
QPointF RectangleEditor::editedTopLeft() const {
|
|
||||||
return part -> mapFromScene(x->value(), y->value());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief RectangleEditor::updateForm
|
|
||||||
* Update the values displayed by this widget
|
|
||||||
*/
|
|
||||||
void RectangleEditor::updateForm()
|
|
||||||
{
|
|
||||||
if (!part) return;
|
|
||||||
activeConnections(false);
|
|
||||||
|
|
||||||
QRectF rect = part->property("rect").toRectF();
|
|
||||||
QPointF p = part->mapToScene(rect.topLeft());
|
|
||||||
x->setValue(p.x());
|
|
||||||
y->setValue(p.y());
|
|
||||||
w->setValue(rect.width());
|
|
||||||
h->setValue(rect.height());
|
|
||||||
|
|
||||||
activeConnections(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief RectangleEditor::editingFinished
|
|
||||||
* Slot called when a editor widget is finish to be edited
|
|
||||||
* Update the geometry of the rectangle according to value of editing widget.
|
|
||||||
*/
|
|
||||||
void RectangleEditor::editingFinished()
|
|
||||||
{
|
|
||||||
if (m_locked) return;
|
|
||||||
m_locked = true;
|
|
||||||
|
|
||||||
QRectF rect(editedTopLeft(), QSizeF(w->value(), h->value()));
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "rect", part->property("rect"), rect);
|
|
||||||
undo->setText(tr("Modifier un rectangle"));
|
|
||||||
undo->enableAnimation();
|
|
||||||
elementScene()->undoStack().push(undo);
|
|
||||||
|
|
||||||
m_locked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief RectangleEditor::activeConnections
|
|
||||||
* Enable/disable connection between editor widget and slot editingFinished
|
|
||||||
* True == enable | false == disable
|
|
||||||
* @param active
|
|
||||||
*/
|
|
||||||
void RectangleEditor::activeConnections(bool active)
|
|
||||||
{
|
|
||||||
if (active)
|
|
||||||
{
|
|
||||||
connect(x, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
connect(y, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
connect(w, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
connect(h, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
disconnect(x, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
disconnect(y, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
disconnect(w, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
disconnect(h, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -118,7 +118,6 @@ StyleEditor::StyleEditor(QETElementEditor *editor, CustomElementGraphicPart *p,
|
|||||||
|
|
||||||
main_layout -> addSpacing(10);
|
main_layout -> addSpacing(10);
|
||||||
main_layout -> addWidget(new QLabel("<u>" + tr("Géométrie :") + "</u> "));
|
main_layout -> addWidget(new QLabel("<u>" + tr("Géométrie :") + "</u> "));
|
||||||
main_layout -> addStretch();
|
|
||||||
setLayout(main_layout);
|
setLayout(main_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
200
sources/editor/ui/rectangleeditor.cpp
Normal file
200
sources/editor/ui/rectangleeditor.cpp
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 The QElectroTech Team
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
#include "rectangleeditor.h"
|
||||||
|
#include "ui_rectangleeditor.h"
|
||||||
|
#include "styleeditor.h"
|
||||||
|
#include "partrectangle.h"
|
||||||
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
#include "elementscene.h"
|
||||||
|
#include "qeticons.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::RectangleEditor
|
||||||
|
* @param editor
|
||||||
|
* @param rect
|
||||||
|
* @param parent
|
||||||
|
*/
|
||||||
|
RectangleEditor::RectangleEditor(QETElementEditor *editor, PartRectangle *rect, QWidget *parent) :
|
||||||
|
ElementItemEditor(editor, parent),
|
||||||
|
m_part(rect),
|
||||||
|
ui(new Ui::RectangleEditor)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
m_style = new StyleEditor(editor);
|
||||||
|
ui->verticalLayout->insertWidget(0, m_style);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::~RectangleEditor
|
||||||
|
*/
|
||||||
|
RectangleEditor::~RectangleEditor() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::setPart
|
||||||
|
* @param part
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool RectangleEditor::setPart(CustomElementPart *part)
|
||||||
|
{
|
||||||
|
if (!part)
|
||||||
|
{
|
||||||
|
if (m_part)
|
||||||
|
{
|
||||||
|
disconnect(m_part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::XRadiusChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::YRadiusChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm);
|
||||||
|
}
|
||||||
|
m_part = nullptr;
|
||||||
|
m_style->setPart(nullptr);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PartRectangle *part_rectangle = dynamic_cast<PartRectangle *>(part))
|
||||||
|
{
|
||||||
|
if (m_part == part_rectangle) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (m_part)
|
||||||
|
{
|
||||||
|
disconnect(m_part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::XRadiusChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::YRadiusChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm);
|
||||||
|
disconnect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm);
|
||||||
|
}
|
||||||
|
m_part = part_rectangle;
|
||||||
|
m_style->setPart(m_part);
|
||||||
|
updateForm();
|
||||||
|
connect(m_part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm);
|
||||||
|
connect(m_part, &PartRectangle::XRadiusChanged, this, &RectangleEditor::updateForm);
|
||||||
|
connect(m_part, &PartRectangle::YRadiusChanged, this, &RectangleEditor::updateForm);
|
||||||
|
connect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm);
|
||||||
|
connect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::currentPart
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
CustomElementPart *RectangleEditor::currentPart() const {
|
||||||
|
return m_part;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::topLeft
|
||||||
|
* @return The edited topLeft already mapped to part coordinate
|
||||||
|
*/
|
||||||
|
QPointF RectangleEditor::editedTopLeft() const {
|
||||||
|
return m_part->mapFromScene(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::updateForm
|
||||||
|
*/
|
||||||
|
void RectangleEditor::updateForm()
|
||||||
|
{
|
||||||
|
if (!m_part) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeConnections(false);
|
||||||
|
|
||||||
|
QRectF rect = m_part->property("rect").toRectF();
|
||||||
|
QPointF p = m_part->mapToScene(rect.topLeft());
|
||||||
|
ui->m_x_sb->setValue(p.x());
|
||||||
|
ui->m_y_sb->setValue(p.y());
|
||||||
|
ui->m_width_sb->setValue(rect.width());
|
||||||
|
ui->m_height_sb->setValue(rect.height());
|
||||||
|
ui->m_rx_sb->setValue(m_part->XRadius());
|
||||||
|
ui->m_rx_sb->setMaximum(rect.width()/2);
|
||||||
|
ui->m_ry_sb->setValue(m_part->YRadius());
|
||||||
|
ui->m_ry_sb->setMaximum(rect.height()/2);
|
||||||
|
|
||||||
|
activeConnections(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::editingFinished
|
||||||
|
* Slot called when a editor widget is finish to be edited
|
||||||
|
* Update the geometry of the rectangle according to value of editing widget.
|
||||||
|
*/
|
||||||
|
void RectangleEditor::editingFinished()
|
||||||
|
{
|
||||||
|
if (m_locked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_locked = true;
|
||||||
|
|
||||||
|
QUndoCommand *undo = new QUndoCommand();
|
||||||
|
undo->setText(tr("Modifier un rectangle"));
|
||||||
|
|
||||||
|
QRectF rect(editedTopLeft(), QSizeF(ui->m_width_sb->value(), ui->m_height_sb->value()));
|
||||||
|
if (m_part->rect() != rect)
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *u = new QPropertyUndoCommand(m_part, "rect", m_part->rect(), rect, undo);
|
||||||
|
u->enableAnimation();
|
||||||
|
}
|
||||||
|
if (m_part->XRadius() != ui->m_rx_sb->value())
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *u = new QPropertyUndoCommand(m_part, "xRadius", m_part->XRadius(), ui->m_rx_sb->value(), undo);
|
||||||
|
u->setAnimated();
|
||||||
|
}
|
||||||
|
if (m_part->YRadius() != ui->m_ry_sb->value())
|
||||||
|
{
|
||||||
|
QPropertyUndoCommand *u = new QPropertyUndoCommand(m_part, "yRadius", m_part->YRadius(), ui->m_ry_sb->value(), undo);
|
||||||
|
u->setAnimated();
|
||||||
|
}
|
||||||
|
elementScene()->undoStack().push(undo);
|
||||||
|
|
||||||
|
m_locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RectangleEditor::activeConnections
|
||||||
|
* Enable/disable connection between editor widget and slot editingFinished
|
||||||
|
* True == enable | false == disable
|
||||||
|
* @param active
|
||||||
|
*/
|
||||||
|
void RectangleEditor::activeConnections(bool active)
|
||||||
|
{
|
||||||
|
if (active)
|
||||||
|
{
|
||||||
|
connect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
connect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
connect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
connect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
connect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
connect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
disconnect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
disconnect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
disconnect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
disconnect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
disconnect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
disconnect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2017 The QElectroTech Team
|
Copyright 2006-2018 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -15,47 +15,46 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef RECTANGLE_EDITOR_H
|
#ifndef RECTANGLEEDITOR_H
|
||||||
#define RECTANGLE_EDITOR_H
|
#define RECTANGLEEDITOR_H
|
||||||
|
|
||||||
#include "elementitemeditor.h"
|
#include "elementitemeditor.h"
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
class PartRectangle;
|
|
||||||
class StyleEditor;
|
class StyleEditor;
|
||||||
class QDoubleSpinBox;
|
class PartRectangle;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class RectangleEditor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a widget to edit rectangles within the element editor.
|
* @brief The RectangleEditor class
|
||||||
*/
|
* This class provides a widget to edit rectangles within the element editor.
|
||||||
|
*/
|
||||||
class RectangleEditor : public ElementItemEditor
|
class RectangleEditor : public ElementItemEditor
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
// constructors, destructor
|
|
||||||
public:
|
|
||||||
RectangleEditor(QETElementEditor *, PartRectangle * = nullptr, QWidget * = nullptr);
|
|
||||||
~RectangleEditor() override;
|
|
||||||
private:
|
|
||||||
RectangleEditor(const RectangleEditor &);
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
private:
|
|
||||||
PartRectangle *part;
|
|
||||||
StyleEditor *style_;
|
|
||||||
QDoubleSpinBox *x, *y, *w, *h;
|
|
||||||
bool m_locked;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
explicit RectangleEditor(QETElementEditor *editor, PartRectangle *rect = nullptr, QWidget *parent = nullptr);
|
||||||
|
~RectangleEditor();
|
||||||
|
|
||||||
|
bool setPart(CustomElementPart *part) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QPointF editedTopLeft () const;
|
QPointF editedTopLeft () const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateForm() override;
|
void updateForm() override;
|
||||||
|
private:
|
||||||
void editingFinished();
|
void editingFinished();
|
||||||
|
void activeConnections(bool active);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void activeConnections(bool);
|
bool m_locked = false;
|
||||||
|
StyleEditor *m_style;
|
||||||
|
PartRectangle *m_part;
|
||||||
|
Ui::RectangleEditor *ui;
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
#endif // RECTANGLEEDITOR_H
|
||||||
166
sources/editor/ui/rectangleeditor.ui
Normal file
166
sources/editor/ui/rectangleeditor.ui
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>RectangleEditor</class>
|
||||||
|
<widget class="QWidget" name="RectangleEditor">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>293</width>
|
||||||
|
<height>147</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetMinimumSize</enum>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="m_grid_layout">
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QDoubleSpinBox" name="m_width_sb">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>Hauteur :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="4">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Dimensions :</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>y</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QDoubleSpinBox" name="m_height_sb">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="3">
|
||||||
|
<widget class="QDoubleSpinBox" name="m_y_sb">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="3">
|
||||||
|
<widget class="QDoubleSpinBox" name="m_rx_sb">
|
||||||
|
<property name="maximum">
|
||||||
|
<double>2500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="4">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Coin supérieur gauche :</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Largeur :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="2">
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Arrondi :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>x</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QDoubleSpinBox" name="m_x_sb">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>5000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="2">
|
||||||
|
<widget class="QLabel" name="label_8">
|
||||||
|
<property name="text">
|
||||||
|
<string>Arrondi :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="3">
|
||||||
|
<widget class="QDoubleSpinBox" name="m_ry_sb">
|
||||||
|
<property name="maximum">
|
||||||
|
<double>2500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -462,13 +462,16 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp, bool addtolist) {
|
|||||||
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
||||||
@return true si l'analyse reussit, false sinon
|
@return true si l'analyse reussit, false sinon
|
||||||
*/
|
*/
|
||||||
bool CustomElement::parseRect(QDomElement &e, QPainter &qp, bool addtolist) {
|
bool CustomElement::parseRect(QDomElement &e, QPainter &qp, bool addtolist)
|
||||||
|
{
|
||||||
// verifie la presence des attributs obligatoires
|
// verifie la presence des attributs obligatoires
|
||||||
qreal rect_x, rect_y, rect_w, rect_h;
|
qreal rect_x, rect_y, rect_w, rect_h, rect_rx, rect_ry;
|
||||||
if (!QET::attributeIsAReal(e, QString("x"), &rect_x)) return(false);
|
if (!QET::attributeIsAReal(e, QString("x"), &rect_x)) return(false);
|
||||||
if (!QET::attributeIsAReal(e, QString("y"), &rect_y)) return(false);
|
if (!QET::attributeIsAReal(e, QString("y"), &rect_y)) return(false);
|
||||||
if (!QET::attributeIsAReal(e, QString("width"), &rect_w)) return(false);
|
if (!QET::attributeIsAReal(e, QString("width"), &rect_w)) return(false);
|
||||||
if (!QET::attributeIsAReal(e, QString("height"), &rect_h)) return(false);
|
if (!QET::attributeIsAReal(e, QString("height"), &rect_h)) return(false);
|
||||||
|
rect_rx = e.attribute("rx", "0").toDouble();
|
||||||
|
rect_ry = e.attribute("ry", "0").toDouble();
|
||||||
|
|
||||||
if (addtolist){
|
if (addtolist){
|
||||||
//Add rectangle to the list
|
//Add rectangle to the list
|
||||||
@@ -484,7 +487,7 @@ bool CustomElement::parseRect(QDomElement &e, QPainter &qp, bool addtolist) {
|
|||||||
p.setJoinStyle(Qt::MiterJoin);
|
p.setJoinStyle(Qt::MiterJoin);
|
||||||
qp.setPen(p);
|
qp.setPen(p);
|
||||||
|
|
||||||
qp.drawRect(QRectF(rect_x, rect_y, rect_w, rect_h));
|
qp.drawRoundedRect(QRectF(rect_x, rect_y, rect_w, rect_h), rect_rx, rect_ry);
|
||||||
qp.restore();
|
qp.restore();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user