From 1514fe06cd53c5facab83ebd5f275167651e40c2 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 22 Jul 2015 10:28:04 -0700 Subject: Show the current selection in the overlay scrollbar. Change-Id: Ie92b7ae170938eac71ede751d9067e1d47293092 Reviewed-on: https://code.wireshark.org/review/9750 Reviewed-by: Gerald Combs --- ui/qt/overlay_scroll_bar.cpp | 32 +++++++++++++++----------------- ui/qt/overlay_scroll_bar.h | 15 +++++++++++++-- ui/qt/packet_list.cpp | 14 +++++++++++++- 3 files changed, 41 insertions(+), 20 deletions(-) (limited to 'ui') diff --git a/ui/qt/overlay_scroll_bar.cpp b/ui/qt/overlay_scroll_bar.cpp index 6990bd57cb..5ea99e882c 100644 --- a/ui/qt/overlay_scroll_bar.cpp +++ b/ui/qt/overlay_scroll_bar.cpp @@ -32,7 +32,8 @@ OverlayScrollBar::OverlayScrollBar(Qt::Orientation orientation, QWidget *parent) : QScrollBar(orientation, parent = 0), near_overlay_(QImage()), - far_overlay_(QImage()) + far_overlay_(QImage()), + selected_pos_(-1) {} QSize OverlayScrollBar::sizeHint() const @@ -40,9 +41,10 @@ QSize OverlayScrollBar::sizeHint() const return QSize(QScrollBar::sizeHint().width() + (far_overlay_.width() * 2), QScrollBar::sizeHint().height()); } -void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image) +void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int selected_pos) { near_overlay_ = overlay_image; + selected_pos_ = selected_pos; update(); } @@ -89,6 +91,17 @@ void OverlayScrollBar::paintEvent(QPaintEvent *event) far_dest.moveLeft(gr_size.width() - fo_width); go_painter.drawImage(far_dest, far_overlay_.mirrored(true, false)); } + + // Selected packet indicator + if (selected_pos_ >= 0 && selected_pos_ < near_overlay_.height()) { + int no_pos = near_dest.height() * selected_pos_ / near_overlay_.height(); + go_painter.save(); + go_painter.setBrush(palette().highlight().color()); + go_painter.drawRect(0, no_pos, near_dest.width(), devicePixelRatio()); + go_painter.restore(); + } + + // Outline QRect near_outline(near_dest); near_outline.adjust(0, 0, -1, -1); go_painter.save(); @@ -98,21 +111,6 @@ void OverlayScrollBar::paintEvent(QPaintEvent *event) go_painter.drawRect(near_outline); go_painter.restore(); -#if 0 - // Fade in from the left and right. - go_painter.save(); - go_painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - QLinearGradient fade(0, 0, groove_overlay.width(), 0); - fade.setColorAt(0, Qt::transparent); - fade.setColorAt(0.2, Qt::white); - fade.setColorAt(0.8, Qt::white); - fade.setColorAt(1, Qt::transparent); - - go_painter.setBrush(fade); - go_painter.drawRect(groove_overlay.rect()); - go_painter.restore(); -#endif - // Punch a hole for the slider. QStyleOptionSlider opt; initStyleOption(&opt); diff --git a/ui/qt/overlay_scroll_bar.h b/ui/qt/overlay_scroll_bar.h index 76e7612292..d1e37d408c 100644 --- a/ui/qt/overlay_scroll_bar.h +++ b/ui/qt/overlay_scroll_bar.h @@ -33,8 +33,18 @@ public: virtual QSize sizeHint() const; - // Images are assumed to be 1 pixel wide and grooveRect.height() high. - void setNearOverlayImage(QImage &overlay_image); + /** Set the "near" overlay image. + * @param overlay_image An image containing a 1:1 mapping of nearby + * packet colors to raster lines. + * @param selected_pos The position of the selected packet within the + * image. -1 means no packet is selected. + */ + void setNearOverlayImage(QImage &overlay_image, int selected_pos = -1); + + /** Set the "far" overlay image. + * @param overlay_image An image showing the position of marked, ignored, + * and reference time packets over the entire packet list. + */ void setFarOverlayImage(QImage &overlay_image); QRect grooveRect(); @@ -44,6 +54,7 @@ protected: private: QImage near_overlay_; QImage far_overlay_; + int selected_pos_; }; #endif // __OVERLAY_SCROLL_BAR_H__ diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 8f91bcd561..0348d08faf 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -1312,6 +1312,7 @@ void PacketList::drawNearOverlay() #endif int o_height = overlay_sb_->height() * dp_ratio * height_multiplier_; int o_rows = qMin(packet_list_model_->rowCount(), o_height); + int selected_pos = -1; if (recent.packet_list_colorize && o_rows > 0) { QImage overlay(1, o_height, QImage::Format_ARGB32_Premultiplied); @@ -1363,7 +1364,18 @@ void PacketList::drawNearOverlay() cur_line = next_line; } - overlay_sb_->setNearOverlayImage(overlay); + if (selectionModel()->hasSelection()) { + int sel_row = selectionModel()->currentIndex().row(); + if (sel_row < start) { + selected_pos = 0; + } else if (sel_row >= end) { + selected_pos = overlay.height() - 1; + } else { + selected_pos = sel_row * overlay.height() / packet_list_model_->rowCount(); + } + } + + overlay_sb_->setNearOverlayImage(overlay, selected_pos); } else { QImage overlay; overlay_sb_->setNearOverlayImage(overlay); -- cgit v1.2.3