]> sigrok.org Git - pulseview.git/commitdiff
TabularDecView: Allow return/enter press and don't change scale
authorSoeren Apel <redacted>
Wed, 10 Jun 2020 22:51:17 +0000 (00:51 +0200)
committerSoeren Apel <redacted>
Thu, 25 Jun 2020 07:54:19 +0000 (09:54 +0200)
pv/views/tabular_decoder/view.cpp
pv/views/tabular_decoder/view.hpp
pv/views/trace/view.cpp

index 4715b4a90b5070444238779e682f42a4dc98eb7e..91bcaea197bee2a0645d9f314fb77c2f5053df21 100644 (file)
@@ -139,6 +139,14 @@ QSize CustomTableView::sizeHint() const
        return minimumSizeHint();
 }
 
+void CustomTableView::keyPressEvent(QKeyEvent *event)
+{
+       if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter))
+               activatedByKey(currentIndex());
+       else
+               QTableView::keyPressEvent(event);
+}
+
 
 View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        ViewBase(session, is_main_view, parent),
@@ -239,6 +247,8 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
                this, SLOT(on_table_item_clicked(const QModelIndex&)));
        connect(table_view_, SIGNAL(doubleClicked(const QModelIndex&)),
                this, SLOT(on_table_item_double_clicked(const QModelIndex&)));
+       connect(table_view_, SIGNAL(activatedByKey(const QModelIndex&)),
+               this, SLOT(on_table_item_double_clicked(const QModelIndex&)));
        connect(table_view_->horizontalHeader(), SIGNAL(customContextMenuRequested(const QPoint&)),
                this, SLOT(on_table_header_requested(const QPoint&)));
 
index 2d0ce54a1a50feda50db19aefe04b44016b12226..3cdcac18637195d597049a90e6505bac0f6409fb 100644 (file)
@@ -23,6 +23,7 @@
 #include <QAction>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QKeyEvent>
 #include <QSortFilterProxyModel>
 #include <QTableView>
 #include <QToolButton>
@@ -130,8 +131,14 @@ class CustomTableView : public QTableView
        Q_OBJECT
 
 public:
-       QSize minimumSizeHint() const;
-       QSize sizeHint() const;
+       virtual QSize minimumSizeHint() const override;
+       virtual QSize sizeHint() const override;
+
+protected:
+       virtual void keyPressEvent(QKeyEvent *event) override;
+
+Q_SIGNALS:
+       void activatedByKey(const QModelIndex &index);
 };
 
 
index 43853359540baf83859d3abd69fffde9254e9b22..e2d9365efaf12d4c09a8a3df9b3891dd9ab38e94 100644 (file)
@@ -854,21 +854,31 @@ void View::zoom_fit(bool gui_state)
 void View::focus_on_range(uint64_t start_sample, uint64_t end_sample)
 {
        assert(viewport_);
-       const int w = viewport_->width();
+       const uint64_t w = viewport_->width();
        if (w <= 0)
                return;
 
        const double samplerate = session_.get_samplerate();
+       const double samples_per_pixel = samplerate * scale_;
+       const uint64_t viewport_samples = w * samples_per_pixel;
 
        const uint64_t sample_delta = (end_sample - start_sample);
 
        // Note: We add 20% margin on the left and 5% on the right
-       const Timestamp delta = (sample_delta * 1.25) / samplerate;
-
-       const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
-       const Timestamp offset = (start_sample - sample_delta * 0.20) / samplerate;
-
-       set_scale_offset(scale.convert_to<double>(), offset);
+       const uint64_t ext_sample_delta = sample_delta * 1.25;
+
+       // Check if we can keep the zoom level and just center the supplied range
+       if (viewport_samples >= ext_sample_delta) {
+               // Note: offset is the left edge of the view so to center, we subtract half the view width
+               const int64_t sample_offset = (start_sample + (sample_delta / 2) - (viewport_samples / 2));
+               const Timestamp offset = sample_offset / samplerate;
+               set_scale_offset(scale_, offset);
+       } else {
+               const Timestamp offset = (start_sample - sample_delta * 0.20) / samplerate;
+               const Timestamp delta = ext_sample_delta / samplerate;
+               const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
+               set_scale_offset(scale.convert_to<double>(), offset);
+       }
 }
 
 void View::set_scale_offset(double scale, const Timestamp& offset)