aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2023-02-09 20:47:44 -0500
committerJohn Thacker <johnthacker@gmail.com>2023-02-10 01:56:20 +0000
commit4221021ab681a981bbd839fd699caff24d3f656b (patch)
treed019183abcd5d4a10fa2bbb462573a67a1c6042c /ui
parent231f55b6f67958dfd6ff011978bbf5915cb42c9e (diff)
Qt: Fix click to packet on OverlayScrollBar
Fix the calculation of the ratio for converting a packet number to the scrollbar value by accounting for the length of the slider. maximum() does not correpond to the last packet; it corresponds to the first packet shown when the scrollbar is at maximum. The last packet is maximum() + pageStep(). (See https://doc.qt.io/qt-6/qscrollbar.html#details) The quarter of a page padding should be subtracted, not added, from the calculated position. (Fix up 422c0f45d497872a963363132ec92d400a79538f) This correctly makes clicking on the a line in the minimap scroll the packet list so that the corresponding packet is 25% of the way down the visible window. (Excepting the cases of packets at the very beginning or end of the entire packet list.) Fix #13989
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/widgets/overlay_scroll_bar.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/ui/qt/widgets/overlay_scroll_bar.cpp b/ui/qt/widgets/overlay_scroll_bar.cpp
index c3262c6220..8a734c6892 100644
--- a/ui/qt/widgets/overlay_scroll_bar.cpp
+++ b/ui/qt/widgets/overlay_scroll_bar.cpp
@@ -241,9 +241,14 @@ void OverlayScrollBar::mouseReleaseEvent(QMouseEvent *event)
if (pm_r.contains(event->pos()) && geometry().height() > 0 && packet_count_ > 0 && pageStep() > 0) {
double map_ratio = double(end_pos_ - start_pos_) / geometry().height();
int clicked_packet = (event->pos().y() * map_ratio) + start_pos_;
- double packet_to_sb_value = double(maximum() - minimum()) / packet_count_;
+ /* The first packet is at minimum(). The last packet is at
+ * maximum() + pageStep(). (maximum() corresponds to the first
+ * packet shown when the scrollbar at at the maximum position.)
+ * https://doc.qt.io/qt-6/qscrollbar.html#details
+ */
+ double packet_to_sb_value = double(maximum() + pageStep() - minimum()) / packet_count_;
int top_pad = pageStep() / 4; // Land near, but not at, the top.
- setValue((clicked_packet * packet_to_sb_value) + top_pad);
+ setValue((clicked_packet * packet_to_sb_value) - top_pad);
}
}