diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/byte_view_tab.cpp | 2 | ||||
-rw-r--r-- | ui/qt/byte_view_tab.h | 1 | ||||
-rw-r--r-- | ui/qt/widgets/byte_view_text.cpp | 93 | ||||
-rw-r--r-- | ui/qt/widgets/byte_view_text.h | 10 |
4 files changed, 70 insertions, 36 deletions
diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index 62a88e28f4..3e5b9a3b43 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -114,6 +114,8 @@ void ByteViewTab::addTab(const char *name, tvbuff_t *tvb) { connect(byte_view_text, SIGNAL(byteHovered(int)), this, SLOT(byteViewTextHovered(int))); connect(byte_view_text, SIGNAL(byteSelected(int)), this, SLOT(byteViewTextMarked(int))); + connect(byte_view_text, SIGNAL(byteViewSettingsChanged()), this, SIGNAL(byteViewSettingsChanged())); + connect(this, SIGNAL(byteViewSettingsChanged()), byte_view_text, SLOT(updateByteViewSettings())); } int idx = QTabWidget::addTab(byte_view_text, name); diff --git a/ui/qt/byte_view_tab.h b/ui/qt/byte_view_tab.h index f1aa93a700..d7291addf5 100644 --- a/ui/qt/byte_view_tab.h +++ b/ui/qt/byte_view_tab.h @@ -45,6 +45,7 @@ public slots: signals: void fieldSelected(FieldInformation *); void fieldHighlight(FieldInformation *); + void byteViewSettingsChanged(void); private: capture_file *cap_file_; diff --git a/ui/qt/widgets/byte_view_text.cpp b/ui/qt/widgets/byte_view_text.cpp index d533c1b7f5..3c1fcfd2aa 100644 --- a/ui/qt/widgets/byte_view_text.cpp +++ b/ui/qt/widgets/byte_view_text.cpp @@ -76,25 +76,18 @@ ByteViewText::~ByteViewText() void ByteViewText::createContextMenu() { - QAction *action; - QActionGroup * copy_actions = DataPrinter::copyActions(this); ctx_menu_.addActions(copy_actions->actions()); ctx_menu_.addSeparator(); QActionGroup * format_actions = new QActionGroup(this); - action = format_actions->addAction(tr("Show bytes as hexadecimal")); - action->setData(QVariant::fromValue(BYTES_HEX)); - action->setCheckable(true); - if (recent.gui_bytes_view == BYTES_HEX) { - action->setChecked(true); - } - action = format_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as bits")); - action->setData(QVariant::fromValue(BYTES_BITS)); - action->setCheckable(true); - if (recent.gui_bytes_view == BYTES_BITS) { - action->setChecked(true); - } + action_bytes_hex_ = format_actions->addAction(tr("Show bytes as hexadecimal")); + action_bytes_hex_->setData(QVariant::fromValue(BYTES_HEX)); + action_bytes_hex_->setCheckable(true); + + action_bytes_bits_ = format_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as bits")); + action_bytes_bits_->setData(QVariant::fromValue(BYTES_BITS)); + action_bytes_bits_->setCheckable(true); ctx_menu_.addActions(format_actions->actions()); connect(format_actions, &QActionGroup::triggered, this, &ByteViewText::setHexDisplayFormat); @@ -102,29 +95,48 @@ void ByteViewText::createContextMenu() ctx_menu_.addSeparator(); QActionGroup * encoding_actions = new QActionGroup(this); - action = encoding_actions->addAction(tr("Show text based on packet")); - action->setData(QVariant::fromValue(BYTES_ENC_FROM_PACKET)); - action->setCheckable(true); - if (recent.gui_bytes_encoding == BYTES_ENC_FROM_PACKET) { - action->setChecked(true); - } - action = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as ASCII")); - action->setData(QVariant::fromValue(BYTES_ENC_ASCII)); - action->setCheckable(true); - if (recent.gui_bytes_encoding == BYTES_ENC_ASCII) { - action->setChecked(true); - } - action = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as EBCDIC")); - action->setData(QVariant::fromValue(BYTES_ENC_EBCDIC)); - action->setCheckable(true); - if (recent.gui_bytes_encoding == BYTES_ENC_EBCDIC) { - action->setChecked(true); - } + action_bytes_enc_from_packet_ = encoding_actions->addAction(tr("Show text based on packet")); + action_bytes_enc_from_packet_->setData(QVariant::fromValue(BYTES_ENC_FROM_PACKET)); + action_bytes_enc_from_packet_->setCheckable(true); + + action_bytes_enc_ascii_ = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as ASCII")); + action_bytes_enc_ascii_->setData(QVariant::fromValue(BYTES_ENC_ASCII)); + action_bytes_enc_ascii_->setCheckable(true); + + action_bytes_enc_ebcdic_ = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as EBCDIC")); + action_bytes_enc_ebcdic_->setData(QVariant::fromValue(BYTES_ENC_EBCDIC)); + action_bytes_enc_ebcdic_->setCheckable(true); + + updateContextMenu(); ctx_menu_.addActions(encoding_actions->actions()); connect(encoding_actions, &QActionGroup::triggered, this, &ByteViewText::setCharacterEncoding); } +void ByteViewText::updateContextMenu() +{ + switch (recent.gui_bytes_view) { + case BYTES_HEX: + action_bytes_hex_->setChecked(true); + break; + case BYTES_BITS: + action_bytes_bits_->setChecked(true); + break; + } + + switch (recent.gui_bytes_encoding) { + case BYTES_ENC_FROM_PACKET: + action_bytes_enc_from_packet_->setChecked(true); + break; + case BYTES_ENC_ASCII: + action_bytes_enc_ascii_->setChecked(true); + break; + case BYTES_ENC_EBCDIC: + action_bytes_enc_ebcdic_->setChecked(true); + break; + } +} + bool ByteViewText::isEmpty() const { return data_.isEmpty(); @@ -182,6 +194,15 @@ void ByteViewText::setMonospaceFont(const QFont &mono_font) viewport()->update(); } +void ByteViewText::updateByteViewSettings() +{ + row_width_ = recent.gui_bytes_view == BYTES_HEX ? 16 : 8; + + updateContextMenu(); + updateScrollbars(); + viewport()->update(); +} + void ByteViewText::paintEvent(QPaintEvent *) { QPainter painter(viewport()); @@ -659,9 +680,8 @@ void ByteViewText::setHexDisplayFormat(QAction *action) } recent.gui_bytes_view = action->data().value<bytes_view_type>(); - row_width_ = recent.gui_bytes_view == BYTES_HEX ? 16 : 8; - updateScrollbars(); - viewport()->update(); + + emit byteViewSettingsChanged(); } void ByteViewText::setCharacterEncoding(QAction *action) @@ -671,7 +691,8 @@ void ByteViewText::setCharacterEncoding(QAction *action) } recent.gui_bytes_encoding = action->data().value<bytes_encoding_type>(); - viewport()->update(); + + emit byteViewSettingsChanged(); } /* diff --git a/ui/qt/widgets/byte_view_text.h b/ui/qt/widgets/byte_view_text.h index 00d020d2f7..13e2c49389 100644 --- a/ui/qt/widgets/byte_view_text.h +++ b/ui/qt/widgets/byte_view_text.h @@ -45,9 +45,11 @@ public: signals: void byteHovered(int pos); void byteSelected(int pos); + void byteViewSettingsChanged(); public slots: void setMonospaceFont(const QFont &mono_font); + void updateByteViewSettings(); void markProtocol(int start, int length); void markField(int start, int length, bool scroll_to = true); @@ -84,6 +86,7 @@ private: int byteOffsetAtPixel(QPoint pos); void createContextMenu(); + void updateContextMenu(); int offsetChars(bool include_pad = true); int offsetPixels(); @@ -123,6 +126,13 @@ private: // Data selection QVector<int> x_pos_to_column_; + // Context menu actions + QAction *action_bytes_hex_; + QAction *action_bytes_bits_; + QAction *action_bytes_enc_from_packet_; + QAction *action_bytes_enc_ascii_; + QAction *action_bytes_enc_ebcdic_; + private slots: void copyBytes(bool); void setHexDisplayFormat(QAction *action); |