forked from osmocom/wireshark
Qt: Display selected rows in overlay bar
Indicate all selected rows in the overlay bar for the PacketList Change-Id: Icddf8607b59bde12701a7e7983df6acbf26e0d23 Reviewed-on: https://code.wireshark.org/review/35161 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
0d534873dc
commit
f211624fa6
|
@ -1855,7 +1855,6 @@ void PacketList::drawNearOverlay()
|
|||
int o_height = overlay_sb_->height() * dp_ratio;
|
||||
int o_rows = qMin(packet_list_model_->rowCount(), o_height);
|
||||
int o_width = (wsApp->fontMetrics().height() * 2 * dp_ratio) + 2; // 2ems + 1-pixel border on either side.
|
||||
int selected_pos = -1;
|
||||
|
||||
if (recent.packet_list_colorize && o_rows > 0) {
|
||||
QImage overlay(o_width, o_height, QImage::Format_ARGB32_Premultiplied);
|
||||
|
@ -1891,18 +1890,44 @@ void PacketList::drawNearOverlay()
|
|||
|
||||
// If the selected packet is in the overlay set selected_pos
|
||||
// accordingly. Otherwise, pin it to either the top or bottom.
|
||||
QList<int> positions;
|
||||
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 - start) * o_height / o_rows;
|
||||
|
||||
QModelIndexList selRows = selectionModel()->selectedRows(0);
|
||||
int last_row = -1;
|
||||
int last_pos = -1;
|
||||
foreach (QModelIndex idx, selRows)
|
||||
{
|
||||
int selected_pos = -1;
|
||||
int sel_row = idx.row();
|
||||
if (sel_row < start) {
|
||||
selected_pos = 0;
|
||||
} else if (sel_row >= end) {
|
||||
selected_pos = overlay.height() - 1;
|
||||
} else {
|
||||
selected_pos = (sel_row - start) * o_height / o_rows;
|
||||
}
|
||||
|
||||
/* Due to the difference in the display height, we sometimes get empty positions
|
||||
* inbetween consecutive valid rows. If those are detected, they are signaled as
|
||||
* being selected as well */
|
||||
if (last_pos >= 0 && selected_pos > (last_pos + 1) && (last_row + 1) == sel_row)
|
||||
{
|
||||
for (int pos = (last_pos + 1); pos < selected_pos; pos++)
|
||||
{
|
||||
if (! positions.contains(pos))
|
||||
positions << pos;
|
||||
}
|
||||
}
|
||||
else if (selected_pos != -1 && ! positions.contains(selected_pos))
|
||||
positions << selected_pos;
|
||||
|
||||
last_row = sel_row;
|
||||
last_pos = selected_pos;
|
||||
}
|
||||
}
|
||||
|
||||
overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, selected_pos);
|
||||
overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, positions);
|
||||
} else {
|
||||
QImage overlay;
|
||||
overlay_sb_->setNearOverlayImage(overlay);
|
||||
|
|
|
@ -66,7 +66,7 @@ OverlayScrollBar::OverlayScrollBar(Qt::Orientation orientation, QWidget *parent)
|
|||
packet_count_(-1),
|
||||
start_pos_(-1),
|
||||
end_pos_(-1),
|
||||
selected_pos_(-1)
|
||||
positions_(QList<int>())
|
||||
{
|
||||
style_ = new OsbProxyStyle();
|
||||
setStyle(style_);
|
||||
|
@ -95,14 +95,14 @@ QSize OverlayScrollBar::sizeHint() const
|
|||
QScrollBar::sizeHint().height());
|
||||
}
|
||||
|
||||
void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int packet_count, int start_pos, int end_pos, int selected_pos)
|
||||
void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image, int packet_count, int start_pos, int end_pos, QList<int> positions)
|
||||
{
|
||||
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;
|
||||
positions_ = positions;
|
||||
|
||||
if (old_width != packet_map_img_.width()) {
|
||||
qreal dp_ratio = devicePixelRatio();
|
||||
|
@ -164,12 +164,24 @@ void OverlayScrollBar::paintEvent(QPaintEvent *event)
|
|||
pm_painter.drawImage(near_dest, packet_map_img_.scaled(near_dest.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
|
||||
// Selected packet indicator
|
||||
if (selected_pos_ >= 0 && selected_pos_ < packet_map_img_.height()) {
|
||||
pm_painter.save();
|
||||
int no_pos = near_dest.height() * selected_pos_ / packet_map_img_.height();
|
||||
pm_painter.setBrush(palette().highlight().color());
|
||||
pm_painter.drawRect(0, no_pos, pm_size.width(), dp_ratio);
|
||||
pm_painter.restore();
|
||||
if (positions_.count() > 0)
|
||||
{
|
||||
foreach (int selected_pos_, positions_)
|
||||
{
|
||||
if (selected_pos_ >= 0 && selected_pos_ < packet_map_img_.height()) {
|
||||
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;
|
||||
}
|
||||
pm_painter.setBrush(palette().highlight().color());
|
||||
pm_painter.drawRect(0, no_pos, pm_size.width(), height);
|
||||
pm_painter.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Borders
|
||||
|
|
|
@ -32,10 +32,10 @@ public:
|
|||
* -1 means no packet is selected.
|
||||
* @param end_pos The last packet number represented by the image. -1
|
||||
* means no packet is selected.
|
||||
* @param selected_pos The position of the selected packet within the
|
||||
* image. -1 means no packet is selected.
|
||||
* @param positions The positions of the selected packets within the
|
||||
* image.
|
||||
*/
|
||||
void setNearOverlayImage(QImage &overlay_image, int packet_count = -1, 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, QList<int> positions = QList<int>());
|
||||
|
||||
/** Set the "far" overlay image.
|
||||
* @param mp_image An image showing the position of marked, ignored,
|
||||
|
@ -70,7 +70,7 @@ private:
|
|||
int packet_count_;
|
||||
int start_pos_;
|
||||
int end_pos_;
|
||||
int selected_pos_;
|
||||
QList<int> positions_;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue