From b517471bc41e849a4aba32dfb402e4393bc801af Mon Sep 17 00:00:00 2001 From: John Thacker Date: Sat, 24 Feb 2024 13:34:41 -0500 Subject: [PATCH] Qt: Show tooltip in sequence diagram for elided comments If the comment (i.e. Info column) text is elided, show the full text as a tooltip. We already show it down in the status hint text, but it's nice not to have to look all the way at the bottom of the window. Somewhat related to #4972 (I think, for that one, we will probably need to make the column width controlled by a different widget rather than a QSplitter, because making it a QSplitter would make the comments no longer an axis, and then they wouldn't be printed.) --- ui/qt/sequence_diagram.cpp | 19 ++++++++++++++++--- ui/qt/sequence_diagram.h | 2 ++ ui/qt/sequence_dialog.cpp | 17 +++++++++++++++++ ui/qt/sequence_dialog.h | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ui/qt/sequence_diagram.cpp b/ui/qt/sequence_diagram.cpp index 4452f095e5..2d33a606eb 100644 --- a/ui/qt/sequence_diagram.cpp +++ b/ui/qt/sequence_diagram.cpp @@ -149,8 +149,6 @@ void SequenceDiagram::setData(_seq_analysis_info *sainfo) double cur_key = 0.0; QVector key_ticks, val_ticks; QVector key_labels, val_labels, com_labels; - QFontMetrics com_fm(comment_axis_->tickLabelFont()); - int elide_w = com_fm.height() * max_comment_em_width_; char* addr_str; for (GList *cur = g_queue_peek_nth_link(sainfo->items, 0); cur; cur = gxx_list_next(cur)) { @@ -165,7 +163,7 @@ void SequenceDiagram::setData(_seq_analysis_info *sainfo) key_ticks.append(cur_key); key_labels.append(sai->time_str); - com_labels.append(com_fm.elidedText(sai->comment, Qt::ElideRight, elide_w)); + com_labels.append(elidedComment(sai->comment)); cur_key++; } @@ -211,6 +209,21 @@ _seq_analysis_item *SequenceDiagram::itemForPosY(int ypos) return NULL; } +bool SequenceDiagram::inComment(QPoint pos) const +{ + return pos.x() >= (comment_axis_->axisRect()->right() + + comment_axis_->padding() + + comment_axis_->tickLabelPadding() + + comment_axis_->offset()); +} + +QString SequenceDiagram::elidedComment(const QString &text) const +{ + QFontMetrics com_fm(comment_axis_->tickLabelFont()); + int elide_w = com_fm.height() * max_comment_em_width_; + return com_fm.elidedText(text, Qt::ElideRight, elide_w); +} + double SequenceDiagram::selectTest(const QPointF &pos, bool, QVariant *) const { double key_pos = qRound(key_axis_->pixelToCoord(pos.y())); diff --git a/ui/qt/sequence_diagram.h b/ui/qt/sequence_diagram.h index aa9a377a4a..2bab3a08f3 100644 --- a/ui/qt/sequence_diagram.h +++ b/ui/qt/sequence_diagram.h @@ -53,6 +53,8 @@ public: // non-property methods: struct _seq_analysis_item *itemForPosY(int ypos); + bool inComment(QPoint pos) const; + QString elidedComment(const QString &text) const; // reimplemented virtual methods: virtual void clearData() { data_->clear(); } diff --git a/ui/qt/sequence_dialog.cpp b/ui/qt/sequence_dialog.cpp index 2f5b5ede51..5ee771cad2 100644 --- a/ui/qt/sequence_dialog.cpp +++ b/ui/qt/sequence_dialog.cpp @@ -225,6 +225,23 @@ void SequenceDialog::updateWidgets() WiresharkDialog::updateWidgets(); } +bool SequenceDialog::event(QEvent *event) +{ + if (event->type() == QEvent::ToolTip) { + QHelpEvent *helpEvent = static_cast(event); + seq_analysis_item_t *sai = seq_diagram_->itemForPosY(helpEvent->pos().y()); + if (sai && seq_diagram_->inComment(helpEvent->pos()) && (sai->comment != seq_diagram_->elidedComment(sai->comment))) { + QToolTip::showText(helpEvent->globalPos(), sai->comment); + } else { + QToolTip::hideText(); + event->ignore(); + } + + return true; + } + return QWidget::event(event); +} + void SequenceDialog::showEvent(QShowEvent *) { QTimer::singleShot(0, this, SLOT(fillDiagram())); diff --git a/ui/qt/sequence_dialog.h b/ui/qt/sequence_dialog.h index 8c321907b7..725f5bcd11 100644 --- a/ui/qt/sequence_dialog.h +++ b/ui/qt/sequence_dialog.h @@ -54,6 +54,7 @@ public: void enableVoIPFeatures(); protected: + bool event(QEvent *event); void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); void keyPressEvent(QKeyEvent *event);