From 33151dc92837c704b02a0c1f6c623bf1d0387e1b Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Tue, 8 Mar 2022 11:27:09 +0100 Subject: [PATCH] Qt: Fix overlay scrollbar indicator The indicator for selected packets is not reflecting the relative size of that packet inside the map --- ui/qt/packet_list.cpp | 2 +- ui/qt/widgets/overlay_scroll_bar.cpp | 16 ++++++---------- ui/qt/widgets/overlay_scroll_bar.h | 5 +++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 9c3e4579b0..45157e7b9e 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -2059,7 +2059,7 @@ void PacketList::drawNearOverlay() } } - overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, positions); + overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, positions, (o_height / o_rows)); } else { QImage overlay; overlay_sb_->setNearOverlayImage(overlay); diff --git a/ui/qt/widgets/overlay_scroll_bar.cpp b/ui/qt/widgets/overlay_scroll_bar.cpp index 67ea10a1f9..a421853f0e 100644 --- a/ui/qt/widgets/overlay_scroll_bar.cpp +++ b/ui/qt/widgets/overlay_scroll_bar.cpp @@ -99,7 +99,7 @@ int OverlayScrollBar::sliderPosition() return child_sb_.sliderPosition(); } -void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int packet_count, int start_pos, int end_pos, QList positions) +void OverlayScrollBar::setNearOverlayImage(QImage& overlay_image, int packet_count, int start_pos, int end_pos, QList positions, int rowHeight) { int old_width = packet_map_img_.width(); packet_map_img_ = overlay_image; @@ -107,6 +107,7 @@ void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int packet_cou start_pos_ = start_pos; end_pos_ = end_pos; positions_ = positions; + row_height_ = rowHeight > devicePixelRatio() ? rowHeight : devicePixelRatio(); if (old_width != packet_map_img_.width()) { qreal dp_ratio = devicePixelRatio(); @@ -173,17 +174,12 @@ void OverlayScrollBar::paintEvent(QPaintEvent *event) { foreach (int selected_pos_, positions_) { - if (selected_pos_ >= 0 && selected_pos_ < packet_map_img_.height()) { + int pmiHeight = packet_map_img_.height(); + if (selected_pos_ >= 0 && selected_pos_ < pmiHeight) { pm_painter.save(); - int no_pos = near_dest.height() * selected_pos_ / packet_map_img_.height(); - int height = dp_ratio; - if ((selected_pos_ + 1) < packet_map_img_.height()) - { - int nx_pos = near_dest.height() * ( selected_pos_ + 1 ) / packet_map_img_.height(); - height = (nx_pos - no_pos + 1) > dp_ratio ? nx_pos - no_pos + 1 : dp_ratio; - } + int no_pos = near_dest.height() * selected_pos_ / pmiHeight; pm_painter.setBrush(palette().highlight().color()); - pm_painter.drawRect(0, no_pos, pm_size.width(), height); + pm_painter.drawRect(0, no_pos, pm_size.width(), row_height_); pm_painter.restore(); } } diff --git a/ui/qt/widgets/overlay_scroll_bar.h b/ui/qt/widgets/overlay_scroll_bar.h index 3ec8a337f6..5724104b68 100644 --- a/ui/qt/widgets/overlay_scroll_bar.h +++ b/ui/qt/widgets/overlay_scroll_bar.h @@ -35,8 +35,9 @@ public: * means no packet is selected. * @param positions The positions of the selected packets within the * image. + * @param rowHeight The row height to be used for displaying the mark */ - void setNearOverlayImage(QImage &overlay_image, int packet_count = -1, int start_pos = -1, int end_pos = -1, QList positions = QList()); + void setNearOverlayImage(QImage &overlay_image, int packet_count = -1, int start_pos = -1, int end_pos = -1, QList positions = QList(), int rowHeight = 1); /** Set the "far" overlay image. * @param mp_image An image showing the position of marked, ignored, @@ -72,7 +73,7 @@ private: int start_pos_; int end_pos_; QList positions_; - + int row_height_; }; #endif // __OVERLAY_SCROLL_BAR_H__