From 9b07412277b4436b30410bd07e9cb8ee0b88ddb2 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 5 May 2020 11:58:52 -0700 Subject: Qt: Add a packet diagram view. Add a new top-level view that shows each packet as a series of diagrams similar to what you'd find in a networking textook or an RFC. Add proto_item_set_bits_offset_len so that we can display some diagram fields correctly. Bugs / to do: - Make this a separate dialog instead of a main window view? - Handle bitfields / flags Change-Id: Iba4897a5bf1dcd73929dde6210d5483cf07f54df Reviewed-on: https://code.wireshark.org/review/37497 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- ui/qt/CMakeLists.txt | 2 + ui/qt/io_graph_dialog.cpp | 2 +- ui/qt/layout_preferences_frame.cpp | 39 ++ ui/qt/layout_preferences_frame.h | 3 + ui/qt/layout_preferences_frame.ui | 30 ++ ui/qt/main_window.cpp | 44 ++- ui/qt/main_window.h | 4 +- ui/qt/main_window.ui | 15 + ui/qt/main_window_layout.cpp | 12 +- ui/qt/main_window_slots.cpp | 6 + ui/qt/packet_diagram.cpp | 736 +++++++++++++++++++++++++++++++++++++ ui/qt/packet_diagram.h | 72 ++++ ui/qt/tcp_stream_dialog.cpp | 1 + ui/qt/utils/field_information.cpp | 19 +- ui/qt/utils/field_information.h | 1 + ui/qt/wireshark_application.cpp | 8 +- ui/qt/wireshark_application.h | 1 + ui/recent.c | 8 + ui/recent.h | 1 + 19 files changed, 972 insertions(+), 32 deletions(-) create mode 100644 ui/qt/packet_diagram.cpp create mode 100644 ui/qt/packet_diagram.h (limited to 'ui') diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 2903124d10..c7751bc87b 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -181,6 +181,7 @@ set(WIRESHARK_QT_HEADERS mtp3_summary_dialog.h multicast_statistics_dialog.h packet_comment_dialog.h + packet_diagram.h packet_dialog.h packet_format_group_box.h packet_list.h @@ -406,6 +407,7 @@ set(WIRESHARK_QT_SRC manage_interfaces_dialog.cpp module_preferences_scroll_area.cpp packet_comment_dialog.cpp + packet_diagram.cpp packet_dialog.cpp packet_format_group_box.cpp packet_list.cpp diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp index fde5f4fdc9..e5c6c73efe 100644 --- a/ui/qt/io_graph_dialog.cpp +++ b/ui/qt/io_graph_dialog.cpp @@ -1462,7 +1462,7 @@ void IOGraphDialog::on_buttonBox_helpRequested() wsApp->helpTopicAction(HELP_STATS_IO_GRAPH_DIALOG); } -// XXX - Copied from tcp_stream_dialog. This should be common code. +// XXX - We have similar code in tcp_stream_dialog and packet_diagram. Should this be a common routine? void IOGraphDialog::on_buttonBox_accepted() { QString file_name, extension; diff --git a/ui/qt/layout_preferences_frame.cpp b/ui/qt/layout_preferences_frame.cpp index bef7507062..a1bf03c5b5 100644 --- a/ui/qt/layout_preferences_frame.cpp +++ b/ui/qt/layout_preferences_frame.cpp @@ -106,6 +106,9 @@ void LayoutPreferencesFrame::updateWidgets() case layout_pane_content_pbytes: ui->pane1PacketBytesRadioButton->setChecked(true); break; + case layout_pane_content_pdiagram: + ui->pane1PacketDiagramRadioButton->setChecked(true); + break; case layout_pane_content_none: ui->pane1NoneRadioButton->setChecked(true); break; @@ -121,6 +124,9 @@ void LayoutPreferencesFrame::updateWidgets() case layout_pane_content_pbytes: ui->pane2PacketBytesRadioButton->setChecked(true); break; + case layout_pane_content_pdiagram: + ui->pane2PacketDiagramRadioButton->setChecked(true); + break; case layout_pane_content_none: ui->pane2NoneRadioButton->setChecked(true); break; @@ -136,6 +142,9 @@ void LayoutPreferencesFrame::updateWidgets() case layout_pane_content_pbytes: ui->pane3PacketBytesRadioButton->setChecked(true); break; + case layout_pane_content_pdiagram: + ui->pane3PacketDiagramRadioButton->setChecked(true); + break; case layout_pane_content_none: ui->pane3NoneRadioButton->setChecked(true); break; @@ -208,6 +217,16 @@ void LayoutPreferencesFrame::on_pane1PacketBytesRadioButton_toggled(bool checked ui->pane3NoneRadioButton->click(); } +void LayoutPreferencesFrame::on_pane1PacketDiagramRadioButton_toggled(bool checked) +{ + if (!checked) return; + prefs_set_enum_value(pref_layout_content_1_, layout_pane_content_pdiagram, pref_stashed); + if (ui->pane2PacketDiagramRadioButton->isChecked()) + ui->pane2NoneRadioButton->click(); + if (ui->pane3PacketDiagramRadioButton->isChecked()) + ui->pane3NoneRadioButton->click(); +} + void LayoutPreferencesFrame::on_pane1NoneRadioButton_toggled(bool checked) { if (!checked) return; @@ -244,6 +263,16 @@ void LayoutPreferencesFrame::on_pane2PacketBytesRadioButton_toggled(bool checked ui->pane3NoneRadioButton->click(); } +void LayoutPreferencesFrame::on_pane2PacketDiagramRadioButton_toggled(bool checked) +{ + if (!checked) return; + prefs_set_enum_value(pref_layout_content_2_, layout_pane_content_pdiagram, pref_stashed); + if (ui->pane1PacketDiagramRadioButton->isChecked()) + ui->pane1NoneRadioButton->click(); + if (ui->pane3PacketDiagramRadioButton->isChecked()) + ui->pane3NoneRadioButton->click(); +} + void LayoutPreferencesFrame::on_pane2NoneRadioButton_toggled(bool checked) { if (!checked) return; @@ -280,6 +309,16 @@ void LayoutPreferencesFrame::on_pane3PacketBytesRadioButton_toggled(bool checked ui->pane2NoneRadioButton->click(); } +void LayoutPreferencesFrame::on_pane3PacketDiagramRadioButton_toggled(bool checked) +{ + if (!checked) return; + prefs_set_enum_value(pref_layout_content_3_, layout_pane_content_pdiagram, pref_stashed); + if (ui->pane1PacketDiagramRadioButton->isChecked()) + ui->pane1NoneRadioButton->click(); + if (ui->pane2PacketDiagramRadioButton->isChecked()) + ui->pane2NoneRadioButton->click(); +} + void LayoutPreferencesFrame::on_pane3NoneRadioButton_toggled(bool checked) { if (!checked) return; diff --git a/ui/qt/layout_preferences_frame.h b/ui/qt/layout_preferences_frame.h index 246e8c6060..342f3cf5b4 100644 --- a/ui/qt/layout_preferences_frame.h +++ b/ui/qt/layout_preferences_frame.h @@ -54,14 +54,17 @@ private slots: void on_pane1PacketListRadioButton_toggled(bool checked); void on_pane1PacketDetailsRadioButton_toggled(bool checked); void on_pane1PacketBytesRadioButton_toggled(bool checked); + void on_pane1PacketDiagramRadioButton_toggled(bool checked); void on_pane1NoneRadioButton_toggled(bool checked); void on_pane2PacketListRadioButton_toggled(bool checked); void on_pane2PacketDetailsRadioButton_toggled(bool checked); void on_pane2PacketBytesRadioButton_toggled(bool checked); + void on_pane2PacketDiagramRadioButton_toggled(bool checked); void on_pane2NoneRadioButton_toggled(bool checked); void on_pane3PacketListRadioButton_toggled(bool checked); void on_pane3PacketDetailsRadioButton_toggled(bool checked); void on_pane3PacketBytesRadioButton_toggled(bool checked); + void on_pane3PacketDiagramRadioButton_toggled(bool checked); void on_pane3NoneRadioButton_toggled(bool checked); void on_restoreButtonBox_clicked(QAbstractButton *button); void on_packetListSeparatorCheckBox_toggled(bool checked); diff --git a/ui/qt/layout_preferences_frame.ui b/ui/qt/layout_preferences_frame.ui index 02d03045cb..0ce09cad74 100644 --- a/ui/qt/layout_preferences_frame.ui +++ b/ui/qt/layout_preferences_frame.ui @@ -212,6 +212,16 @@ + + + + Packet Diagram + + + pane1ButtonGroup + + + @@ -263,6 +273,16 @@ + + + + Packet Diagram + + + pane2ButtonGroup + + + @@ -314,6 +334,16 @@ + + + + Packet Diagram + + + pane3ButtonGroup + + + diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 4cb3ef5cf9..4c1a7c0243 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -57,6 +57,7 @@ DIAG_ON(frame-larger-than=) #include "funnel_statistics.h" #include "import_text_dialog.h" #include "interface_toolbar.h" +#include "packet_diagram.h" #include "packet_list.h" #include "proto_tree.h" #include "simple_dialog.h" @@ -466,20 +467,23 @@ MainWindow::MainWindow(QWidget *parent) : packet_list_->setProtoTree(proto_tree_); packet_list_->installEventFilter(this); + packet_diagram_ = new PacketDiagram(&master_split_); + welcome_page_ = main_ui_->welcomePage; - connect(proto_tree_, SIGNAL(fieldSelected(FieldInformation *)), - this, SIGNAL(fieldSelected(FieldInformation *))); - connect(packet_list_, SIGNAL(fieldSelected(FieldInformation *)), - this, SIGNAL(fieldSelected(FieldInformation *))); - connect(this, SIGNAL(fieldSelected(FieldInformation *)), - this, SLOT(setMenusForSelectedTreeRow(FieldInformation *))); - connect(this, SIGNAL(fieldSelected(FieldInformation *)), - main_ui_->statusBar, SLOT(selectedFieldChanged(FieldInformation *))); + connect(proto_tree_, &ProtoTree::fieldSelected, + this, &MainWindow::fieldSelected); + connect(packet_list_, &PacketList::fieldSelected, + this, &MainWindow::fieldSelected); + connect(this, &MainWindow::fieldSelected, + this, &MainWindow::setMenusForSelectedTreeRow); + connect(this, &MainWindow::fieldSelected, + main_ui_->statusBar, &MainStatusBar::selectedFieldChanged); - connect(this, SIGNAL(fieldHighlight(FieldInformation *)), - main_ui_->statusBar, SLOT(highlightedFieldChanged(FieldInformation *))); - connect(wsApp, SIGNAL(captureActive(int)), this, SIGNAL(captureActive(int))); + connect(this, &MainWindow::fieldHighlight, + main_ui_->statusBar, &MainStatusBar::highlightedFieldChanged); + connect(wsApp, &WiresharkApplication::captureActive, + this, &MainWindow::captureActive); byte_view_tab_ = new ByteViewTab(&master_split_); @@ -543,14 +547,14 @@ MainWindow::MainWindow(QWidget *parent) : filter_expression_toolbar_, &FilterExpressionToolBar::filterExpressionsChanged); /* Connect change of capture file */ - connect(this, SIGNAL(setCaptureFile(capture_file*)), - main_ui_->searchFrame, SLOT(setCaptureFile(capture_file*))); - connect(this, SIGNAL(setCaptureFile(capture_file*)), - main_ui_->statusBar, SLOT(setCaptureFile(capture_file*))); - connect(this, SIGNAL(setCaptureFile(capture_file*)), - packet_list_, SLOT(setCaptureFile(capture_file*))); - connect(this, SIGNAL(setCaptureFile(capture_file*)), - proto_tree_, SLOT(setCaptureFile(capture_file*))); + connect(this, &MainWindow::setCaptureFile, + main_ui_->searchFrame, &SearchFrame::setCaptureFile); + connect(this, &MainWindow::setCaptureFile, + main_ui_->statusBar, &MainStatusBar::setCaptureFile); + connect(this, &MainWindow::setCaptureFile, + packet_list_, &PacketList::setCaptureFile); + connect(this, &MainWindow::setCaptureFile, + proto_tree_, &ProtoTree::setCaptureFile); connect(wsApp, SIGNAL(zoomMonospaceFont(QFont)), packet_list_, SLOT(setMonospaceFont(QFont))); @@ -701,6 +705,7 @@ QMenu *MainWindow::createPopupMenu() menu->addAction(main_ui_->actionViewPacketList); menu->addAction(main_ui_->actionViewPacketDetails); menu->addAction(main_ui_->actionViewPacketBytes); + menu->addAction(main_ui_->actionViewPacketDiagram); return menu; } @@ -2058,6 +2063,7 @@ void MainWindow::initShowHideMainWidgets() shmw_actions[main_ui_->actionViewPacketList] = packet_list_; shmw_actions[main_ui_->actionViewPacketDetails] = proto_tree_; shmw_actions[main_ui_->actionViewPacketBytes] = byte_view_tab_; + shmw_actions[main_ui_->actionViewPacketDiagram] = packet_diagram_; foreach(QAction *shmwa, shmw_actions.keys()) { shmwa->setData(QVariant::fromValue(shmw_actions[shmwa])); diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index e1125c816b..74f4a68068 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -85,6 +85,7 @@ class FilterDialog; class FunnelStatistics; class WelcomePage; class PacketCommentDialog; +class PacketDiagram; class PacketList; class ProtoTree; #if defined(HAVE_LIBNL) && defined(HAVE_NL80211) @@ -191,7 +192,8 @@ private: // probably be full-on values instead of pointers. PacketList *packet_list_; ProtoTree *proto_tree_; - ByteViewTab * byte_view_tab_; + ByteViewTab *byte_view_tab_; + PacketDiagram *packet_diagram_; QWidget *previous_focus_; FileSetDialog *file_set_dialog_; QWidget empty_pane_; diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index 024e3eebc5..79b6ffc08c 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -362,6 +362,7 @@ + @@ -2473,6 +2474,20 @@ Show or hide the packet bytes + + + true + + + true + + + Packet &Diagram + + + Show or hide the packet diagram + + &Conversation Hash Tables diff --git a/ui/qt/main_window_layout.cpp b/ui/qt/main_window_layout.cpp index 741a563301..f201784f37 100644 --- a/ui/qt/main_window_layout.cpp +++ b/ui/qt/main_window_layout.cpp @@ -24,9 +24,10 @@ #include #include +#include #include +#include #include -#include /* * The generated Ui_MainWindow::setupUi() can grow larger than our configured limit, @@ -56,6 +57,8 @@ QWidget* MainWindow::getLayoutWidget(layout_pane_content_e type) { return proto_tree_; case layout_pane_content_pbytes: return byte_view_tab_; + case layout_pane_content_pdiagram: + return packet_diagram_; default: g_assert_not_reached(); return NULL; @@ -76,7 +79,8 @@ void MainWindow::layoutPanes() << prefs.gui_layout_content_3 << recent.packet_list_show << recent.tree_view_show - << recent.byte_view_show; + << recent.byte_view_show + << recent.packet_diagram_show; if (cur_layout_ == new_layout) return; @@ -84,10 +88,11 @@ void MainWindow::layoutPanes() // Reparent all widgets and add them back in the proper order below. // This hides each widget as well. - packet_list_->freeze(); // Clears tree and byte view tabs. + packet_list_->freeze(); // Clears tree, byte view tabs, and diagram. packet_list_->setParent(main_ui_->mainStack); proto_tree_->setParent(main_ui_->mainStack); byte_view_tab_->setParent(main_ui_->mainStack); + packet_diagram_->setParent(main_ui_->mainStack); empty_pane_.setParent(main_ui_->mainStack); extra_split_.setParent(main_ui_->mainStack); @@ -156,6 +161,7 @@ void MainWindow::layoutPanes() packet_list_->setVisible(ms_children.contains(packet_list_) && recent.packet_list_show); proto_tree_->setVisible(ms_children.contains(proto_tree_) && recent.tree_view_show); byte_view_tab_->setVisible(ms_children.contains(byte_view_tab_) && recent.byte_view_show); + packet_diagram_->setVisible(ms_children.contains(packet_diagram_) && recent.packet_diagram_show); // Show the packet list here to prevent pending resize events changing columns // when the packet list is set as current widget for the first time. diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 6ae4238e36..a0d3250cf3 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -127,6 +127,7 @@ DIAG_ON(frame-larger-than=) #include "mtp3_summary_dialog.h" #include "multicast_statistics_dialog.h" #include "packet_comment_dialog.h" +#include "packet_diagram.h" #include "packet_dialog.h" #include "packet_list.h" #include "credentials_dialog.h" @@ -360,6 +361,7 @@ void MainWindow::updatePreferenceActions() main_ui_->actionViewPacketList->setEnabled(prefs_has_layout_pane_content(layout_pane_content_plist)); main_ui_->actionViewPacketDetails->setEnabled(prefs_has_layout_pane_content(layout_pane_content_pdetails)); main_ui_->actionViewPacketBytes->setEnabled(prefs_has_layout_pane_content(layout_pane_content_pbytes)); + main_ui_->actionViewPacketDiagram->setEnabled(prefs_has_layout_pane_content(layout_pane_content_pdiagram)); main_ui_->actionViewNameResolutionPhysical->setChecked(gbl_resolv_flags.mac_name); main_ui_->actionViewNameResolutionNetwork->setChecked(gbl_resolv_flags.network_name); @@ -378,6 +380,7 @@ void MainWindow::updateRecentActions() main_ui_->actionViewPacketList->setChecked(recent.packet_list_show && prefs_has_layout_pane_content(layout_pane_content_plist)); main_ui_->actionViewPacketDetails->setChecked(recent.tree_view_show && prefs_has_layout_pane_content(layout_pane_content_pdetails)); main_ui_->actionViewPacketBytes->setChecked(recent.byte_view_show && prefs_has_layout_pane_content(layout_pane_content_pbytes)); + main_ui_->actionViewPacketDiagram->setChecked(recent.packet_diagram_show && prefs_has_layout_pane_content(layout_pane_content_pdiagram)); foreach(QAction *action, main_ui_->menuInterfaceToolbars->actions()) { if (g_list_find_custom(recent.interface_toolbars, action->text().toUtf8(), (GCompareFunc)strcmp)) { @@ -2299,6 +2302,9 @@ void MainWindow::showHideMainWidgets(QAction *action) } else if (widget == byte_view_tab_) { recent.byte_view_show = show; main_ui_->actionViewPacketBytes->setChecked(show); + } else if (widget == packet_diagram_) { + recent.packet_diagram_show = show; + main_ui_->actionViewPacketDiagram->setChecked(show); } else { foreach(QAction *action, main_ui_->menuInterfaceToolbars->actions()) { QToolBar *toolbar = action->data().value(); diff --git a/ui/qt/packet_diagram.cpp b/ui/qt/packet_diagram.cpp new file mode 100644 index 0000000000..f83f782ec1 --- /dev/null +++ b/ui/qt/packet_diagram.cpp @@ -0,0 +1,736 @@ +/* packet_diagram.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "packet_diagram.h" + +#include "math.h" + +#include "epan/epan.h" +#include "epan/epan_dissect.h" + +#include "wsutil/utf8_entities.h" + +#include "wireshark_application.h" + +#include "ui/qt/main_window.h" +#include "ui/qt/utils/proto_node.h" +#include "ui/qt/utils/variant_pointer.h" + + +#include +#include +#include + +#if defined(QT_SVG_LIB) && 0 +#include +#include +#include +#endif + +#include + +// "rems" are root em widths, aka the regular font height, similar to rems in CSS. +class DiagramLayout { +public: + DiagramLayout() : + bits_per_row_(32), + small_font_rems_(0.75), + bit_width_rems_(1.0), + padding_rems_(0.5), + span_mark_offset_rems_(0.2), + show_fields_(false) + { + setFont(wsApp->font()); + } + + void setFont(QFont font) { + regular_font_ = font; + small_font_ = font; + small_font_.setPointSize(regular_font_.pointSize() * small_font_rems_); + + QFontMetrics fm(regular_font_); + root_em_ = fm.height(); + } + void setShowFields(bool show_fields = false) { show_fields_ = show_fields; } + + int bitsPerRow() const { return bits_per_row_; } + const QFont regularFont() const { return regular_font_; } + const QFont smallFont() const { return small_font_; } + int bitWidth() const { return root_em_ * bit_width_rems_; } + int lineHeight() const { return root_em_; } + int hPadding() const { return root_em_ * padding_rems_; } + int vPadding() const { return root_em_ * padding_rems_; } + int spanMarkOffset() const { return root_em_ * span_mark_offset_rems_; } + int rowHeight() const { + int rows = show_fields_ ? 2 : 1; + return ((lineHeight() * rows) + (vPadding() * 2)); + } + bool showFields() const { return show_fields_; } +private: + int bits_per_row_; + double small_font_rems_; + double bit_width_rems_; + double padding_rems_; + double span_mark_offset_rems_; // XXX Make this padding_rems_ / 2 instead? + bool show_fields_; + QFont regular_font_; + QFont small_font_; + int root_em_; +}; + +class FieldInformationGraphicsItem : public QGraphicsPolygonItem +{ +public: + FieldInformationGraphicsItem(field_info *fi, int start_bit, int fi_length, const DiagramLayout *layout, QGraphicsItem *parent = nullptr) : + QGraphicsPolygonItem(QPolygonF(), parent), + finfo_(new FieldInformation(fi)), + start_bit_(start_bit), + layout_(layout), + collapsed_len_(fi_length), + collapsed_row_(-1) + { + Q_ASSERT(layout_); + + for (int idx = 0; idx < NumSpanMarks; idx++) { + span_marks_[idx] = new QGraphicsLineItem(this); + span_marks_[idx]->hide(); + } + + int bits_per_row = layout_->bitsPerRow(); + int row1_start = start_bit_ % bits_per_row; + int bits_remain = fi_length; + + int row1_bits = bits_remain; + if (bits_remain + row1_start > bits_per_row) { + row1_bits = bits_per_row - row1_start; + bits_remain -= row1_bits; + if (row1_start == 0 && bits_remain > bits_per_row) { + // Collapse first row + bits_remain %= bits_per_row; + collapsed_row_ = 0; + } + } else { + bits_remain = 0; + } + + int row2_bits = bits_remain; + if (bits_remain > bits_per_row) { + row2_bits = bits_per_row; + bits_remain -= bits_per_row; + if (bits_remain > bits_per_row) { + // Collapse second row + bits_remain %= bits_per_row; + collapsed_row_ = 1; + } + } else { + bits_remain = 0; + } + int row3_bits = bits_remain; + + collapsed_len_ = row1_bits + row2_bits + row3_bits; + + QRectF rr1, rr2, rr3; + QRectF row_rect = QRectF(row1_start, 0, row1_bits, 1); + unit_shape_ = QPolygonF(row_rect); + rr1 = row_rect; + unit_tr_ = row_rect; + + if (row2_bits > 0) { + row_rect = QRectF(0, 1, row2_bits, 1); + unit_shape_ = unit_shape_.united(QPolygonF(row_rect)); + rr2 = row_rect; + if (row2_bits > row1_bits) { + unit_tr_ = row_rect; + } + + if (row3_bits > 0) { + row_rect = QRectF(0, 2, row3_bits, 1); + unit_shape_ = unit_shape_.united(QPolygonF(row_rect)); + rr3 = row_rect; + } + QPainterPath pp; + pp.addPolygon(unit_shape_); + unit_shape_ = pp.simplified().toFillPolygon(); + } + + updateLayout(); + + if (finfo_->isValid()) { + setToolTip(QString("%1 (%2) = %3") + .arg(finfo_->headerInfo().name) + .arg(finfo_->headerInfo().abbreviation) + .arg(finfo_->toString())); + setData(Qt::UserRole, VariantPointer::asQVariant(finfo_->fieldInfo())); + } else { + setToolTip(QObject::tr("Gap in dissection")); + } + } + + int collapsedLength() { return collapsed_len_; } + + void setPos(qreal x, qreal y) { + QGraphicsPolygonItem::setPos(x, y); + updateLayout(); + } + + int maxLeftY() { + qreal rel_len = (start_bit_ % layout_->bitsPerRow()) + collapsed_len_; + QPointF pt = mapToParent(QPointF(0, ceil(rel_len / layout_->bitsPerRow()) * layout_->rowHeight())); + return pt.y(); + } + + int maxRightY() { + qreal rel_len = (start_bit_ % layout_->bitsPerRow()) + collapsed_len_; + QPointF pt = mapToParent(QPointF(0, floor(rel_len / layout_->bitsPerRow()) * layout_->rowHeight())); + return pt.y(); + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { + + painter->setPen(Qt::NoPen); + painter->save(); + if (!finfo_->isValid()) { + QBrush brush = QBrush(option->palette.text().color(), Qt::BDiagPattern); + painter->setBrush(brush); + } else if (isSelected()) { + painter->setBrush(option->palette.highlight().color()); + } + painter->drawPolygon(polygon()); + painter->restore(); + + // Lower and inner right borders + painter->setPen(option->palette.text().color()); + QPolygonF shape = polygon(); + for (int idx = 1; idx < unit_shape_.size(); idx++) { + QPointF u_start = unit_shape_[idx - 1]; + QPointF u_end = unit_shape_[idx]; + QPointF start, end; + bool draw_line = false; + + if (u_start.y() > 0 && u_start.y() == u_end.y()) { + draw_line = true; + } else if (u_start.x() > 0 && u_start.x() < layout_->bitsPerRow() && u_start.x() == u_end.x()) { + draw_line = true; + } + if (draw_line) { + start = shape[idx - 1]; + end = shape[idx]; + painter->drawLine(start, end); + } + } + + if (!finfo_->isValid()) { + return; + } + + // Field label(s) + QString label = finfo_->headerInfo().name; + paintLabel(painter, label, scaled_tr_); + + if (layout_->showFields()) { + label = finfo_->toString(); + paintLabel(painter, label, scaled_tr_.adjusted(0, scaled_tr_.height(), 0, scaled_tr_.height())); + } + } + +private: + enum SpanMark { + TopLeft, + BottomLeft, + TopRight, + BottomRight, + NumSpanMarks + }; + FieldInformation *finfo_; + int start_bit_; + const DiagramLayout *layout_; + int collapsed_len_; + int collapsed_row_; + QPolygonF unit_shape_; + QRectF unit_tr_; + QRectF scaled_tr_; + QGraphicsLineItem *span_marks_[NumSpanMarks]; + + void updateLayout() { + QTransform xform; + + xform.scale(layout_->bitWidth(), layout_->rowHeight()); + setPolygon(xform.map(unit_shape_)); + scaled_tr_ = xform.mapRect(unit_tr_); + scaled_tr_.adjust(layout_->hPadding(), layout_->vPadding(), -layout_->hPadding(), -layout_->vPadding()); + scaled_tr_.setHeight(layout_->lineHeight()); + + // Collapsed / span marks + for (int idx = 0; idx < NumSpanMarks; idx++) { + span_marks_[idx]->hide(); + } + if (collapsed_row_ >= 0) { + QRectF bounding_rect = polygon().boundingRect(); + qreal center_y = bounding_rect.top() + (layout_->rowHeight() * collapsed_row_) + (layout_->rowHeight() / 2); + qreal mark_w = layout_->bitWidth() / 3; // Each mark side to center + QLineF span_l = QLineF(-mark_w, mark_w / 2, mark_w, -mark_w / 2); + for (int idx = 0; idx < NumSpanMarks; idx++) { + QPointF center; + switch (idx) { + case TopLeft: + center = QPointF(bounding_rect.left(), center_y - layout_->spanMarkOffset()); + break; + case BottomLeft: + center = QPointF(bounding_rect.left(), center_y + layout_->spanMarkOffset()); + break; + case TopRight: + center = QPointF(bounding_rect.right(), center_y - layout_->spanMarkOffset()); + break; + case BottomRight: + center = QPointF(bounding_rect.right(), center_y + layout_->spanMarkOffset()); + break; + } + + span_marks_[idx]->setLine(span_l.translated(center)); + span_marks_[idx]->setZValue(zValue() - 0.1); + span_marks_[idx]->show(); + } + } + } + + void paintLabel(QPainter *painter, QString label, QRectF label_rect) { + QFontMetrics fm = QFontMetrics(layout_->regularFont()); + + painter->setFont(layout_->regularFont()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + int label_w = fm.horizontalAdvance(label); +#else + int label_w = fm.width(label); +#endif + if (label_w > label_rect.width()) { + painter->setFont(layout_->smallFont()); + fm = QFontMetrics(layout_->smallFont()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + label_w = fm.horizontalAdvance(label); +#else + label_w = fm.width(label); +#endif + if (label_w > label_rect.width()) { + // XXX Use parent+ItemClipsChildrenToShape or setScale instead? + label = fm.elidedText(label, Qt::ElideRight, label_rect.width()); + } + } + painter->drawText(label_rect, Qt::AlignCenter, label); + } +}; + +PacketDiagram::PacketDiagram(QWidget *parent) : + QGraphicsView(new QGraphicsScene(), parent), + layout_(new DiagramLayout), + cap_file_(nullptr), + root_node_(nullptr), + selected_field_(nullptr), + y_pos_(0) +{ + setAccessibleName(tr("Packet diagram")); + + setRenderHint(QPainter::Antialiasing); + + // XXX Move to setMonospaceFont similar to ProtoTree + layout_->setFont(font()); + + connect(wsApp, &WiresharkApplication::appInitialized, this, &PacketDiagram::connectToMainWindow); + QGraphicsScene *this_scene = scene(); + connect(this_scene, &QGraphicsScene::selectionChanged, this, &PacketDiagram::sceneSelectionChanged); + + connect(wsApp, &WiresharkApplication::zoomRegularFont, this, &PacketDiagram::setFont); +} + +PacketDiagram::~PacketDiagram() +{ + delete layout_; +} + +void PacketDiagram::setRootNode(proto_node *root_node) +{ + scene()->clear(); + root_node_ = root_node; + selected_field_ = nullptr; + y_pos_ = 0; + + ProtoNode parent_node(root_node_); + if (!parent_node.isValid()) { + return; + } + + ProtoNode::ChildIterator kids = parent_node.children(); + while (kids.element().isValid()) + { + proto_node *tl_node = kids.element().protoNode(); + kids.next(); + + // Exclude all ("Frame") and nothing + if (tl_node->finfo->start == 0 && tl_node->finfo->length == (int) tvb_captured_length(cap_file_->edt->tvb)) { + continue; + } + if (tl_node->finfo->length < 1) { + continue; + } + addDiagram(tl_node); + } +} + +void PacketDiagram::clear() +{ + setRootNode(nullptr); +} + +void PacketDiagram::setCaptureFile(capture_file *cf) +{ + // For use by the main view, set the capture file which will later have a + // dissection (EDT) ready. + // The packet dialog sets a fixed EDT context and MUST NOT use this. + cap_file_ = cf; +} + +void PacketDiagram::setFont(const QFont &font) +{ + layout_->setFont(font); + setRootNode(root_node_); +} + +void PacketDiagram::selectedFieldChanged(FieldInformation *finfo) +{ + setSelectedField(finfo ? finfo->fieldInfo() : nullptr); +} + +void PacketDiagram::selectedFrameChanged(QList frames) +{ + if (frames.count() == 1 && cap_file_ && cap_file_->edt && cap_file_->edt->tree) { + setRootNode(cap_file_->edt->tree); + } else { + // Clear the proto tree contents as they have become invalid. + setRootNode(nullptr); + } +} + +void PacketDiagram::contextMenuEvent(QContextMenuEvent *event) +{ + if (!event) { + return; + } + + QAction *action; + QMenu ctx_menu(this); + + action = ctx_menu.addAction(tr("Show Field Values")); + action->setCheckable(true); + action->setChecked(layout_->showFields()); + connect(action, &QAction::toggled, this, &PacketDiagram::showFieldsToggled); + + ctx_menu.addSeparator(); + + action = ctx_menu.addAction(tr("Save Diagram As" UTF8_HORIZONTAL_ELLIPSIS)); + connect(action, &QAction::triggered, this, &PacketDiagram::saveAsTriggered); + + action = ctx_menu.addAction(tr("Copy as Raster Image")); + connect(action, &QAction::triggered, this, &PacketDiagram::copyAsRasterTriggered); + +#if defined(QT_SVG_LIB) && !defined(Q_OS_MAC) + action = ctx_menu.addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as SVG")); + connect(action, &QAction::triggered, this, &PacketDiagram::copyAsSvgTriggered); +#endif + + ctx_menu.exec(event->globalPos()); +} + +void PacketDiagram::connectToMainWindow() +{ + MainWindow *main_window = qobject_cast(wsApp->mainWindow()); + if (!main_window) { + return; + } + connect(main_window, &MainWindow::setCaptureFile, this, &PacketDiagram::setCaptureFile); + connect(main_window, &MainWindow::fieldSelected, this, &PacketDiagram::selectedFieldChanged); + connect(main_window, &MainWindow::framesSelected, this, &PacketDiagram::selectedFrameChanged); + + connect(this, &PacketDiagram::fieldSelected, main_window, &MainWindow::fieldSelected); +} + +void PacketDiagram::sceneSelectionChanged() +{ + field_info *sel_fi = nullptr; + if (! scene()->selectedItems().isEmpty()) { + sel_fi = VariantPointer::asPtr(scene()->selectedItems().first()->data(Qt::UserRole)); + } + + if (sel_fi) { + FieldInformation finfo(sel_fi, this); + emit fieldSelected(&finfo); + } else { + emit fieldSelected(nullptr); + } +} + +struct WireItem { + proto_item *item; + int start_bit; + int length; +}; + +void PacketDiagram::addDiagram(proto_node *tl_node) +{ + QGraphicsItem *item; + QGraphicsSimpleTextItem *t_item; + int bits_per_row = layout_->bitsPerRow(); + int bit_width = layout_->bitWidth(); + int diag_w = bit_width * layout_->bitsPerRow(); + qreal x = layout_->hPadding(); + + // Title + t_item = scene()->addSimpleText(tl_node->finfo->hfinfo->name); + t_item->setFont(layout_->regularFont()); + t_item->setPos(0, y_pos_); + y_pos_ += layout_->lineHeight() + (bit_width / 4); + + int border_top = y_pos_; + + // Bit scale + tick marks + QList tick_nums; + for (int tn = 0 ; tn < layout_->bitsPerRow(); tn += 16) { + tick_nums << tn << tn + 15; + } + qreal y_bottom = y_pos_ + bit_width; + QGraphicsItem *tl_item = scene()->addLine(x, y_bottom, x + diag_w, y_bottom); + for (int tick_n = 0; tick_n < bits_per_row; tick_n++) { + x = layout_->hPadding() + (tick_n * bit_width); + qreal y_top = y_pos_ + (tick_n % 8 == 0 ? 0 : bit_width / 2); + if (tick_n > 0) { + scene()->addLine(x, y_top, x, y_bottom); + } + + if (tick_nums.contains(tick_n)) { + t_item = scene()->addSimpleText(QString::number(tick_n)); + t_item->setFont(layout_->smallFont()); + t_item->setPos(x + ((bit_width - t_item->boundingRect().width()) / 2.0) + 2, y_pos_); + } + } + y_pos_ = y_bottom; + x = layout_->hPadding(); + + // Top-level fields + int last_start_bit = -1; + int max_l_y = y_bottom; + QListwire_items; + for (proto_item *cur_item = tl_node->first_child; cur_item; cur_item = cur_item->next) { + if (proto_item_is_generated(cur_item) || proto_item_is_hidden(cur_item)) { + continue; + } + + field_info *fi = cur_item->finfo; + int start_bit = ((fi->start - tl_node->finfo->start) * 8) + FI_GET_BITS_OFFSET(fi); + int length = FI_GET_BITS_SIZE(fi) ? FI_GET_BITS_SIZE(fi) : fi->length * 8; + + if (start_bit <= last_start_bit || length <= 0) { + qDebug() << "Skipping pass 1" << fi->hfinfo->abbrev << start_bit << last_start_bit << length; + continue; + } + last_start_bit = start_bit; + + WireItem wire_item = { cur_item, start_bit, length }; + wire_items << wire_item; + } + qreal z_value = tl_item->zValue(); + for (int idx = 0; idx < wire_items.size(); idx++) { + WireItem *wire_item = &wire_items[idx]; + field_info *fi = wire_item->item->finfo; + + if (idx < wire_items.size() - 1) { + WireItem *next_item = &wire_items[idx + 1]; + if (wire_item->start_bit + wire_item->length > next_item->start_bit) { + wire_item->length = next_item->start_bit - wire_item->start_bit; + qDebug() << "Resized pass 2" << fi->hfinfo->abbrev << wire_item->start_bit << wire_item->length << next_item->start_bit; + if (wire_item->length <= 0) { + qDebug() << "Skipping pass 2" << fi->hfinfo->abbrev << wire_item->start_bit << wire_item->length; + continue; + } + } + + if (next_item->start_bit > wire_item->start_bit + wire_item->length) { + int gap_start_bit = wire_item->start_bit + wire_item->length; + int gap_len = next_item->start_bit - gap_start_bit; + int y_off = (gap_start_bit / bits_per_row) * layout_->rowHeight(); + // Stack each item behind the previous one. + z_value -= .01; + FieldInformationGraphicsItem *gap_item = new FieldInformationGraphicsItem(nullptr, gap_start_bit, gap_len, layout_); + gap_item->setPos(x, y_bottom + y_off); + gap_item->setZValue(z_value); + scene()->addItem(gap_item); + } + } + + int y_off = (wire_item->start_bit / bits_per_row) * layout_->rowHeight(); + // Stack each item behind the previous one. + z_value -= .01; + FieldInformationGraphicsItem *fi_item = new FieldInformationGraphicsItem(fi, wire_item->start_bit, wire_item->length, layout_); + fi_item->setPos(x, y_bottom + y_off); + fi_item->setFlag(QGraphicsItem::ItemIsSelectable); + fi_item->setAcceptedMouseButtons(Qt::LeftButton); + fi_item->setZValue(z_value); + scene()->addItem(fi_item); + + y_pos_ = fi_item->maxRightY(); + max_l_y = fi_item->maxLeftY(); + } + + // Left & right borders + scene()->addLine(x, border_top, x, max_l_y); + scene()->addLine(x + diag_w, border_top, x + diag_w, y_pos_); + + // Inter-diagram margin + y_pos_ = max_l_y + bit_width; + + // Set the proper color. Needed for dark mode on macOS + Qt 5.15.0 at least, possibly other cases. + foreach (item, scene()->items()) { + QGraphicsSimpleTextItem *t_item = qgraphicsitem_cast(item); + if (t_item) { + t_item->setBrush(palette().text().color()); + } + QGraphicsLineItem *l_item = qgraphicsitem_cast(item); + if (l_item) { + l_item->setPen(palette().text().color()); + } + } +} + +void PacketDiagram::setSelectedField(field_info *fi) +{ + QSignalBlocker blocker(this); + FieldInformationGraphicsItem *fi_item; + + foreach (QGraphicsItem *item, scene()->items()) { + if (item->isSelected()) { + item->setSelected(false); + fi_item = qgraphicsitem_cast(item); + } + if (fi && VariantPointer::asPtr(item->data(Qt::UserRole)) == fi) { + fi_item = qgraphicsitem_cast(item); + if (fi_item) { + fi_item->setSelected(true); + } + } + } +} + +QImage PacketDiagram::exportToImage() +{ + // Create a hi-res 2x scaled image. + int scale = 2; + QRect rr = QRect(0, 0, sceneRect().size().width() * scale, sceneRect().size().height() * scale); + QImage raster_diagram = QImage(rr.size(), QImage::Format_ARGB32); + QPainter raster_painter(&raster_diagram); + + raster_painter.setRenderHint(QPainter::Antialiasing); + raster_painter.fillRect(rr, palette().base().color()); + scene()->render(&raster_painter); + + raster_painter.end(); + + return raster_diagram; +} + +#if defined(QT_SVG_LIB) && 0 +QByteArray PacketDiagram::exportToSvg() +{ + QRect sr = QRect(0, 0, sceneRect().size().width(), sceneRect().size().height()); + QBuffer svg_buf; + QSvgGenerator svg_diagram; + svg_diagram.setSize(sr.size()); + svg_diagram.setViewBox(sr); + svg_diagram.setOutputDevice(&svg_buf); + + QPainter svg_painter(&svg_diagram); + svg_painter.fillRect(sr, palette().base().color()); + scene()->render(&svg_painter); + + svg_painter.end(); + + return svg_buf.buffer(); +} +#endif + +void PacketDiagram::showFieldsToggled(bool checked) +{ + layout_->setShowFields(checked); + setRootNode(root_node_); +} + +// XXX - We have similar code in tcp_stream_dialog and io_graph_dialog. Should this be a common routine? +void PacketDiagram::saveAsTriggered() +{ + QString file_name, extension; + QDir path(wsApp->lastOpenDir()); + QString png_filter = tr("Portable Network Graphics (*.png)"); + QString bmp_filter = tr("Windows Bitmap (*.bmp)"); + // Gaze upon my beautiful graph with lossy artifacts! + QString jpeg_filter = tr("JPEG File Interchange Format (*.jpeg *.jpg)"); + QStringList fl = QStringList() << png_filter << bmp_filter << jpeg_filter; +#if defined(QT_SVG_LIB) && 0 + QString svg_filter = tr("Scalable Vector Graphics (*.svg)"); + fl << svg_filter; +#endif + QString filter = fl.join(";;"); + + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + path.canonicalPath(), filter, &extension); + + if (file_name.length() > 0) { + bool save_ok = false; + if (extension.compare(png_filter) == 0) { + QImage raster_diagram = exportToImage(); + save_ok = raster_diagram.save(file_name, "PNG"); + } else if (extension.compare(bmp_filter) == 0) { + QImage raster_diagram = exportToImage(); + save_ok = raster_diagram.save(file_name, "BMP"); + } else if (extension.compare(jpeg_filter) == 0) { + QImage raster_diagram = exportToImage(); + save_ok = raster_diagram.save(file_name, "JPG"); + } +#if defined(QT_SVG_LIB) && 0 + else if (extension.compare(svg_filter) == 0) { + QByteArray svg_diagram = exportToSvg(); + QFile file(file_name); + if (file.open(QIODevice::WriteOnly)) { + save_ok = file.write(svg_diagram) > 0; + file.close(); + } + } +#endif + // else error dialog? + if (save_ok) { + path = QDir(file_name); + wsApp->setLastOpenDir(path.canonicalPath().toUtf8().constData()); + } + } +} + +void PacketDiagram::copyAsRasterTriggered() +{ + QImage raster_diagram = exportToImage(); + wsApp->clipboard()->setImage(raster_diagram); +} + +#if defined(QT_SVG_LIB) && !defined(Q_OS_MAC) && 0 +void PacketDiagram::copyAsSvgTriggered() +{ + QByteArray svg_ba = exportToSvg(); + + // XXX It looks like we have to use/subclass QMacPasteboardMime in + // order for this to work on macOS. + // It might be easier to just do "Save As" instead. + QMimeData *md = new QMimeData(); + md->setData("image/svg+xml", svg_buf); + wsApp->clipboard()->setMimeData(md); +} +#endif diff --git a/ui/qt/packet_diagram.h b/ui/qt/packet_diagram.h new file mode 100644 index 0000000000..328b67111f --- /dev/null +++ b/ui/qt/packet_diagram.h @@ -0,0 +1,72 @@ +/* packet_diagram.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PACKET_DIAGRAM_H +#define PACKET_DIAGRAM_H + +#include + +#include + +#include "cfile.h" + +#include + +#include + +class DiagramLayout; + +class PacketDiagram : public QGraphicsView +{ + Q_OBJECT +public: + PacketDiagram(QWidget *parent = nullptr); + ~PacketDiagram(); + void setRootNode(proto_node *root_node); + void clear(); + +signals: + void fieldSelected(FieldInformation *); + +public slots: + void setCaptureFile(capture_file *cf); + void setFont(const QFont &font); + void selectedFieldChanged(FieldInformation *finfo); + void selectedFrameChanged(QList frames); + +protected: + virtual void contextMenuEvent(QContextMenuEvent *event) override; + +private slots: + void connectToMainWindow(); + void sceneSelectionChanged(); + +private: + void addDiagram(proto_node *tl_node); + void setSelectedField(field_info *fi); + QImage exportToImage(); +#if defined(QT_SVG_LIB) && 0 + QByteArray exportToSvg(); +#endif + + void showFieldsToggled(bool checked); + void saveAsTriggered(); + void copyAsRasterTriggered(); +#if defined(QT_SVG_LIB) && !defined(Q_OS_MAC) && 0 + void copyAsSvgTriggered(); +#endif + + DiagramLayout *layout_; + capture_file *cap_file_; + proto_node *root_node_; + field_info *selected_field_; + int y_pos_; +}; + +#endif // PACKET_DIAGRAM_H diff --git a/ui/qt/tcp_stream_dialog.cpp b/ui/qt/tcp_stream_dialog.cpp index b0b0f9c9ad..a19e3cd434 100644 --- a/ui/qt/tcp_stream_dialog.cpp +++ b/ui/qt/tcp_stream_dialog.cpp @@ -1823,6 +1823,7 @@ void TCPStreamDialog::transformYRange(const QCPRange &y_range1) sp->yAxis2->setRangeLower(yp2.y1()); } +// XXX - We have similar code in io_graph_dialog and packet_diagram. Should this be a common routine? void TCPStreamDialog::on_buttonBox_accepted() { QString file_name, extension; diff --git a/ui/qt/utils/field_information.cpp b/ui/qt/utils/field_information.cpp index 2648930c83..7dd1221084 100644 --- a/ui/qt/utils/field_information.cpp +++ b/ui/qt/utils/field_information.cpp @@ -136,16 +136,23 @@ const QString FieldInformation::moduleName() return module_name; } +QString FieldInformation::toString() +{ + QString repr; + gchar *repr_str; + repr_str = fvalue_to_string_repr(NULL, &fi_->value, FTREPR_DISPLAY, fi_->hfinfo->display); + if (repr_str) { + repr = repr_str; + } + wmem_free(NULL, repr_str); + return repr; +} + QString FieldInformation::url() { QString url; if (flag(FI_URL) && headerInfo().isValid && IS_FT_STRING(fi_->hfinfo->type)) { - gchar *url_str; - url_str = fvalue_to_string_repr(NULL, &fi_->value, FTREPR_DISPLAY, fi_->hfinfo->display); - if (url_str) { - url = url_str; - } - wmem_free(NULL, url_str); + url = toString(); } return url; } diff --git a/ui/qt/utils/field_information.h b/ui/qt/utils/field_information.h index e021b4ad1b..19df83e552 100644 --- a/ui/qt/utils/field_information.h +++ b/ui/qt/utils/field_information.h @@ -60,6 +60,7 @@ public: bool tvbContains(FieldInformation *); unsigned flag(unsigned mask); const QString moduleName(); + QString toString(); QString url(); const QByteArray printableData(); diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 35daf14f69..9bf6ad931d 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -1188,13 +1188,17 @@ void WiresharkApplication::zoomTextFont(int zoomLevel) { // Scale by 10%, rounding to nearest half point, minimum 1 point. // XXX Small sizes repeat. It might just be easier to create a map of multipliers. - zoomed_font_ = mono_font_; qreal zoom_size = mono_font_.pointSize() * 2 * qPow(qreal(1.1), zoomLevel); zoom_size = qRound(zoom_size) / qreal(2.0); zoom_size = qMax(zoom_size, qreal(1.0)); - zoomed_font_.setPointSizeF(zoom_size); + zoomed_font_ = mono_font_; + zoomed_font_.setPointSizeF(zoom_size); emit zoomMonospaceFont(zoomed_font_); + + QFont zoomed_application_font = font(); + zoomed_application_font.setPointSizeF(zoom_size); + emit zoomRegularFont(zoomed_application_font); } #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN) diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index 70d61c2f95..7b0af2098b 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -205,6 +205,7 @@ signals: /* Signals activation and stop of a capture. The value provides the number of active captures */ void captureActive(int); + void zoomRegularFont(const QFont & font); void zoomMonospaceFont(const QFont & font); public slots: diff --git a/ui/recent.c b/ui/recent.c index 4905666423..c36dbcad7b 100644 --- a/ui/recent.c +++ b/ui/recent.c @@ -35,6 +35,7 @@ #define RECENT_KEY_PACKET_LIST_SHOW "gui.packet_list_show" #define RECENT_KEY_TREE_VIEW_SHOW "gui.tree_view_show" #define RECENT_KEY_BYTE_VIEW_SHOW "gui.byte_view_show" +#define RECENT_KEY_PACKET_DIAGRAM_SHOW "gui.packet_diagram_show" #define RECENT_KEY_STATUSBAR_SHOW "gui.statusbar_show" #define RECENT_KEY_PACKET_LIST_COLORIZE "gui.packet_list_colorize" #define RECENT_GUI_TIME_FORMAT "gui.time_format" @@ -844,6 +845,10 @@ write_profile_recent(void) RECENT_KEY_BYTE_VIEW_SHOW, recent.byte_view_show); + write_recent_boolean(rf, "Packet diagram show (hide)", + RECENT_KEY_PACKET_DIAGRAM_SHOW, + recent.packet_diagram_show); + write_recent_boolean(rf, "Statusbar show (hide)", RECENT_KEY_STATUSBAR_SHOW, recent.statusbar_show); @@ -1054,6 +1059,8 @@ read_set_recent_pair_static(gchar *key, const gchar *value, parse_recent_boolean(value, &recent.tree_view_show); } else if (strcmp(key, RECENT_KEY_BYTE_VIEW_SHOW) == 0) { parse_recent_boolean(value, &recent.byte_view_show); + } else if (strcmp(key, RECENT_KEY_PACKET_DIAGRAM_SHOW) == 0) { + parse_recent_boolean(value, &recent.packet_diagram_show); } else if (strcmp(key, RECENT_KEY_STATUSBAR_SHOW) == 0) { parse_recent_boolean(value, &recent.statusbar_show); } else if (strcmp(key, RECENT_KEY_PACKET_LIST_COLORIZE) == 0) { @@ -1323,6 +1330,7 @@ recent_read_profile_static(char **rf_path_return, int *rf_errno_return) recent.packet_list_show = TRUE; recent.tree_view_show = TRUE; recent.byte_view_show = TRUE; + recent.packet_diagram_show = TRUE; recent.statusbar_show = TRUE; recent.packet_list_colorize = TRUE; recent.gui_time_format = TS_RELATIVE; diff --git a/ui/recent.h b/ui/recent.h index 2ba7110108..b154a57741 100644 --- a/ui/recent.h +++ b/ui/recent.h @@ -89,6 +89,7 @@ typedef struct recent_settings_tag { gboolean packet_list_show; gboolean tree_view_show; gboolean byte_view_show; + gboolean packet_diagram_show; gboolean statusbar_show; gboolean packet_list_colorize; ts_type gui_time_format; -- cgit v1.2.3