From: Soeren Apel Date: Tue, 19 Mar 2019 20:27:08 +0000 (+0100) Subject: DecoderSelector: Make window as wide as necessary when opening X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c52493c97570bfef5e4efb50e9f115da562ecf06;p=pulseview.git DecoderSelector: Make window as wide as necessary when opening --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 43d1e7d2..aa0bf948 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -313,6 +313,9 @@ shared_ptr MainWindow::add_subwindow( if (v->has_toolbar()) dock_main->addToolBar(v->create_toolbar(dock_main)); + if (v->minimum_width() > 0) + dock->setMinimumSize(v->minimum_width(), 0); + return v; } diff --git a/pv/subwindows/decoder_selector/subwindow.cpp b/pv/subwindows/decoder_selector/subwindow.cpp index 675e135c..0172a43d 100644 --- a/pv/subwindows/decoder_selector/subwindow.cpp +++ b/pv/subwindows/decoder_selector/subwindow.cpp @@ -19,7 +19,9 @@ #include +#include #include +#include #include #include #include @@ -37,6 +39,9 @@ namespace pv { namespace subwindows { namespace decoder_selector { +const QString initial_notice = QApplication::tr("Select a decoder to see its description here."); +const int min_width_margin = 75; + bool QCustomSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const @@ -126,7 +131,7 @@ SubWindow::SubWindow(Session& session, QWidget* parent) : info_label_header_->setTextInteractionFlags(flags); info_label_body_->setWordWrap(true); info_label_body_->setTextInteractionFlags(flags); - info_label_body_->setText(tr("Select a decoder to see its description here.")); + info_label_body_->setText(initial_notice); info_label_footer_->setWordWrap(true); info_label_footer_->setTextInteractionFlags(flags); @@ -154,6 +159,14 @@ QToolBar* SubWindow::create_toolbar(QWidget *parent) const return toolbar; } +int SubWindow::minimum_width() const +{ + QFontMetrics m(info_label_body_->font()); + const int label_width = m.width(initial_notice); + + return label_width + min_width_margin; +} + vector SubWindow::get_decoder_inputs(const srd_decoder* d) const { vector ret_val; diff --git a/pv/subwindows/decoder_selector/subwindow.hpp b/pv/subwindows/decoder_selector/subwindow.hpp index 6bb14397..a1ace196 100644 --- a/pv/subwindows/decoder_selector/subwindow.hpp +++ b/pv/subwindows/decoder_selector/subwindow.hpp @@ -112,6 +112,8 @@ public: bool has_toolbar() const; QToolBar* create_toolbar(QWidget *parent) const; + int minimum_width() const; + /** * Returns a list of input types that a given protocol decoder requires * ("logic", "uart", etc.) diff --git a/pv/subwindows/subwindowbase.cpp b/pv/subwindows/subwindowbase.cpp index 8606d657..de08c440 100644 --- a/pv/subwindows/subwindowbase.cpp +++ b/pv/subwindows/subwindowbase.cpp @@ -98,6 +98,11 @@ void SubWindowBase::remove_decode_signal(shared_ptr signal) } #endif +int SubWindowBase::minimum_width() const +{ + return 0; +} + void SubWindowBase::on_signals_changed() { } diff --git a/pv/subwindows/subwindowbase.hpp b/pv/subwindows/subwindowbase.hpp index 47b8ce39..ab3a08b4 100644 --- a/pv/subwindows/subwindowbase.hpp +++ b/pv/subwindows/subwindowbase.hpp @@ -76,6 +76,8 @@ public: virtual void remove_decode_signal(shared_ptr signal); #endif + virtual int minimum_width() const; + public Q_SLOTS: virtual void on_signals_changed();