diff --git a/qelectrotech.pro b/qelectrotech.pro index 997e6511f..e8d97d08d 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -163,7 +163,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \ $$files(sources/print/*.h) \ $$files(sources/TerminalStrip/*.h) \ $$files(sources/TerminalStrip/ui/*.h) \ - $$files(sources/TerminalStrip/UndoCommand/*.h) + $$files(sources/TerminalStrip/UndoCommand/*.h) \ + $$files(sources/TerminalStrip/GraphicsItem/*.h) SOURCES += $$files(sources/*.cpp) \ $$files(sources/editor/*.cpp) \ @@ -199,7 +200,8 @@ SOURCES += $$files(sources/*.cpp) \ $$files(sources/print/*.cpp) \ $$files(sources/TerminalStrip/*.cpp) \ $$files(sources/TerminalStrip/ui/*.cpp) \ - $$files(sources/TerminalStrip/UndoCommand/*.cpp) + $$files(sources/TerminalStrip/UndoCommand/*.cpp) \ + $$files(sources/TerminalStrip/GraphicsItem/*.cpp) # Needed for use promote QTreeWidget in terminalstripeditor.ui INCLUDEPATH += sources/TerminalStrip/ui diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp new file mode 100644 index 000000000..48b3de916 --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp @@ -0,0 +1,49 @@ +/* + Copyright 2006-2022 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 . +*/ +#include "terminalstripitem.h" +#include "../../qetgraphicsitem/qgraphicsitemutility.h" + +TerminalStripItem::TerminalStripItem(QPointer strip, QGraphicsItem *parent) : + QetGraphicsItem{parent}, + m_strip{strip}, + m_drawer{strip} +{ + setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + setAcceptHoverEvents(true); +} + +void TerminalStripItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option) + Q_UNUSED(widget) + + m_drawer.paint(painter); + + if (isSelected() || isHovered()) + { + QGIUtility::drawBoundingRectSelection(this, painter); + } +} + +QRectF TerminalStripItem::boundingRect() const +{ + auto br_ = m_drawer.boundingRect(); + br_.adjust(-5,-5,5,5); + + return br_; +} diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h new file mode 100644 index 000000000..e3410037e --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h @@ -0,0 +1,44 @@ +/* + Copyright 2006-2022 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 . +*/ +#ifndef TERMINALSTRIPITEM_H +#define TERMINALSTRIPITEM_H + +#include + +#include "terminalstriplayoutpattern.h" +#include "../../qetgraphicsitem/qetgraphicsitem.h" + +class TerminalStrip; + +class TerminalStripItem : public QetGraphicsItem +{ + Q_OBJECT + + public: + TerminalStripItem(QPointer strip, QGraphicsItem *parent = nullptr); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + QRectF boundingRect() const override; + + private: + QPointer m_strip; + TerminalStripDrawer m_drawer; + +}; + +#endif // TERMINALSTRIPITEM_H diff --git a/sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.cpp b/sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.cpp new file mode 100644 index 000000000..a299c9a2a --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.cpp @@ -0,0 +1,247 @@ +/* + Copyright 2006-2022 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 . +*/ +#include "terminalstriplayoutpattern.h" + +#include "../physicalterminal.h" +#include "../realterminal.h" +#include "../terminalstrip.h" + +#include + +/** + * @brief TerminalStripDrawer::TerminalStripDrawer + * @param strip + * @param pattern + */ +TerminalStripDrawer::TerminalStripDrawer(QPointer strip) : + m_strip(strip) +{} + +/** + * @brief TerminalStripDrawer::paint + * @param painter + */ +void TerminalStripDrawer::paint(QPainter *painter) +{ + if (m_strip) + { + //To draw text, QPainter need a Qrect. Instead of create an instance + //for each text, we re-use the same instance of QRect. + QRect text_rect; + painter->save(); + + auto pen_{painter->pen()}; + pen_.setColor(Qt::black); + pen_.setWidth(1); + + auto brush_ = painter->brush(); + brush_.setColor(Qt::white); + + painter->setPen(pen_); + painter->setBrush(brush_); + + //Draw header + painter->drawRect(m_pattern.m_header_rect); + + //Draw the header text + painter->save(); + + if (m_pattern.m_header_text_orientation == Qt::Horizontal) + { + text_rect.setRect(0,m_pattern.m_header_rect.y(),m_pattern.m_header_rect.width(),m_pattern.m_header_rect.height()); + } + else + { + painter->translate(m_pattern.m_header_rect.bottomLeft()); + painter->rotate(270); + text_rect.setRect(0,0,m_pattern.m_header_rect.height(),m_pattern.m_header_rect.width()); + } + + const auto text_{m_strip->installation() + " " + m_strip->location() + " " + m_strip->name()}; + painter->drawText(text_rect, text_, m_pattern.headerTextOption()); + painter->restore(); + + //Move painter pos to next drawing + painter->translate(m_pattern.m_header_rect.width(),0); + + //Draw spacer + painter->drawRect(m_pattern.m_spacer_rect); + //Move painter pos to next drawing + painter->translate(m_pattern.m_spacer_rect.width(),0); + + + //Draw terminals + const auto terminals_text_rect{m_pattern.m_terminals_text_rect}; + const auto terminals_text_orientation{m_pattern.m_terminals_text_orientation}; + const auto terminals_text_option{m_pattern.terminalsTextOption()}; + QRect terminal_rect; + + //Loop over physical terminals + for (const auto &physical_t : m_strip->physicalTerminal()) + { + //Get the good offset according to how many level have the current physical terminal + const QVector> real_terminal{physical_t->realTerminals()}; + const auto real_t_count{real_terminal.size()}; + const auto offset_{4 - real_t_count}; + + //Loop over real terminals + for (auto i=0 ; i= 4) { + break; + } + + terminal_rect = m_pattern.m_terminal_rect[index_]; + painter->drawRect(terminal_rect); + + //Draw text + painter->save(); + if (terminals_text_orientation[index_] == Qt::Horizontal) + { + text_rect = terminals_text_rect[index_]; + } + else + { + const auto rect_{terminals_text_rect[index_]}; + painter->translate(rect_.bottomLeft()); + painter->rotate(270); + text_rect.setRect(0, 0, rect_.height(), rect_.width()); + } + + const auto shared_real_terminal{real_terminal[i]}; + painter->drawText(text_rect, + shared_real_terminal ? shared_real_terminal->label() : QLatin1String(), + terminals_text_option[index_]); + painter->restore(); + + //Move painter pos to next drawing + painter->translate(terminal_rect.width(),0); + } + } + + painter->restore(); + } +} + +QRectF TerminalStripDrawer::boundingRect() const +{ + return QRect{0, 0, width(), height()};; +} + +int TerminalStripDrawer::height() const +{ + auto height_{m_pattern.m_header_rect.y() + m_pattern.m_header_rect.height()}; + + height_ = std::max(height_, m_pattern.m_spacer_rect.y() + m_pattern.m_spacer_rect.height()); + + for (const auto &rect : m_pattern.m_terminal_rect) { + height_ = std::max(height_, rect.y() + rect.height()); + } + + return height_; +} + +int TerminalStripDrawer::width() const +{ + int width_{m_pattern.m_header_rect.width() + m_pattern.m_spacer_rect.width()}; + + if (m_strip) + { + //Loop over physical terminals + for (const auto &physical_t : m_strip->physicalTerminal()) + { + //Get the good offset according to how many level have the current physical terminal + const QVector> real_terminal{physical_t->realTerminals()}; + const auto real_t_count{real_terminal.size()}; + const auto offset_{4 - real_t_count}; + + //Loop over real terminals + for (auto i=0 ; i= 4) { + break; + } + + width_ += m_pattern.m_terminal_rect[index_].width(); + } + } + } + + return width_; +} + +TerminalStripLayoutPattern::TerminalStripLayoutPattern() +{ + updateHeaderTextOption(); + updateTerminalsTextOption(); +} + +void TerminalStripLayoutPattern::setHeaderTextAlignment(const Qt::Alignment &alignment) +{ + m_header_text_alignment = alignment; + updateHeaderTextOption(); +} + +Qt::Alignment TerminalStripLayoutPattern::headerTextAlignment() const +{ + return m_header_text_alignment; +} + +QTextOption TerminalStripLayoutPattern::headerTextOption() const { + return m_header_text_option; +} + +void TerminalStripLayoutPattern::setTerminalsTextAlignment(const QVector &alignment) +{ + m_terminals_text_alignment = alignment; + updateTerminalsTextOption(); +} + +QVector TerminalStripLayoutPattern::terminalsTextAlignment() const +{ + return m_terminals_text_alignment; +} + +QVector TerminalStripLayoutPattern::terminalsTextOption() const +{ + return m_terminals_text_option; +} + +void TerminalStripLayoutPattern::updateHeaderTextOption() +{ + m_header_text_option.setAlignment(m_header_text_alignment); + m_header_text_option.setWrapMode(QTextOption::WordWrap); +} + +void TerminalStripLayoutPattern::updateTerminalsTextOption() +{ + if (m_terminals_text_option.size() == + m_terminals_text_alignment.size()) + { + for (auto i = 0 ; i. +*/ +#ifndef TERMINALSTRIPLAYOUTPATTERN_H +#define TERMINALSTRIPLAYOUTPATTERN_H + +#include +#include +#include +#include +#include + +class QPainter; +class TerminalStrip; + +/** + * @brief The TerminalStripLayoutPattern class + * A class with all values used to define how a terminal strip must be drawn. + * Most of the value are public, some values are private and have getter / setter + * because when these values change we need to compute the change. + * + * The values with name '_y_offset' mean offset is relating to the top + * of the QGraphicsItem used to display the terminal strip. + * + * The terminal strip can display up to 4 terminal level, + * the value used for multilevel terminal are stored in several QVector (m_terminal_y_offset, m_terminal_height, m_bridge_point_y_offset). + * The order of the values are from the most back terminal to the front terminal. + */ +class TerminalStripLayoutPattern +{ + public: + TerminalStripLayoutPattern(); + + //Header of terminal strip + QRect m_header_rect{0,30,50,130}; + Qt::Orientation m_header_text_orientation{Qt::Horizontal}; + void setHeaderTextAlignment(const Qt::Alignment &alignment); + Qt::Alignment headerTextAlignment() const; + QTextOption headerTextOption() const; + + //Spacer between the header and the terminals + QRect m_spacer_rect{0, 50, 10, 90}; + + //Terminals + QVector m_terminal_rect + { + QRect{0, 0, 20, 190}, + QRect{0, 10, 20, 170}, + QRect{0, 20, 20, 150}, + QRect{0, 30, 20, 130} + }; + + void setTerminalsTextAlignment(const QVector &alignment); + QVector terminalsTextAlignment() const; + QVector terminalsTextOption() const; + + QVector m_terminals_text_rect + { + QRect{0,35,20,50}, + QRect{0,35,20,50}, + QRect{0,35,20,50}, + QRect{0,35,20,50} + }; + QVector m_terminals_text_orientation + { + Qt::Vertical, + Qt::Vertical, + Qt::Vertical, + Qt::Vertical + }; + + int m_bridge_point_d{5}; + QVector m_bridge_point_y_offset{50,70,90,110}; + + private: + void updateHeaderTextOption(); + void updateTerminalsTextOption(); + + private: + Qt::Alignment m_header_text_alignment{Qt::AlignCenter}; + QTextOption m_header_text_option; + + QVector m_terminals_text_alignment + { + Qt::AlignRight | Qt::AlignVCenter, + Qt::AlignRight | Qt::AlignVCenter, + Qt::AlignRight | Qt::AlignVCenter, + Qt::AlignRight | Qt::AlignVCenter + }; + QVector m_terminals_text_option + { + QTextOption(), + QTextOption(), + QTextOption(), + QTextOption() + }; +}; + +class TerminalStripDrawer +{ + public: + TerminalStripDrawer(QPointer strip); + void paint(QPainter *painter); + + QRectF boundingRect() const; + + private: + int height() const; + int width() const; + + private: + QPointer m_strip; + TerminalStripLayoutPattern m_pattern; +}; + +#endif // TERMINALSTRIPLAYOUTPATTERN_H diff --git a/sources/TerminalStrip/ui/addterminalstripitemdialog.cpp b/sources/TerminalStrip/ui/addterminalstripitemdialog.cpp new file mode 100644 index 000000000..44f54de47 --- /dev/null +++ b/sources/TerminalStrip/ui/addterminalstripitemdialog.cpp @@ -0,0 +1,85 @@ +/* + Copyright 2006-2022 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 . +*/ +#include "addterminalstripitemdialog.h" +#include "ui_addterminalstripitemdialog.h" + +#include "../terminalstrip.h" +#include "../GraphicsItem/terminalstripitem.h" +#include "../../diagram.h" + +void AddTerminalStripItemDialog::openDialog(Diagram *diagram, QWidget *parent) +{ + AddTerminalStripItemDialog d(diagram->project(), parent); + if (d.exec()) + { + const auto strip_{d.selectedTerminalStrip()}; + if (strip_) + { + auto item_ = new TerminalStripItem(strip_); + diagram->addItem(item_); + item_->setPos(20, 20); + } + } +} + +AddTerminalStripItemDialog::AddTerminalStripItemDialog(QETProject *project, QWidget *parent) : + QDialog{parent}, + m_project{project}, + ui{new Ui::AddTerminalStripItemDialog} +{ + ui->setupUi(this); + fillComboBox(); +} + +AddTerminalStripItemDialog::~AddTerminalStripItemDialog() +{ + delete ui; +} + +/** + * @brief AddTerminalStripItemDialog::selectedTerminalStrip + * @return The selected terminal strip or nullptr if no one is selected + * or error encounted. + */ +TerminalStrip *AddTerminalStripItemDialog::selectedTerminalStrip() const +{ + if (m_project) + { + QUuid uuid_{ui->m_terminal_strip_cb->currentData().toUuid()}; + for (const auto &strip_ : m_project->terminalStrip()) + { + if (strip_->uuid() == uuid_) { + return strip_; + } + } + } + + return nullptr; +} + +void AddTerminalStripItemDialog::fillComboBox() +{ + if (m_project) + { + for (const auto strip_ : m_project->terminalStrip()) + { + const auto text{strip_->installation() + " " + strip_->location() + " " + strip_->name()}; + ui->m_terminal_strip_cb->addItem(text, strip_->uuid()); + } + } +} diff --git a/sources/TerminalStrip/ui/addterminalstripitemdialog.h b/sources/TerminalStrip/ui/addterminalstripitemdialog.h new file mode 100644 index 000000000..e7eae36f9 --- /dev/null +++ b/sources/TerminalStrip/ui/addterminalstripitemdialog.h @@ -0,0 +1,51 @@ +/* + Copyright 2006-2022 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 . +*/ +#ifndef ADDTERMINALSTRIPITEMDIALOG_H +#define ADDTERMINALSTRIPITEMDIALOG_H + +#include +#include + +class Diagram; +class QETDiagramEditor; +class QETProject; +class TerminalStrip; + +namespace Ui { + class AddTerminalStripItemDialog; +} + +class AddTerminalStripItemDialog : public QDialog +{ + Q_OBJECT + + public: + static void openDialog(Diagram *diagram, QWidget *parent = nullptr); + + private: + explicit AddTerminalStripItemDialog(QETProject *project, QWidget *parent = nullptr); + ~AddTerminalStripItemDialog(); + TerminalStrip *selectedTerminalStrip() const; + void fillComboBox(); + + private: + QPointer m_project; + Ui::AddTerminalStripItemDialog *ui; +}; + +#endif // ADDTERMINALSTRIPITEMDIALOG_H diff --git a/sources/TerminalStrip/ui/addterminalstripitemdialog.ui b/sources/TerminalStrip/ui/addterminalstripitemdialog.ui new file mode 100644 index 000000000..34c4f937d --- /dev/null +++ b/sources/TerminalStrip/ui/addterminalstripitemdialog.ui @@ -0,0 +1,87 @@ + + + AddTerminalStripItemDialog + + + + 0 + 0 + 326 + 100 + + + + Dialog + + + + + + Ajouter le plan de bornes suivant : + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AddTerminalStripItemDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddTerminalStripItemDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 08ddcac02..db362aa0b 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -44,6 +44,7 @@ #include "diagram.h" #include "TerminalStrip/ui/terminalstripeditorwindow.h" #include "ui/diagrameditorhandlersizewidget.h" +#include "TerminalStrip/ui/addterminalstripitemdialog.h" #ifdef BUILD_WITHOUT_KF5 #else @@ -664,6 +665,7 @@ void QETDiagramEditor::setUpActions() QAction *add_rectangle = m_add_item_actions_group.addAction(QET::Icons::PartRectangle, tr("Ajouter un rectangle")); QAction *add_ellipse = m_add_item_actions_group.addAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse")); QAction *add_polyline = m_add_item_actions_group.addAction(QET::Icons::PartPolygon, tr("Ajouter une polyligne")); + QAction *add_terminal_strip = m_add_item_actions_group.addAction(QET::Icons::TerminalStrip, tr("Ajouter un plan de bornes")); add_text ->setStatusTip(tr("Ajoute un champ de texte sur le folio actuel")); add_image ->setStatusTip(tr("Ajoute une image sur le folio actuel")); @@ -671,6 +673,7 @@ void QETDiagramEditor::setUpActions() add_rectangle->setStatusTip(tr("Ajoute un rectangle sur le folio actuel")); add_ellipse ->setStatusTip(tr("Ajoute une ellipse sur le folio actuel")); add_polyline ->setStatusTip(tr("Ajoute une polyligne sur le folio actuel")); + add_terminal_strip->setStatusTip(tr("Ajoute un plan de bornier sur le folio actuel")); add_text ->setData("text"); add_image ->setData("image"); @@ -678,6 +681,7 @@ void QETDiagramEditor::setUpActions() add_rectangle->setData("rectangle"); add_ellipse ->setData("ellipse"); add_polyline ->setData("polyline"); + add_terminal_strip->setData(QStringLiteral("terminal_strip")); for(QAction *action : m_add_item_actions_group.actions()) { action->setCheckable(true); @@ -1430,7 +1434,17 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) diagram_event = deai; } else if (value == "text") + { diagram_event = new DiagramEventAddText(d); + } + else if (value == QLatin1String("terminal_strip")) + { + const auto diagram_view{currentDiagramView()}; + if (diagram_view) + { + AddTerminalStripItemDialog::openDialog(diagram_view->diagram(), this); + } + } if (diagram_event) { diff --git a/sources/qetgraphicsitem/qetgraphicsitem.cpp b/sources/qetgraphicsitem/qetgraphicsitem.cpp index e1c9bc6a0..6c952e25c 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.cpp +++ b/sources/qetgraphicsitem/qetgraphicsitem.cpp @@ -64,6 +64,10 @@ void QetGraphicsItem::setPos(qreal x, qreal y) { setPos(QPointF(x, y)); } +bool QetGraphicsItem::isHovered() const { + return m_hovered; +} + /** @brief QetGraphicsItem::state @return the current state of this item @@ -155,3 +159,15 @@ void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) event->accept(); } } + +void QetGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + m_hovered = true; + QGraphicsObject::hoverEnterEvent(event); +} + +void QetGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + m_hovered = false; + QGraphicsObject::hoverLeaveEvent(event); +} diff --git a/sources/qetgraphicsitem/qetgraphicsitem.h b/sources/qetgraphicsitem/qetgraphicsitem.h index 5c7742c35..5c33b63b5 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.h +++ b/sources/qetgraphicsitem/qetgraphicsitem.h @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2021 The QElectroTech Team This file is part of QElectroTech. @@ -42,6 +42,8 @@ class QetGraphicsItem : public QGraphicsObject {return is_movable_;} virtual void setMovable (bool movable) { is_movable_ = movable;} + bool isHovered() const; + virtual void editProperty () {} virtual QString name ()const {return QString("");} @@ -54,6 +56,8 @@ class QetGraphicsItem : public QGraphicsObject void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; protected: bool is_movable_; @@ -62,6 +66,9 @@ class QetGraphicsItem : public QGraphicsObject QPointF m_mouse_to_origin_movement; QET::GraphicsItemState m_state = QET:: GIOK; + private: + bool m_hovered{false}; + }; #endif // QETGRAPHICSITEM_H diff --git a/sources/qetgraphicsitem/qgraphicsitemutility.cpp b/sources/qetgraphicsitem/qgraphicsitemutility.cpp index 765980f77..1be9f32a2 100644 --- a/sources/qetgraphicsitem/qgraphicsitemutility.cpp +++ b/sources/qetgraphicsitem/qgraphicsitemutility.cpp @@ -90,5 +90,19 @@ bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_f return true; } + +void drawBoundingRectSelection(QGraphicsItem *item, QPainter *painter) +{ + painter->save(); + QPen t; + t.setColor(Qt::gray); + t.setStyle(Qt::DashDotLine); + t.setCosmetic(true); + + painter->setPen(t); + painter->drawRoundedRect(item->boundingRect(),10,10); + painter->restore(); +} + } diff --git a/sources/qetgraphicsitem/qgraphicsitemutility.h b/sources/qetgraphicsitem/qgraphicsitemutility.h index 2bb660696..09f9d292a 100644 --- a/sources/qetgraphicsitem/qgraphicsitemutility.h +++ b/sources/qetgraphicsitem/qgraphicsitemutility.h @@ -22,11 +22,13 @@ class QGraphicsItem; class Element; +class QPainter; namespace QGIUtility { bool centerToParentBottom (QGraphicsItem *item); bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 ); + void drawBoundingRectSelection(QGraphicsItem *item, QPainter *painter); } #endif // QGRAPHICSITEMUTILITY_H