diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index c58b2c8ec..1b3430d8c 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -61,9 +61,16 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, //Always remove the brush painter -> setBrush(Qt::NoBrush); QPen t = painter -> pen(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove t.setCosmetic(options && options -> levelOfDetail < 1.0); +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0); +#endif painter -> setPen(t); - + if (isSelected()) { painter->save(); @@ -79,7 +86,7 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, t.setColor(Qt::red); painter -> setPen(t); } - + painter->drawArc(m_rect, m_start_angle, m_span_angle); if (m_hovered) @@ -196,8 +203,8 @@ QVariant PartArc::itemChange(QGraphicsItem::GraphicsItemChange change, const QVa { //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged); - + connect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged); + if (scene()->selectedItems().size() == 1) addHandler(); } @@ -215,10 +222,10 @@ QVariant PartArc::itemChange(QGraphicsItem::GraphicsItemChange change, const QVa { if(scene()) disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged); - + setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed. } - + return QGraphicsItem::itemChange(change, value); } @@ -234,7 +241,7 @@ bool PartArc::sceneEventFilter(QGraphicsItem *watched, QEvent *event) if(watched->type() == QetGraphicsHandlerItem::Type) { QetGraphicsHandlerItem *qghi = qgraphicsitem_cast(watched); - + if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize { m_vector_index = m_handler_vector.indexOf(qghi); @@ -258,7 +265,7 @@ bool PartArc::sceneEventFilter(QGraphicsItem *watched, QEvent *event) } } } - + return false; } @@ -266,7 +273,7 @@ bool PartArc::sceneEventFilter(QGraphicsItem *watched, QEvent *event) @brief PartArc::switchResizeMode */ void PartArc::switchResizeMode() -{ +{ if (m_resize_mode == 1) { m_resize_mode = 2; @@ -274,24 +281,24 @@ void PartArc::switchResizeMode() qghi->setColor(Qt::darkGreen); } else if (m_resize_mode == 2) - { + { m_resize_mode = 3; - + //From rect mode to angle mode, then numbers of handlers change removeHandler(); addHandler(); - + for (QetGraphicsHandlerItem *qghi : m_handler_vector) qghi->setColor(Qt::magenta); } else - { + { m_resize_mode = 1; - + //From angle mode to rect mode, then numbers of handlers change removeHandler(); addHandler(); - + for (QetGraphicsHandlerItem *qghi : m_handler_vector) qghi->setColor(Qt::blue); } @@ -304,21 +311,21 @@ void PartArc::adjusteHandlerPos() { if (m_handler_vector.isEmpty()) return; - + QVector points_vector; - + if(m_resize_mode == 3) points_vector = QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16); else points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect); - - + + if (m_handler_vector.size() == points_vector.size()) { points_vector = mapToScene(points_vector); for (int i = 0 ; i < points_vector.size() ; ++i) m_handler_vector.at(i)->setPos(points_vector.at(i)); - } + } } /** @@ -330,7 +337,7 @@ void PartArc::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsScen { Q_UNUSED(qghi) Q_UNUSED(event) - + if (m_resize_mode == 3) //Resize angle { if (m_vector_index == 0) @@ -368,12 +375,12 @@ void PartArc::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsScen void PartArc::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event) { Q_UNUSED(qghi) - + QPointF new_pos = event->scenePos(); if (event->modifiers() != Qt::ControlModifier) new_pos = elementScene()->snapToGrid(event->scenePos()); new_pos = mapFromScene(new_pos); - + if (m_resize_mode == 1) setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index)); else if (m_resize_mode == 2) @@ -403,7 +410,7 @@ void PartArc::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSc { Q_UNUSED(qghi) Q_UNUSED(event) - + if (m_resize_mode == 3) { if (m_vector_index == 0) @@ -461,7 +468,7 @@ void PartArc::addHandler() } else m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect))); - + for(QetGraphicsHandlerItem *handler : m_handler_vector) { QColor color = Qt::blue; @@ -469,7 +476,7 @@ void PartArc::addHandler() color = Qt::darkGreen; else if (m_resize_mode == 3) color = Qt::magenta; - + handler->setColor(color); scene()->addItem(handler); handler->installSceneEventFilter(this); diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index 8e30f2636..c121e6135 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -55,8 +55,15 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio applyStylesToQPainter(*painter); QPen t = painter -> pen(); - t.setCosmetic(options && options -> levelOfDetail < 1.0); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove + t.setCosmetic(options && options -> levelOfDetail < 1.0); +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0); +#endif if (isSelected()) t.setColor(Qt::red); @@ -159,7 +166,7 @@ void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos()) switchResizeMode(); - + CustomElementGraphicPart::mouseReleaseEvent(event); } @@ -177,8 +184,8 @@ QVariant PartEllipse::itemChange(QGraphicsItem::GraphicsItemChange change, const { //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged); - + connect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged); + if (scene()->selectedItems().size() == 1) addHandler(); } @@ -196,10 +203,10 @@ QVariant PartEllipse::itemChange(QGraphicsItem::GraphicsItemChange change, const { if(scene()) disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged); - + setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed. } - + return QGraphicsItem::itemChange(change, value); } @@ -215,7 +222,7 @@ bool PartEllipse::sceneEventFilter(QGraphicsItem *watched, QEvent *event) if(watched->type() == QetGraphicsHandlerItem::Type) { QetGraphicsHandlerItem *qghi = qgraphicsitem_cast(watched); - + if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize { m_vector_index = m_handler_vector.indexOf(qghi); @@ -239,7 +246,7 @@ bool PartEllipse::sceneEventFilter(QGraphicsItem *watched, QEvent *event) } } } - + return false; } @@ -266,9 +273,9 @@ void PartEllipse::adjusteHandlerPos() { if (m_handler_vector.isEmpty()) return; - + QVector points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect); - + if (m_handler_vector.size() == points_vector.size()) { points_vector = mapToScene(points_vector); @@ -290,7 +297,7 @@ void PartEllipse::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphics m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect)); m_undo_command->setText(tr("Modifier un rectangle")); m_undo_command->enableAnimation(); - return; + return; } /** @@ -301,17 +308,17 @@ void PartEllipse::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphics void PartEllipse::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event) { Q_UNUSED(qghi); - + QPointF new_pos = event->scenePos(); if (event->modifiers() != Qt::ControlModifier) new_pos = elementScene()->snapToGrid(event->scenePos()); new_pos = mapFromScene(new_pos); - + if (m_resize_mode == 1) setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index)); else setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index)); - + adjusteHandlerPos(); } @@ -324,7 +331,7 @@ void PartEllipse::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphi { Q_UNUSED(qghi); Q_UNUSED(event); - + m_undo_command->setNewValue(QVariant(m_rect)); elementScene()->undoStack().push(m_undo_command); m_undo_command = nullptr; @@ -350,15 +357,15 @@ void PartEllipse::sceneSelectionChanged() void PartEllipse::addHandler() { if (m_handler_vector.isEmpty() && scene()) - { + { m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect))); - + for(QetGraphicsHandlerItem *handler : m_handler_vector) { QColor color = Qt::blue; if (m_resize_mode == 2) color = Qt::darkGreen; - + handler->setColor(color); scene()->addItem(handler); handler->installSceneEventFilter(this); diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index 6e6a799c1..304406e2e 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -42,7 +42,7 @@ PartLine::~PartLine() { if(m_undo_command) delete m_undo_command; - + removeHandler(); } @@ -79,12 +79,19 @@ void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, applyStylesToQPainter(*painter); QPen t = painter -> pen(); t.setJoinStyle(Qt::MiterJoin); - t.setCosmetic(options && options -> levelOfDetail < 1.0); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove + t.setCosmetic(options && options -> levelOfDetail < 1.0); +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0); +#endif if (isSelected()) t.setColor(Qt::red); painter -> setPen(t); - + if (first_end || second_end) painter -> drawPath(path()); else @@ -106,7 +113,7 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const { QPointF p1(sceneP1()); QPointF p2(sceneP2()); - + QDomElement xml_element = xml_document.createElement("line"); xml_element.setAttribute("x1", QString("%1").arg(p1.x())); xml_element.setAttribute("y1", QString("%1").arg(p1.y())); @@ -116,7 +123,7 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const xml_element.setAttribute("length1", QString("%1").arg(first_length)); xml_element.setAttribute("end2", Qet::endTypeToString(second_end)); xml_element.setAttribute("length2", QString("%1").arg(second_length)); - + stylesToXml(xml_element); return(xml_element); } @@ -153,8 +160,8 @@ QVariant PartLine::itemChange(QGraphicsItem::GraphicsItemChange change, const QV { //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartLine::sceneSelectionChanged); - + connect(scene(), &QGraphicsScene::selectionChanged, this, &PartLine::sceneSelectionChanged); + if (scene()->selectedItems().size() == 1) addHandler(); } @@ -172,10 +179,10 @@ QVariant PartLine::itemChange(QGraphicsItem::GraphicsItemChange change, const QV { if(scene()) disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartLine::sceneSelectionChanged); - + setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed. } - + return QGraphicsItem::itemChange(change, value); } @@ -191,7 +198,7 @@ bool PartLine::sceneEventFilter(QGraphicsItem *watched, QEvent *event) if(watched->type() == QetGraphicsHandlerItem::Type) { QetGraphicsHandlerItem *qghi = qgraphicsitem_cast(watched); - + if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize { m_vector_index = m_handler_vector.indexOf(qghi); @@ -215,7 +222,7 @@ bool PartLine::sceneEventFilter(QGraphicsItem *watched, QEvent *event) } } } - + return false; } @@ -227,10 +234,10 @@ void PartLine::adjusteHandlerPos() { if(m_handler_vector.isEmpty()) return; - + QVector points_vector; points_vector << m_line.p1() << m_line.p2(); - + if (m_handler_vector.size() == points_vector.size()) { points_vector = mapToScene(points_vector); @@ -248,7 +255,7 @@ void PartLine::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSce { Q_UNUSED(qghi) Q_UNUSED(event) - + m_undo_command = new QPropertyUndoCommand(this, "line", QVariant(m_line)); m_undo_command->setText(tr("Modifier une ligne")); m_undo_command->enableAnimation(); @@ -263,12 +270,12 @@ void PartLine::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSce void PartLine::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event) { Q_UNUSED(qghi) - + QPointF new_pos = event->scenePos(); if (event->modifiers() != Qt::ControlModifier) new_pos = elementScene()->snapToGrid(event->scenePos()); new_pos = mapFromScene(new_pos); - + prepareGeometryChange(); if (m_vector_index == 0) m_line.setP1(new_pos); @@ -276,7 +283,7 @@ void PartLine::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsScen m_line.setP2(new_pos); emit lineChanged(); - + adjusteHandlerPos(); } @@ -289,7 +296,7 @@ void PartLine::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsS { Q_UNUSED(qghi) Q_UNUSED(event) - + m_undo_command->setNewValue(QVariant(m_line)); elementScene()->undoStack().push(m_undo_command); m_undo_command = nullptr; @@ -318,9 +325,9 @@ void PartLine::addHandler() { QVector points_vector; points_vector << m_line.p1() << m_line.p2(); - + m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(points_vector)); - + for(QetGraphicsHandlerItem *handler : m_handler_vector) { handler->setColor(Qt::blue); @@ -416,12 +423,12 @@ QRectF PartLine::firstEndCircleRect() const QList interesting_points = fourEndPoints(m_line.p1(), m_line.p2(), first_length); - + QRectF end_rect( interesting_points[0] - QPointF(first_length, first_length), QSizeF(2.0 * first_length, 2.0 * first_length) ); - + return(end_rect); } @@ -434,12 +441,12 @@ QRectF PartLine::secondEndCircleRect() const QList interesting_points = fourEndPoints(m_line.p2(), m_line.p1(), second_length); - + QRectF end_rect( interesting_points[0] - QPointF(second_length, second_length), QSizeF(2.0 * second_length, 2.0 * second_length) ); - + return(end_rect); } @@ -448,7 +455,7 @@ QRectF PartLine::secondEndCircleRect() const @return the bounding rect of this part */ QRectF PartLine::boundingRect() const -{ +{ QRectF bound; if (first_end || second_end) bound = path().boundingRect(); @@ -537,13 +544,13 @@ QList PartLine::fourEndPoints(const QPointF &end_point, const QPointF & //Unitary vector and perpendicular vector QPointF u(line_vector / line_length * length); QPointF v(-u.y(), u.x()); - + // points O, A, B, C QPointF o(end_point - u); QPointF a(o - u); QPointF b(o + v); QPointF c(o - v); - + return(QList() << o << a << b << c); } diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index e859ef8b4..0875781de 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -66,7 +66,14 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio applyStylesToQPainter(*painter); QPen t = painter -> pen(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove t.setCosmetic(options && options -> levelOfDetail < 1.0); +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0); +#endif if (isSelected()) t.setColor(Qt::red); painter -> setPen(t); @@ -95,7 +102,7 @@ void PartPolygon::fromXml(const QDomElement &qde) else break; } - + QPolygonF temp_polygon; for (int j = 1 ; j < i ; ++ j) { @@ -103,7 +110,7 @@ void PartPolygon::fromXml(const QDomElement &qde) qde.attribute(QString("y%1").arg(j)).toDouble()); } m_polygon = temp_polygon; - + m_closed = qde.attribute("closed") != "false"; } @@ -290,7 +297,7 @@ void PartPolygon::resetAllHandlerColor() @brief PartPolygon::itemChange @param change @param value - @return + @return */ QVariant PartPolygon::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { @@ -300,8 +307,8 @@ QVariant PartPolygon::itemChange(QGraphicsItem::GraphicsItemChange change, const { //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged); - + connect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged); + if (scene()->selectedItems().size() == 1) addHandler(); } @@ -319,10 +326,10 @@ QVariant PartPolygon::itemChange(QGraphicsItem::GraphicsItemChange change, const { if(scene()) disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged); - + setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed. } - + return QGraphicsItem::itemChange(change, value); } @@ -330,7 +337,7 @@ QVariant PartPolygon::itemChange(QGraphicsItem::GraphicsItemChange change, const @brief PartPolygon::sceneEventFilter @param watched @param event - @return + @return */ bool PartPolygon::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { @@ -338,7 +345,7 @@ bool PartPolygon::sceneEventFilter(QGraphicsItem *watched, QEvent *event) if(watched->type() == QetGraphicsHandlerItem::Type) { QetGraphicsHandlerItem *qghi = qgraphicsitem_cast(watched); - + if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize { m_vector_index = m_handler_vector.indexOf(qghi); @@ -362,7 +369,7 @@ bool PartPolygon::sceneEventFilter(QGraphicsItem *watched, QEvent *event) } } } - + return false; } @@ -397,7 +404,7 @@ void PartPolygon::adjusteHandlerPos() { if(m_handler_vector.isEmpty()) return; - + if (m_handler_vector.size() == m_polygon.size()) { QVector points_vector = mapToScene(m_polygon); @@ -421,7 +428,7 @@ void PartPolygon::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphics { Q_UNUSED(qghi); Q_UNUSED(event); - + m_undo_command = new QPropertyUndoCommand(this, "polygon", QVariant(m_polygon)); m_undo_command->setText(tr("Modifier un polygone")); } @@ -434,12 +441,12 @@ void PartPolygon::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphics void PartPolygon::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event) { Q_UNUSED(qghi); - + QPointF new_pos = event->scenePos(); if (event->modifiers() != Qt::ControlModifier) new_pos = elementScene()->snapToGrid(event->scenePos()); new_pos = mapFromScene(new_pos); - + prepareGeometryChange(); m_polygon.replace(m_vector_index, new_pos); adjusteHandlerPos(); @@ -455,7 +462,7 @@ void PartPolygon::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphi { Q_UNUSED(qghi); Q_UNUSED(event); - + m_undo_command->setNewValue(QVariant(m_polygon)); elementScene()->undoStack().push(m_undo_command); m_undo_command = nullptr; @@ -481,9 +488,9 @@ void PartPolygon::sceneSelectionChanged() void PartPolygon::addHandler() { if (m_handler_vector.isEmpty() && scene()) - { + { m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(m_polygon)); - + for(QetGraphicsHandlerItem *handler : m_handler_vector) { handler->setColor(Qt::blue); @@ -514,7 +521,7 @@ void PartPolygon::removeHandler() void PartPolygon::insertPoint() { QPolygonF new_polygon = QetGraphicsHandlerUtility::polygonForInsertPoint(m_polygon, m_closed, elementScene()->snapToGrid(m_context_menu_pos)); - + if(new_polygon != m_polygon) { //Wrap the undo for avoid to merge the undo commands when user add several points. @@ -532,7 +539,7 @@ void PartPolygon::removePoint() { if (m_handler_vector.size() == 2) return; - + QPointF point = mapToScene(m_context_menu_pos); int index = -1; for (int i=0 ; ipolygon(); qDebug() << index; polygon.removeAt(index); - + //Wrap the undo for avoid to merge the undo commands when user add several points. QUndoCommand *undo = new QUndoCommand(tr("Supprimer un point d'un polygone")); new QPropertyUndoCommand(this, "polygon", this->polygon(), polygon, undo); elementScene()->undoStack().push(undo); } - + } /** diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 1ad7d7685..b087829cd 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -51,17 +51,23 @@ void PartRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt Q_UNUSED(widget); applyStylesToQPainter(*painter); QPen t = painter -> pen(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove t.setCosmetic(options && options -> levelOfDetail < 1.0); - +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0); +#endif if (isSelected()) t.setColor(Qt::red); t.setJoinStyle(Qt::MiterJoin); - + //Force the pen to width 0 if one of dimension is null if (!rect().width() || !rect().height()) t.setWidth(0); - + painter->setPen(t); painter->drawRoundedRect(m_rect, m_xRadius, m_yRadius); @@ -86,7 +92,7 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const xml_element.setAttribute("y", QString("%1").arg(top_left.y())); xml_element.setAttribute("width", QString("%1").arg(m_rect.width())); xml_element.setAttribute("height", QString("%1").arg(m_rect.height())); - + QRectF rect = m_rect.normalized(); qreal x = m_xRadius; if (x > rect.width()/2) { @@ -96,10 +102,10 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const 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); return(xml_element); } @@ -272,7 +278,7 @@ void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos()) switchResizeMode(); - + CustomElementGraphicPart::mouseReleaseEvent(event); } @@ -280,7 +286,7 @@ void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) @brief PartRectangle::itemChange @param change @param value - @return + @return */ QVariant PartRectangle::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { @@ -290,8 +296,8 @@ QVariant PartRectangle::itemChange(QGraphicsItem::GraphicsItemChange change, con { //When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler, //according to the number of selected items. - connect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged); - + connect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged); + if (scene()->selectedItems().size() == 1) addHandler(); } @@ -309,10 +315,10 @@ QVariant PartRectangle::itemChange(QGraphicsItem::GraphicsItemChange change, con { if(scene()) disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged); - + setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed. } - + return QGraphicsItem::itemChange(change, value); } @@ -320,7 +326,7 @@ QVariant PartRectangle::itemChange(QGraphicsItem::GraphicsItemChange change, con @brief PartRectangle::sceneEventFilter @param watched @param event - @return + @return */ bool PartRectangle::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { @@ -328,7 +334,7 @@ bool PartRectangle::sceneEventFilter(QGraphicsItem *watched, QEvent *event) if(watched->type() == QetGraphicsHandlerItem::Type) { QetGraphicsHandlerItem *qghi = qgraphicsitem_cast(watched); - + if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize { m_vector_index = m_handler_vector.indexOf(qghi); @@ -352,7 +358,7 @@ bool PartRectangle::sceneEventFilter(QGraphicsItem *watched, QEvent *event) } } } - + return false; } @@ -397,16 +403,16 @@ void PartRectangle::adjusteHandlerPos() if (m_handler_vector.isEmpty()) { return; } - + QVector 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()) { points_vector = mapToScene(points_vector); @@ -430,7 +436,7 @@ void PartRectangle::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphi { Q_UNUSED(qghi) Q_UNUSED(event) - + m_old_rect = m_rect; m_old_xRadius = m_xRadius; m_old_yRadius = m_yRadius; @@ -447,12 +453,12 @@ void PartRectangle::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphi void PartRectangle::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event) { Q_UNUSED(qghi) - + QPointF new_pos = event->scenePos(); if (event->modifiers() != Qt::ControlModifier) new_pos = elementScene()->snapToGrid(event->scenePos()); new_pos = mapFromScene(new_pos); - + if (m_resize_mode == 1) setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index)); else if (m_resize_mode == 2) @@ -471,7 +477,7 @@ void PartRectangle::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphic setYRadius(radius); } } - + adjusteHandlerPos(); } @@ -479,9 +485,9 @@ void PartRectangle::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGrap { Q_UNUSED(qghi) Q_UNUSED(event) - + m_modifie_radius_equaly = false; - + 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); @@ -495,7 +501,7 @@ void PartRectangle::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGrap QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "yRadius", QVariant(m_old_yRadius), QVariant(m_yRadius), undo); u->setAnimated(); } - + elementScene()->undoStack().push(undo); m_vector_index = -1; } @@ -519,21 +525,21 @@ void PartRectangle::sceneSelectionChanged() void PartRectangle::addHandler() { if (m_handler_vector.isEmpty() && scene()) - { + { 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) { QColor color; if(m_resize_mode == 1) {color = Qt::blue;} else if (m_resize_mode == 2) {color = Qt::darkGreen;} else {color = Qt::magenta;} - + handler->setColor(color); scene()->addItem(handler); handler->installSceneEventFilter(this); diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 0f8621f19..9fe3728a5 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -62,37 +62,52 @@ const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const /** Dessine la borne - @param p QPainter a utiliser pour rendre le dessin + @param painter QPainter a utiliser pour rendre le dessin @param options Options pour affiner le rendu @param widget Widget sur lequel le rendu est effectue */ -void PartTerminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidget *widget) { +void PartTerminal::paint( + QPainter *painter, + const QStyleOptionGraphicsItem *options, + QWidget *widget) +{ Q_UNUSED(widget); - p -> save(); + painter -> save(); // annulation des renderhints - p -> setRenderHint(QPainter::Antialiasing, false); - p -> setRenderHint(QPainter::TextAntialiasing, false); - p -> setRenderHint(QPainter::SmoothPixmapTransform, false); + painter -> setRenderHint(QPainter::Antialiasing, false); + painter -> setRenderHint(QPainter::TextAntialiasing, false); + painter -> setRenderHint(QPainter::SmoothPixmapTransform, false); QPen t; t.setWidthF(1.0); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove t.setCosmetic(options && options -> levelOfDetail < 1.0); - +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + t.setCosmetic( + options + && options->levelOfDetailFromTransform( + painter->worldTransform()) + < 1.0); +#endif // dessin de la borne en rouge t.setColor(isSelected() ? Terminal::neutralColor : Qt::red); - p -> setPen(t); - p -> drawLine(QPointF(0.0, 0.0), d -> second_point); + painter -> setPen(t); + painter -> drawLine(QPointF(0.0, 0.0), d -> second_point); // dessin du point d'amarrage au conducteur en bleu t.setColor(isSelected() ? Qt::red : Terminal::neutralColor); - p -> setPen(t); - p -> setBrush(Terminal::neutralColor); - p -> drawPoint(QPointF(0.0, 0.0)); - p -> restore(); + painter -> setPen(t); + painter -> setBrush(Terminal::neutralColor); + painter -> drawPoint(QPointF(0.0, 0.0)); + painter -> restore(); if (m_hovered) - drawShadowShape(p); + drawShadowShape(painter); } /** diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index 49f7beafd..0f323acff 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -55,7 +55,10 @@ class PartTerminal : public CustomElementGraphicPart { QString xmlName() const override { return(QString("terminal")); } void fromXml(const QDomElement &) override; const QDomElement toXml(QDomDocument &) const override; - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; + void paint( + QPainter *painter, + const QStyleOptionGraphicsItem *, + QWidget *) override; QPainterPath shape() const override; QPainterPath shadowShape() const override {return shape();} @@ -70,7 +73,7 @@ class PartTerminal : public CustomElementGraphicPart { void setName(QString& name); void setNewUuid(); - + private: void updateSecondPoint(); TerminalData* d; // pointer to the terminal data diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 1befcfa1b..a3de13335 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -262,23 +262,30 @@ void Terminal::removeConductor(Conductor *conductor) /** @brief Terminal::paint Fonction de dessin des bornes - @param p Le QPainter a utiliser + @param painter Le QPainter a utiliser @param options Les options de dessin */ void Terminal::paint( - QPainter *p, + QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *) { // en dessous d'un certain zoom, les bornes ne sont plus dessinees +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove if (options && options -> levelOfDetail < 0.5) return; - - p -> save(); +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + if (options && options->levelOfDetailFromTransform(painter->worldTransform()) < 0.5) + return; +#endif + painter -> save(); //annulation des renderhints - p -> setRenderHint(QPainter::Antialiasing, false); - p -> setRenderHint(QPainter::TextAntialiasing, false); - p -> setRenderHint(QPainter::SmoothPixmapTransform, false); + painter -> setRenderHint(QPainter::Antialiasing, false); + painter -> setRenderHint(QPainter::TextAntialiasing, false); + painter -> setRenderHint(QPainter::SmoothPixmapTransform, false); // on travaille avec les coordonnees de l'element parent QPointF c = mapFromParent(d->m_pos); @@ -287,23 +294,31 @@ void Terminal::paint( QPen t; t.setWidthF(1.0); - if (options && options -> levelOfDetail < 1.0) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove + if (options && options -> levelOfDetail < 1.0) +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + if (options && options->levelOfDetailFromTransform(painter->worldTransform()) < 1.0) +#endif + { t.setCosmetic(true); } // dessin de la borne en rouge t.setColor(Qt::red); - p -> setPen(t); - p -> drawLine(c, e); + painter -> setPen(t); + painter -> drawLine(c, e); // dessin du point d'amarrage au conducteur en bleu t.setColor(hovered_color_); - p -> setPen(t); - p -> setBrush(hovered_color_); + painter -> setPen(t); + painter -> setBrush(hovered_color_); if (hovered_) { - p -> setRenderHint(QPainter::Antialiasing, true); - p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0)); - } else p -> drawPoint(c); + painter -> setRenderHint(QPainter::Antialiasing, true); + painter -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0)); + } else painter -> drawPoint(c); //Draw help line if needed, if (diagram() && m_draw_help_line) @@ -365,7 +380,7 @@ void Terminal::paint( m_help_line_a -> setLine(line); } - p -> restore(); + painter -> restore(); } /** diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 6250fe52e..7e0ca59f6 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -1,17 +1,17 @@ /* Copyright 2006-2020 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 . */ @@ -38,7 +38,7 @@ class Terminal : public QGraphicsObject signals: void conductorWasAdded(Conductor *conductor); void conductorWasRemoved(Conductor *conductor); - + // constructors, destructor public: Terminal(QPointF, Qet::Orientation, Element * = nullptr); @@ -47,10 +47,10 @@ class Terminal : public QGraphicsObject Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr); ~Terminal() override; - + private: Terminal(const Terminal &); - + // methods public: /** @@ -60,13 +60,15 @@ class Terminal : public QGraphicsObject @return the QGraphicsItem type */ int type() const override { return Type; } - - void paint (QPainter *,const QStyleOptionGraphicsItem *, - QWidget *) override; + + void paint( + QPainter *painter, + const QStyleOptionGraphicsItem *, + QWidget *) override; void drawHelpLine (bool draw = true); QLineF HelpLine () const; QRectF boundingRect () const override; - + // methods to manage conductors attached to the terminal Terminal* alignedWithTerminal () const; bool addConductor (Conductor *conductor); @@ -75,7 +77,7 @@ class Terminal : public QGraphicsObject Diagram *diagram () const; Element *parentElement () const; QUuid uuid () const; - + QList conductors() const; Qet::Orientation orientation() const; QPointF dockConductor() const; @@ -86,12 +88,12 @@ class Terminal : public QGraphicsObject void updateConductor(); bool isLinkedTo(Terminal *); bool canBeLinkedTo(Terminal *); - + // methods related to XML import/export static bool valideXml(QDomElement &); bool fromXml (QDomElement &); QDomElement toXml (QDomDocument &) const; - + protected: // methods related to events management void hoverEnterEvent (QGraphicsSceneHoverEvent *) override; @@ -100,7 +102,7 @@ class Terminal : public QGraphicsObject void mousePressEvent (QGraphicsSceneMouseEvent *) override; void mouseMoveEvent (QGraphicsSceneMouseEvent *) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override; - + // attributes public: enum { Type = UserType + 1002 }; @@ -116,7 +118,7 @@ class Terminal : public QGraphicsObject static QColor warningColor; /// color for forbidden actions static QColor forbiddenColor; - + private: bool m_draw_help_line{false}; QGraphicsLineItem *m_help_line{nullptr}; @@ -127,10 +129,10 @@ class Terminal : public QGraphicsObject /// Parent electrical element Element *parent_element_{nullptr}; - public: + public: /// docking point for parent element QPointF dock_elmt_; - private: + private: /// List of conductors attached to the terminal QList conductors_; /** @@ -150,7 +152,7 @@ class Terminal : public QGraphicsObject /// Name of Terminal QString name_terminal_; bool name_terminal_hidden; - + private: void init(QString number, QString name, bool hiddenName); void init(QPointF pf, Qet::Orientation o, QString number, @@ -185,6 +187,6 @@ inline QString Terminal::name() const } QList relatedPotentialTerminal (const Terminal *terminal, - const bool all_diagram = true); + const bool all_diagram = true); #endif