Qt: Make the packet map work with Qt 5.7.

It's not safe to assume that the overlay scroll bar range is equal(ish)
to the number of packets. Adjust our arithmetic accordingly.

Change-Id: Ic8cc8a746bdd2bdc6771794303e95a810bc3d1d2
Reviewed-on: https://code.wireshark.org/review/16186
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2016-06-27 20:13:35 -07:00 committed by Gerald Combs
parent 000ac66fce
commit 422c0f45d4
3 changed files with 12 additions and 7 deletions

View File

@ -76,6 +76,7 @@ OverlayScrollBar::OverlayScrollBar(Qt::Orientation orientation, QWidget *parent)
packet_map_img_(QImage()),
packet_map_width_(0),
marked_packet_width_(0),
packet_count_(-1),
start_pos_(-1),
end_pos_(-1),
selected_pos_(-1)
@ -99,10 +100,11 @@ QSize OverlayScrollBar::sizeHint() const
QScrollBar::sizeHint().height());
}
void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int start_pos, int end_pos, int selected_pos)
void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int packet_count, int start_pos, int end_pos, int selected_pos)
{
int old_width = packet_map_img_.width();
packet_map_img_ = overlay_image;
packet_count_ = packet_count;
start_pos_ = start_pos;
end_pos_ = end_pos;
selected_pos_ = selected_pos;
@ -242,11 +244,13 @@ void OverlayScrollBar::mouseReleaseEvent(QMouseEvent *event)
{
QRect pm_r(0, 0, packet_map_width_, height());
if (pm_r.contains(event->pos())) {
qreal map_ratio = qreal(end_pos_ - start_pos_) / geometry().height();
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_;
int top_pad = pageStep() / 4; // Land near, but not at, the top.
// Try to put the clicked packet near but not at the top.
setValue((event->pos().y() * map_ratio) + start_pos_ - (pageStep() / 4));
setValue((clicked_packet * packet_to_sb_value) + top_pad);
}
}

View File

@ -44,7 +44,7 @@ public:
* @param selected_pos The position of the selected packet within the
* image. -1 means no packet is selected.
*/
void setNearOverlayImage(QImage &overlay_image, int start_pos = -1, int end_pos = -1, int selected_pos = -1);
void setNearOverlayImage(QImage &overlay_image, int packet_count = -1, int start_pos = -1, int end_pos = -1, int selected_pos = -1);
/** Set the "far" overlay image.
* @param mp_image An image showing the position of marked, ignored,
@ -77,6 +77,7 @@ private:
QImage marked_packet_img_;
int packet_map_width_;
int marked_packet_width_;
int packet_count_;
int start_pos_;
int end_pos_;
int selected_pos_;

View File

@ -1565,7 +1565,7 @@ void PacketList::drawNearOverlay()
}
}
overlay_sb_->setNearOverlayImage(overlay, start, end, selected_pos);
overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, selected_pos);
} else {
QImage overlay;
overlay_sb_->setNearOverlayImage(overlay);