diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 91092c4f6..0532fa422 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -44,6 +44,7 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Diagram *parent_diagram) : QGraphicsPathItem(0, parent_diagram), terminal1(p1), terminal2(p2), + bMouseOver(false), destroyed_(false), text_item(0), segments(NULL), @@ -444,6 +445,10 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi } } + // if mouse over conductor change size + if ( bMouseOver ) conductor_pen.setWidthF(3.0); + else conductor_pen.setWidthF(1.0); + // affectation du QPen et de la QBrush modifies au QPainter qp -> setBrush(conductor_brush); QPen final_conductor_pen = conductor_pen; @@ -687,9 +692,8 @@ void Conductor::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { void Conductor::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { Q_UNUSED(e); segments_squares_scale_ = 2.0; - if (isSelected()) { - update(); - } + bMouseOver = true; + update(); } /** @@ -699,9 +703,8 @@ void Conductor::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { void Conductor::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { Q_UNUSED(e); segments_squares_scale_ = 1.0; - if (isSelected()) { - update(); - } + update(); + bMouseOver = false; } /** diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index 00ef962c2..3f0651f06 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -130,6 +130,8 @@ class Conductor : public QObject, public QGraphicsPathItem { virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *); virtual QVariant itemChange(GraphicsItemChange, const QVariant &); + bool bMouseOver; + private: /// Functional properties ConductorProperties properties_; diff --git a/sources/qetgraphicsitem/conductortextitem.cpp b/sources/qetgraphicsitem/conductortextitem.cpp index 004d894b7..b4f3ac299 100644 --- a/sources/qetgraphicsitem/conductortextitem.cpp +++ b/sources/qetgraphicsitem/conductortextitem.cpp @@ -30,7 +30,9 @@ ConductorTextItem::ConductorTextItem(Conductor *parent_conductor, Diagram *paren parent_conductor_(parent_conductor), moved_by_user_(false), rotate_by_user_(false) -{} +{ + setAcceptsHoverEvents(true); +} /** Constructeur @@ -201,3 +203,40 @@ void ConductorTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { QGraphicsTextItem::mouseReleaseEvent(e); } } + + + +/** + When mouse over element + change bMouseOver to true (used in paint() function ) + @param e QGraphicsSceneHoverEvent +*/ +void ConductorTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + + bMouseOver = true; + QString str_ToolTip = toPlainText(); + setToolTip( str_ToolTip ); + update(); +} + +/** + When mouse over element leave the position + change bMouseOver to false(used in paint() function ) + @param e QGraphicsSceneHoverEvent +*/ +void ConductorTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + //qDebug() << "Leave mouse over"; + bMouseOver = false; + update(); +} + +/** + Do nothing default function . + @param e QGraphicsSceneHoverEvent +*/ +void ConductorTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + QGraphicsTextItem::hoverMoveEvent(e); +} diff --git a/sources/qetgraphicsitem/conductortextitem.h b/sources/qetgraphicsitem/conductortextitem.h index 7a2341e55..a8335ee1a 100644 --- a/sources/qetgraphicsitem/conductortextitem.h +++ b/sources/qetgraphicsitem/conductortextitem.h @@ -57,6 +57,11 @@ class ConductorTextItem : public DiagramTextItem { virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event); + protected: + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *); + // attributes private: Conductor *parent_conductor_; diff --git a/sources/qetgraphicsitem/diagramtextitem.cpp b/sources/qetgraphicsitem/diagramtextitem.cpp index 191e49cbb..ba94f601b 100644 --- a/sources/qetgraphicsitem/diagramtextitem.cpp +++ b/sources/qetgraphicsitem/diagramtextitem.cpp @@ -28,10 +28,12 @@ */ DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, Diagram *parent_diagram) : QGraphicsTextItem(parent, parent_diagram), + bMouseOver(false), previous_text_(), rotation_angle_(0.0), m_first_move (true) { + setAcceptsHoverEvents(true); build(); } @@ -43,10 +45,12 @@ DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, Diagram *parent_diagram) */ DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent, Diagram *parent_diagram) : QGraphicsTextItem(text, parent, parent_diagram), + bMouseOver(false), previous_text_(text), rotation_angle_(0.0) { build(); + setAcceptsHoverEvents(true); } /// Destructeur @@ -211,6 +215,24 @@ void DiagramTextItem::setFontSize(int &s) { void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter -> setRenderHint(QPainter::Antialiasing, false); QGraphicsTextItem::paint(painter, option, widget); + + if ( bMouseOver ) { + painter -> save(); + // Annulation des renderhints + painter -> setRenderHint(QPainter::Antialiasing, false); + painter -> setRenderHint(QPainter::TextAntialiasing, false); + painter -> setRenderHint(QPainter::SmoothPixmapTransform, false); + // Dessin du cadre de selection en gris + QPen t; + t.setColor(Qt::gray); + t.setStyle(Qt::DashDotLine); + painter -> setPen(t); + // Le dessin se fait a partir du rectangle delimitant + //painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10); + painter -> drawRoundRect(boundingRect().adjusted(0, 0, 0, 0), 10, 10); + painter -> restore(); + } + } /** @@ -366,3 +388,39 @@ void DiagramTextItem::edit() { editor->show(); } + + +/** + When mouse over element + change bMouseOver to true (used in paint() function ) + @param e QGraphicsSceneHoverEvent +*/ +void DiagramTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + + bMouseOver = true; + QString str_ToolTip = toPlainText(); + setToolTip( str_ToolTip ); + update(); +} + +/** + When mouse over element leave the position + change bMouseOver to false (used in paint() function ) + @param e QGraphicsSceneHoverEvent +*/ +void DiagramTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + //qDebug() << "Leave mouse over"; + bMouseOver = false; + update(); +} + +/** + Do nothing default function . + @param e QGraphicsSceneHoverEvent +*/ +void DiagramTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + QGraphicsTextItem::hoverMoveEvent(e); +} diff --git a/sources/qetgraphicsitem/diagramtextitem.h b/sources/qetgraphicsitem/diagramtextitem.h index 0ad86689d..708d20f83 100644 --- a/sources/qetgraphicsitem/diagramtextitem.h +++ b/sources/qetgraphicsitem/diagramtextitem.h @@ -76,8 +76,13 @@ class DiagramTextItem : public QGraphicsTextItem { virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event); + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *); + virtual void applyRotation(const qreal &); + bool bMouseOver; signals: /// signal emitted when the text field loses focus void lostFocus(); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index f1671d36b..d8c190b01 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -33,7 +33,8 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) : QetGraphicsItem(parent), internal_connections_(false), - must_highlight_(false) + must_highlight_(false), + bMouseOver(false) { Q_UNUSED(scene); @@ -41,7 +42,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) : uuid_ = QUuid::createUuid(); setZValue(10); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - + setAcceptsHoverEvents(true); } /** @@ -106,6 +107,8 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, // Dessin du cadre de selection si necessaire if (isSelected()) drawSelection(painter, options); + + if ( bMouseOver ) drawSelection(painter, options); } /** @@ -540,3 +543,39 @@ bool comparPos(const Element *elmt1, const Element *elmt2) { return elmt1->y() <= elmt2->pos().y(); return elmt1->pos().x() <= elmt2->pos().x(); } + + +/** + When mouse over element + change bMouseOver to true (used in paint() function ) + @param e QGraphicsSceneHoverEvent +*/ +void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + + bMouseOver = true; + QString str_ToolTip = name(); + setToolTip( str_ToolTip ); + update(); +} + +/** + When mouse over element leave the position + change bMouseOver to false(used in paint() function ) + @param e QGraphicsSceneHoverEvent +*/ +void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { + Q_UNUSED(e); + //qDebug() << "Leave mouse over"; + bMouseOver = 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 16ccbabf5..98578a118 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -186,6 +186,14 @@ class Element : public QetGraphicsItem { 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; + }; bool comparPos(const Element * elmt1, const Element * elmt2);