From 3c5a9b10b4dd6696861a62672b322807bb2bfdf6 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 27 Apr 2016 16:53:03 -0700 Subject: Qt: Display filter toolbar behavior tweaks. By default GtkToolbar shows overflow items in a menu. QToolBar shows them in a bigger toolbar. This is a problem for users with lots of display filter expressions because expanding the display filter toolbar can make it very tall. QToolBar can optionally overflow into a menu, but as noted in https://bugreports.qt.io/browse/QTBUG-2472 there isn't a way do so directly, e.g. with a setter. Force an overflow menu in the display filter toolbar by adding a child QToolBar and adding filter expression actions to it. While we're here, set the minimum width of the display filter edit to two-thirds of the width of the main window. Change-Id: I49cd58397e087f1aa79b5bbce471f827e9804148 Reviewed-on: https://code.wireshark.org/review/15134 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs --- ui/qt/main_window.cpp | 12 ++++++++++++ ui/qt/main_window.h | 4 +++- ui/qt/main_window_slots.cpp | 9 +++++---- 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index da39acaaa3..2e1d9b453d 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -361,6 +361,13 @@ MainWindow::MainWindow(QWidget *parent) : main_ui_->displayFilterToolBar->insertWidget(main_ui_->actionDisplayFilterExpression, df_combo_box_); + // Make sure filter expressions overflow into a menu instead of a + // larger toolbar. We do this by adding them to a child toolbar. + // https://bugreports.qt.io/browse/QTBUG-2472 + filter_expression_toolbar_ = new QToolBar(); + filter_expression_toolbar_->setStyleSheet("QToolBar { background: none; border: none; }"); + main_ui_->displayFilterToolBar->addWidget(filter_expression_toolbar_); + wireless_frame_ = new WirelessFrame(this); main_ui_->wirelessToolBar->addWidget(wireless_frame_); connect(wireless_frame_, SIGNAL(pushAdapterStatus(const QString&)), @@ -2139,6 +2146,11 @@ void MainWindow::changeEvent(QEvent* event) QMainWindow::changeEvent(event); } +void MainWindow::resizeEvent(QResizeEvent *) +{ + df_combo_box_->setMinimumWidth(width() * 2 / 3); // Arbitrary +} + /* Update main window items based on whether there's a capture in progress. */ void MainWindow::setForCaptureInProgress(gboolean capture_in_progress) { diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 235011fe57..72bf460479 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -154,6 +154,7 @@ private: QWidget *freeze_focus_; QMap td_actions; QMap tp_actions; + QToolBar *filter_expression_toolbar_; bool capture_stopping_; bool capture_filter_valid_; @@ -609,7 +610,8 @@ private slots: void on_actionContextWikiProtocolPage_triggered(); void on_actionContextFilterFieldReference_triggered(); - void changeEvent(QEvent* event); + virtual void changeEvent(QEvent* event); + virtual void resizeEvent(QResizeEvent *); #ifdef HAVE_EXTCAP void extcap_options_finished(int result); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 5a144545cb..a63824a667 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -772,10 +772,10 @@ void MainWindow::captureFileSaveStarted(const QString &file_path) void MainWindow::filterExpressionsChanged() { // Recreate filter buttons - foreach (QAction *act, main_ui_->displayFilterToolBar->actions()) { + foreach (QAction *act, filter_expression_toolbar_->actions()) { // Permanent actions shouldn't have data if (act->property(dfe_property_).isValid()) { - main_ui_->displayFilterToolBar->removeAction(act); + filter_expression_toolbar_->removeAction(act); delete act; } } @@ -783,13 +783,14 @@ void MainWindow::filterExpressionsChanged() // XXX Add a context menu for removing and changing buttons. for (struct filter_expression *fe = *pfilter_expression_head; fe != NULL; fe = fe->next) { if (!fe->enabled) continue; - QAction *dfb_action = new QAction(fe->label, main_ui_->displayFilterToolBar); + QAction *dfb_action = new QAction(fe->label, filter_expression_toolbar_); dfb_action->setToolTip(fe->expression); dfb_action->setData(fe->expression); dfb_action->setProperty(dfe_property_, true); - main_ui_->displayFilterToolBar->addAction(dfb_action); + filter_expression_toolbar_->addAction(dfb_action); connect(dfb_action, SIGNAL(triggered()), this, SLOT(displayFilterButtonClicked())); } + main_ui_->displayFilterToolBar->update(); } // -- cgit v1.2.1