aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/overlay_scroll_bar.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-06-11 15:53:51 -0700
committerGerald Combs <gerald@wireshark.org>2015-07-16 22:57:31 +0000
commit255d53dfc11fa49eadd30fefe3ed5950b03e6659 (patch)
tree1404c49ffb41d4f1245889f24e0e260e4cc011fd /ui/qt/overlay_scroll_bar.cpp
parent3e059c9d1fedf9c890f910fa88cc2ef99fb1e470 (diff)
Draw packet colors in the packet list scrollbar.
Inspired by (but not as fancy as) Packet Fence, an enhancement written for Ethereal a loooong time ago by Martin Visser: https://www.wireshark.org/lists/ethereal-dev/200011/msg00122.html Several text editors call this a "minimap". Color each scrollbar raster line to match the color of up to 7 packets. Note in the comments why this number was chosen. If we have any flagged frames (marked, ignored, time ref) indicate them on either side of the scrolbar. Handle HiDPI (retina) displays. This means that your window size depends on the height of your scrollbar *and* your monitor resolution. Qt's idea of the slider rect doesn't match up with the slider on OS X. This might be local to my build -- I can replicate it Qt Creator. Change-Id: Ia089d2d766ce37bab11e22d1a5721b4908935304 Reviewed-on: https://code.wireshark.org/review/8982 Reviewed-by: Gerald Combs <gerald@wireshark.org> Tested-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/overlay_scroll_bar.cpp')
-rw-r--r--ui/qt/overlay_scroll_bar.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/ui/qt/overlay_scroll_bar.cpp b/ui/qt/overlay_scroll_bar.cpp
new file mode 100644
index 0000000000..6990bd57cb
--- /dev/null
+++ b/ui/qt/overlay_scroll_bar.cpp
@@ -0,0 +1,158 @@
+/* overlay_scroll_bar.cpp
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "overlay_scroll_bar.h"
+
+#include <QPainter>
+#include <QResizeEvent>
+#include <QStyle>
+#include <QStyleOptionSlider>
+
+// To do:
+// - The slider hole doesn't match up with the slider on OS X + Qt 5.3.2.
+
+OverlayScrollBar::OverlayScrollBar(Qt::Orientation orientation, QWidget *parent) :
+ QScrollBar(orientation, parent = 0),
+ near_overlay_(QImage()),
+ far_overlay_(QImage())
+{}
+
+QSize OverlayScrollBar::sizeHint() const
+{
+ return QSize(QScrollBar::sizeHint().width() + (far_overlay_.width() * 2), QScrollBar::sizeHint().height());
+}
+
+void OverlayScrollBar::setNearOverlayImage(QImage &overlay_image)
+{
+ near_overlay_ = overlay_image;
+ update();
+}
+
+void OverlayScrollBar::setFarOverlayImage(QImage &overlay_image)
+{
+ int old_width = far_overlay_.width();
+ far_overlay_ = overlay_image;
+ if (old_width != far_overlay_.width()) {
+ updateGeometry();
+ }
+ update();
+}
+
+QRect OverlayScrollBar::grooveRect()
+{
+ QStyleOptionSlider opt;
+ initStyleOption(&opt);
+
+ return style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarGroove, this);
+}
+
+void OverlayScrollBar::paintEvent(QPaintEvent *event)
+{
+ QScrollBar::paintEvent(event);
+ if (!near_overlay_.isNull()) {
+ QRect groove_rect = grooveRect();
+ QSize gr_size = groove_rect.size();
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+ gr_size *= devicePixelRatio();
+#endif
+ QImage groove_overlay(gr_size, QImage::Format_ARGB32_Premultiplied);
+ groove_overlay.fill(Qt::transparent);
+
+ // Draw the image supplied by the packet list and apply a mask.
+ QPainter go_painter(&groove_overlay);
+ go_painter.setPen(Qt::NoPen);
+
+ int fo_width = far_overlay_.width();
+ QRect near_dest(fo_width, 0, gr_size.width() - (fo_width * 2), gr_size.height());
+ go_painter.drawImage(near_dest, near_overlay_.scaled(near_dest.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ if (fo_width > 0) {
+ QRect far_dest(0, 0, fo_width, gr_size.height());
+ go_painter.drawImage(far_dest, far_overlay_);
+ far_dest.moveLeft(gr_size.width() - fo_width);
+ go_painter.drawImage(far_dest, far_overlay_.mirrored(true, false));
+ }
+ QRect near_outline(near_dest);
+ near_outline.adjust(0, 0, -1, -1);
+ go_painter.save();
+ QColor no_fg(palette().text().color());
+ no_fg.setAlphaF(0.25);
+ go_painter.setPen(no_fg);
+ 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);
+
+ QRect slider_rect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSlider, this);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+ slider_rect.setHeight(slider_rect.height() * devicePixelRatio());
+ slider_rect.setWidth(slider_rect.width() * devicePixelRatio());
+ slider_rect.moveTop((slider_rect.top() - groove_rect.top()) * devicePixelRatio());
+#else
+ slider_rect.moveTop(slider_rect.top() - groove_rect.top());
+#endif
+ slider_rect.adjust(fo_width + 1, 1, -1 - fo_width, -1);
+
+ go_painter.save();
+ go_painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ QColor slider_hole(Qt::white);
+ slider_hole.setAlphaF(0.1);
+ go_painter.setBrush(slider_hole);
+ go_painter.drawRect(slider_rect);
+ go_painter.restore();
+
+ // Draw over the groove.
+ QPainter painter(this);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+ groove_overlay.setDevicePixelRatio(devicePixelRatio());
+#endif
+ painter.drawImage(groove_rect.topLeft(), groove_overlay);
+ }
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */