[qet] [3490] Light change in user interface |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3490
Author: runsys
Date: 2014-11-16 15:15:32 +0100 (Sun, 16 Nov 2014)
Log Message:
-----------
Light change in user interface
When mouse over a element, coonductor, text, the graphic symbol draw his bounding box.
and draw a tooltip with his name
For conductor the conductor size change.
Modified Paths:
--------------
trunk/sources/qetgraphicsitem/conductor.cpp
trunk/sources/qetgraphicsitem/conductor.h
trunk/sources/qetgraphicsitem/conductortextitem.cpp
trunk/sources/qetgraphicsitem/conductortextitem.h
trunk/sources/qetgraphicsitem/diagramtextitem.cpp
trunk/sources/qetgraphicsitem/diagramtextitem.h
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/element.h
Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/conductor.cpp 2014-11-16 14:15:32 UTC (rev 3490)
@@ -44,6 +44,7 @@
QGraphicsPathItem(0, parent_diagram),
terminal1(p1),
terminal2(p2),
+ bMouseOver(false),
destroyed_(false),
text_item(0),
segments(NULL),
@@ -444,6 +445,10 @@
}
}
+ // 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::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e);
segments_squares_scale_ = 2.0;
- if (isSelected()) {
- update();
- }
+ bMouseOver = true;
+ update();
}
/**
@@ -699,9 +703,8 @@
void Conductor::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e);
segments_squares_scale_ = 1.0;
- if (isSelected()) {
- update();
- }
+ update();
+ bMouseOver = false;
}
/**
Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/conductor.h 2014-11-16 14:15:32 UTC (rev 3490)
@@ -130,6 +130,8 @@
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
+ bool bMouseOver;
+
private:
/// Functional properties
ConductorProperties properties_;
Modified: trunk/sources/qetgraphicsitem/conductortextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductortextitem.cpp 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/conductortextitem.cpp 2014-11-16 14:15:32 UTC (rev 3490)
@@ -30,7 +30,9 @@
parent_conductor_(parent_conductor),
moved_by_user_(false),
rotate_by_user_(false)
-{}
+{
+ setAcceptsHoverEvents(true);
+}
/**
Constructeur
@@ -201,3 +203,40 @@
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);
+}
Modified: trunk/sources/qetgraphicsitem/conductortextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductortextitem.h 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/conductortextitem.h 2014-11-16 14:15:32 UTC (rev 3490)
@@ -57,6 +57,11 @@
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_;
Modified: trunk/sources/qetgraphicsitem/diagramtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramtextitem.cpp 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/diagramtextitem.cpp 2014-11-16 14:15:32 UTC (rev 3490)
@@ -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(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::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 @@
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);
+}
Modified: trunk/sources/qetgraphicsitem/diagramtextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/diagramtextitem.h 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/diagramtextitem.h 2014-11-16 14:15:32 UTC (rev 3490)
@@ -76,8 +76,13 @@
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();
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/element.cpp 2014-11-16 14:15:32 UTC (rev 3490)
@@ -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 @@
uuid_ = QUuid::createUuid();
setZValue(10);
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
-
+ setAcceptsHoverEvents(true);
}
/**
@@ -106,6 +107,8 @@
// Dessin du cadre de selection si necessaire
if (isSelected()) drawSelection(painter, options);
+
+ if ( bMouseOver ) drawSelection(painter, options);
}
/**
@@ -540,3 +543,39 @@
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);
+}
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2014-11-15 17:15:43 UTC (rev 3489)
+++ trunk/sources/qetgraphicsitem/element.h 2014-11-16 14:15:32 UTC (rev 3490)
@@ -186,6 +186,14 @@
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);