]> sigrok.org Git - pulseview.git/commitdiff
DecoderSelector: Make window as wide as necessary when opening
authorSoeren Apel <redacted>
Tue, 19 Mar 2019 20:27:08 +0000 (21:27 +0100)
committerSoeren Apel <redacted>
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 43d1e7d2607dbf2ab9a95377f806eed9d8c0640c..aa0bf94894f156c303dd094e936cbed8d9704fc7 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 675e135cefad3f682e4609f71cc1f8eadcd55d60..0172a43d9a4951b97a322ca46bee7c397e3706e1 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 6bb1439758abfb95776d6b3c51755f0895acd5fa..a1ace196eb66eb3f64ab431270473c850ef82fb4 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 8606d65775339177ea8727fdd5562bc827acda38..de08c4409ca452f7b5255b1c7ab69dfc46bee193 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 47b8ce392c925cbcdda15fa96821eb6828a2d227..ab3a08b412af72790fde7eed678030a8bdc4b91e 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();