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
This commit is contained in:
blacksun
2014-12-14 18:51:49 +00:00
parent d385c6f8cf
commit 3c94d9a054
3 changed files with 42 additions and 55 deletions

View File

@@ -34,7 +34,7 @@ Element::Element(QGraphicsItem *parent) :
QetGraphicsItem(parent), QetGraphicsItem(parent),
internal_connections_(false), internal_connections_(false),
must_highlight_(false), must_highlight_(false),
bMouseOver(false) m_mouse_over(false)
{ {
link_type_ = Simple; link_type_ = Simple;
uuid_ = QUuid::createUuid(); uuid_ = QUuid::createUuid();
@@ -100,13 +100,11 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
#endif #endif
if (must_highlight_) drawHighlight(painter, options); if (must_highlight_) drawHighlight(painter, options);
// Dessin de l'element lui-meme //Draw the element himself
paint(painter, options); paint(painter, options);
// Dessin du cadre de selection si necessaire //Draw the selection rectangle
if (isSelected()) drawSelection(painter, options); if ( isSelected() || m_mouse_over ) drawSelection(painter, options);
if ( bMouseOver ) drawSelection(painter, options);
} }
/** /**
@@ -545,36 +543,34 @@ bool comparPos(const Element *elmt1, const Element *elmt2) {
/** /**
When mouse over element * When mouse over element
change bMouseOver to true (used in paint() function ) * change m_mouse_over to true (used in paint() function )
@param e QGraphicsSceneHoverEvent * Also highlight linked elements
* @param e QGraphicsSceneHoverEvent
*/ */
void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) { void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e); Q_UNUSED(e);
bMouseOver = true; foreach (Element *elmt, linkedElements())
QString str_ToolTip = name(); elmt -> setHighlighted(true);
setToolTip( str_ToolTip );
m_mouse_over = true;
setToolTip( name() );
update(); update();
} }
/** /**
When mouse over element leave the position * When mouse over element leave the position
change bMouseOver to false(used in paint() function ) * change m_mouse_over to false(used in paint() function )
@param e QGraphicsSceneHoverEvent * Also un-highlight linked elements
* @param e QGraphicsSceneHoverEvent
*/ */
void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) { void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e); Q_UNUSED(e);
//qDebug() << "Leave mouse over";
bMouseOver = false; foreach (Element *elmt, linkedElements())
elmt -> setHighlighted(false);
m_mouse_over = false;
update(); update();
} }
/**
Do nothing default function .
@param e QGraphicsSceneHoverEvent
*/
void Element::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e);
QGraphicsItem::hoverMoveEvent(e);
}

View File

@@ -176,21 +176,20 @@ class Element : public QetGraphicsItem {
int orientation() const; int orientation() const;
protected: protected:
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
private: private:
bool internal_connections_; bool internal_connections_;
bool must_highlight_; bool must_highlight_;
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
void updatePixmap(); void updatePixmap();
protected: protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * );
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * );
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *); private:
bool m_mouse_over;
bool bMouseOver;
}; };

View File

@@ -289,15 +289,12 @@ void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
* @brief ElementTextItem::hoverEnterEvent * @brief ElementTextItem::hoverEnterEvent
* @param event * @param event
*/ */
void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
{
if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) {
{
foreach (Element *elmt, parent_element_ -> linkedElements()) if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_->isFree()) {
elmt -> setHighlighted(true);
if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_->isFree())
{
setDefaultTextColor(Qt::blue); setDefaultTextColor(Qt::blue);
//Also color the child text if parent is a slave and linked //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); qgti -> setDefaultTextColor(Qt::blue);
} }
} }
else
{ DiagramTextItem::hoverEnterEvent(event);
DiagramTextItem::hoverEnterEvent(event);
}
} }
/** /**
* @brief ElementTextItem::hoverLeaveEvent * @brief ElementTextItem::hoverLeaveEvent
* @param event * @param event
*/ */
void ElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void ElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
{
if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) if (tagg_ == "label" || parent_element_ -> linkType() & Element::AllReport) {
{
foreach (Element *elmt, parent_element_ -> linkedElements())
elmt -> setHighlighted(false);
if (defaultTextColor() != Qt::black) if (defaultTextColor() != Qt::black)
setDefaultTextColor(Qt::black); setDefaultTextColor(Qt::black);