forked from osmocom/wireshark
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 422c0f45d4
)
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
This commit is contained in:
parent
231f55b6f6
commit
4221021ab6
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue