diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index 18410e455..7fc536a45 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -785,6 +785,9 @@ void DynamicElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void DynamicElementTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + if (m_jump_highlight) + painter->fillRect(boundingRect(), QColor(69, 137, 255, 90)); + DiagramTextItem::paint(painter, option, widget); if (m_frame) @@ -1635,10 +1638,18 @@ void DynamicElementTextItem::zoomToLinkedElement() setSelected(false); ungrabMouse(); - QetGraphicsItem::showItem(zoomed_element); + Element::jumpTo(zoomed_element); } } +void DynamicElementTextItem::setJumpHighlight(bool on) +{ + if (on == m_jump_highlight) + return; + m_jump_highlight = on; + update(); +} + /** * @brief DynamicElementTextItem::parentElementRotationChanged * Called when the parent element is rotated diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 2a6044890..eb7cd8f09 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -106,6 +106,9 @@ class DynamicElementTextItem : public DiagramTextItem void setInfoName(const QString &info_name); QString infoName() const; Element *linkedElementShown() const; + /// Shaded blue for a moment: its symbol is where a jump landed + void setJumpHighlight(bool on); + bool isJumpHighlighted() const {return m_jump_highlight;} void setCompositeText(const QString &text); QString compositeText() const; void setFrame(const bool frame); @@ -197,6 +200,7 @@ class DynamicElementTextItem : public DiagramTextItem CrossRefItem *m_Xref_item = nullptr; QGraphicsTextItem *m_slave_Xref_item = nullptr; qreal m_text_width = -1; + bool m_jump_highlight = false; /// The text was emptied with its alignment kept (setPlainText()) bool m_emptied_aligned = false; QPointF m_initial_position; diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 98ab82b48..982b1ed22 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -50,6 +50,8 @@ #include #include #include +#include +#include "../diagramview.h" static const QString plcTerminalKeys[] = { QETInformation::ELMT_PLC_T1, @@ -263,15 +265,58 @@ void Element::setHighlighted(bool hl) */ void Element::showAsJumpTarget() { + //The symbol and its texts, so that the label jumped to is seen too + QList texts = dynamicTextItems(); + for (ElementTextItemGroup *group : textGroups()) + texts.append(group->texts()); + for (DynamicElementTextItem *text : std::as_const(texts)) + text->setJumpHighlight(true); + ++m_jump_highlight; update(); - QTimer::singleShot(2000, this, [this]() { - if (m_jump_highlight > 0) - --m_jump_highlight; - update(); + QPointer self(this); + QTimer::singleShot(3000, this, [self]() { + if (!self) return; + if (self->m_jump_highlight > 0) + --self->m_jump_highlight; + if (self->m_jump_highlight == 0) { + QList texts = self->dynamicTextItems(); + for (ElementTextItemGroup *group : self->textGroups()) + texts.append(group->texts()); + for (DynamicElementTextItem *text : std::as_const(texts)) + text->setJumpHighlight(false); + } + self->update(); }); } +/** + @brief Element::jumpTo + Go to @a target, the other end of a folio report or the master of a + cross reference: its folio is shown whole, as a page, without zooming + in on it, and the target and its texts are shaded blue for a moment, + so that the eye finds it on the page. + (The mouse pointer cannot be put on it: Wayland does not let a program + move the pointer.) +*/ +void Element::jumpTo(Element *target) +{ + if (!target || !target->diagram()) + return; + Diagram *diagram = target->diagram(); + diagram->showMe(); + diagram->clearSelection(); + target->setSelected(true); + for (QGraphicsView *view : diagram->views()) + { + if (auto *diagram_view = qobject_cast(view)) + diagram_view->zoomFit(); + else + view->fitInView(diagram->sceneRect(), Qt::KeepAspectRatio); + } + target->showAsJumpTarget(); +} + /** @brief Element::jumpTarget @return the element a double click on this one jumps to: the other end @@ -2402,7 +2447,7 @@ void Element::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) //move when the target is in the same scene as this. setSelected(false); ungrabMouse(); - QetGraphicsItem::showItem(target); + jumpTo(target); return; } QetGraphicsItem::mouseDoubleClickEvent(event); diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 8a7afb311..a18653d3b 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -179,6 +179,7 @@ class Element : public QetGraphicsItem void showAsJumpTarget(); bool isShownAsJumpTarget() const { return m_jump_highlight > 0; } Element *jumpTarget() const; + static void jumpTo(Element *target); void displayHelpLine(bool b = true); QSize size() const; QPixmap pixmap(); diff --git a/tests/qttest/report_jump_probe.cpp b/tests/qttest/report_jump_probe.cpp index f6aebe073..9e9bf6f2c 100644 --- a/tests/qttest/report_jump_probe.cpp +++ b/tests/qttest/report_jump_probe.cpp @@ -5,7 +5,7 @@ // A linked folio report shows a pointing hand under the mouse, on its // arrow and on the text that shows its label, and a double click on // either goes to the other end. The end jumped to is highlighted for a -// moment, independently of the hover highlight, which the mouse leaving +// moment, its texts too, independently of the hover highlight, which the mouse leaving // the end jumped from would clear at once. An unlinked report shows no // hand and has nowhere to jump to. #include @@ -112,10 +112,22 @@ int main(int argc, char **argv) doubleClick(one, going); check(coming->isSelected(), "the end jumped to is selected"); check(coming->isShownAsJumpTarget(), "the end jumped to is highlighted"); + { + bool texts_shaded = !coming->dynamicTextItems().isEmpty(); + for (DynamicElementTextItem *text : coming->dynamicTextItems()) + texts_shaded &= text->isJumpHighlighted(); + check(texts_shaded, "and its texts are shaded too"); + } hover(one, going, QEvent::GraphicsSceneHoverLeave); check(coming->isShownAsJumpTarget(), "leaving the report keeps the jump highlight"); - wait(2300); + wait(3300); check(!coming->isShownAsJumpTarget(), "the jump highlight goes after a moment"); + { + bool texts_plain = true; + for (DynamicElementTextItem *text : coming->dynamicTextItems()) + texts_plain &= !text->isJumpHighlighted(); + check(texts_plain, "and so does the shading of its texts"); + } // The text showing the label: a pointing hand, and a double click // jumps back.