From 3c94d9a05463b37127c42110c1ea7c15e4e036ef Mon Sep 17 00:00:00 2001 From: blacksun Date: Sun, 14 Dec 2014 18:51:49 +0000 Subject: [PATCH] Minor improvment : over element, highlight every linked elements git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3554 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qetgraphicsitem/element.cpp | 48 ++++++++++----------- sources/qetgraphicsitem/element.h | 21 +++++---- sources/qetgraphicsitem/elementtextitem.cpp | 28 +++++------- 3 files changed, 42 insertions(+), 55 deletions(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 1413925cc..6213ba9ef 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -34,7 +34,7 @@ Element::Element(QGraphicsItem *parent) : QetGraphicsItem(parent), internal_connections_(false), must_highlight_(false), - bMouseOver(false) + m_mouse_over(false) { link_type_ = Simple; uuid_ = QUuid::createUuid(); @@ -100,13 +100,11 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, #endif if (must_highlight_) drawHighlight(painter, options); - // Dessin de l'element lui-meme + //Draw the element himself paint(painter, options); - // Dessin du cadre de selection si necessaire - if (isSelected()) drawSelection(painter, options); - - if ( bMouseOver ) drawSelection(painter, options); + //Draw the selection rectangle + if ( isSelected() || m_mouse_over ) drawSelection(painter, options); } /** @@ -545,36 +543,34 @@ bool comparPos(const Element *elmt1, const Element *elmt2) { /** - When mouse over element - change bMouseOver to true (used in paint() function ) - @param e QGraphicsSceneHoverEvent + * When mouse over element + * change m_mouse_over to true (used in paint() function ) + * Also highlight linked elements + * @param e QGraphicsSceneHoverEvent */ void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { Q_UNUSED(e); - bMouseOver = true; - QString str_ToolTip = name(); - setToolTip( str_ToolTip ); + foreach (Element *elmt, linkedElements()) + elmt -> setHighlighted(true); + + m_mouse_over = true; + setToolTip( name() ); update(); } /** - When mouse over element leave the position - change bMouseOver to false(used in paint() function ) - @param e QGraphicsSceneHoverEvent + * When mouse over element leave the position + * change m_mouse_over to false(used in paint() function ) + * Also un-highlight linked elements + * @param e QGraphicsSceneHoverEvent */ void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { Q_UNUSED(e); - //qDebug() << "Leave mouse over"; - bMouseOver = false; + + foreach (Element *elmt, linkedElements()) + elmt -> setHighlighted(false); + + m_mouse_over = false; update(); } - -/** - Do nothing default function . - @param e QGraphicsSceneHoverEvent -*/ -void Element::hoverMoveEvent(QGraphicsSceneHoverEvent *e) { - Q_UNUSED(e); - QGraphicsItem::hoverMoveEvent(e); -} diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 6bde6c15b..53904fffc 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -176,21 +176,20 @@ class Element : public QetGraphicsItem { int orientation() const; protected: - void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); + void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); private: - bool internal_connections_; - bool must_highlight_; - void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); - void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); - void updatePixmap(); + bool internal_connections_; + bool must_highlight_; + void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); + void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); + void updatePixmap(); protected: - virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *); - virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *); - virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *); - - bool bMouseOver; + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * ); + private: + bool m_mouse_over; }; diff --git a/sources/qetgraphicsitem/elementtextitem.cpp b/sources/qetgraphicsitem/elementtextitem.cpp index b3d690575..4f754f9c3 100644 --- a/sources/qetgraphicsitem/elementtextitem.cpp +++ b/sources/qetgraphicsitem/elementtextitem.cpp @@ -289,15 +289,12 @@ void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { * @brief ElementTextItem::hoverEnterEvent * @param event */ -void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) - { - foreach (Element *elmt, parent_element_ -> linkedElements()) - elmt -> setHighlighted(true); +void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { + + if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) { + + if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_->isFree()) { - if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_->isFree()) - { setDefaultTextColor(Qt::blue); //Also color the child text if parent is a slave and linked @@ -307,22 +304,17 @@ void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) qgti -> setDefaultTextColor(Qt::blue); } } - else - { - DiagramTextItem::hoverEnterEvent(event); - } + + DiagramTextItem::hoverEnterEvent(event); } /** * @brief ElementTextItem::hoverLeaveEvent * @param event */ -void ElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) - { - foreach (Element *elmt, parent_element_ -> linkedElements()) - elmt -> setHighlighted(false); +void ElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + + if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) { if (defaultTextColor() != Qt::black) setDefaultTextColor(Qt::black);