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.)
This commit is contained in:
John Thacker 2024-02-24 13:34:41 -05:00 committed by AndersBroman
parent 4fcb4b5364
commit b517471bc4
4 changed files with 36 additions and 3 deletions

View File

@ -149,8 +149,6 @@ void SequenceDiagram::setData(_seq_analysis_info *sainfo)
double cur_key = 0.0;
QVector<double> key_ticks, val_ticks;
QVector<QString> 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()));

View File

@ -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(); }

View File

@ -225,6 +225,23 @@ void SequenceDialog::updateWidgets()
WiresharkDialog::updateWidgets();
}
bool SequenceDialog::event(QEvent *event)
{
if (event->type() == QEvent::ToolTip) {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(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()));

View File

@ -54,6 +54,7 @@ public:
void enableVoIPFeatures();
protected:
bool event(QEvent *event);
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
void keyPressEvent(QKeyEvent *event);