DecoderSelector: Make window as wide as necessary when opening
authorSoeren Apel <soeren@apelpie.net>
Tue, 19 Mar 2019 20:27:08 +0000 (21:27 +0100)
committerSoeren Apel <soeren@apelpie.net>
Tue, 19 Mar 2019 20:27:08 +0000 (21:27 +0100)
pv/mainwindow.cpp
pv/subwindows/decoder_selector/subwindow.cpp
pv/subwindows/decoder_selector/subwindow.hpp
pv/subwindows/subwindowbase.cpp
pv/subwindows/subwindowbase.hpp

index 43d1e7d..aa0bf94 100644 (file)
@@ -313,6 +313,9 @@ shared_ptr<subwindows::SubWindowBase> 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;
 }
 
index 675e135..0172a43 100644 (file)
@@ -19,7 +19,9 @@
 
 #include <algorithm>
 
+#include <QApplication>
 #include <QDebug>
+#include <QFontMetrics>
 #include <QInputDialog>
 #include <QLabel>
 #include <QLineEdit>
@@ -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<const char*> SubWindow::get_decoder_inputs(const srd_decoder* d) const
 {
        vector<const char*> ret_val;
index 6bb1439..a1ace19 100644 (file)
@@ -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.)
index 8606d65..de08c44 100644 (file)
@@ -98,6 +98,11 @@ void SubWindowBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
 }
 #endif
 
+int SubWindowBase::minimum_width() const
+{
+       return 0;
+}
+
 void SubWindowBase::on_signals_changed()
 {
 }
index 47b8ce3..ab3a08b 100644 (file)
@@ -76,6 +76,8 @@ public:
        virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
 #endif
 
+       virtual int minimum_width() const;
+
 public Q_SLOTS:
        virtual void on_signals_changed();