]> sigrok.org Git - pulseview.git/commitdiff
Add home and end shortcuts
authorMiklos Marton <redacted>
Wed, 10 Jul 2019 14:15:33 +0000 (16:15 +0200)
committerUwe Hermann <redacted>
Wed, 31 Jul 2019 20:47:56 +0000 (22:47 +0200)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index d04759cfe380d0920c2408ba10aaeaea065b0eb5..e33901a222c1db720adf58acba7f684be122d142 100644 (file)
@@ -517,6 +517,12 @@ void MainWindow::setup_ui()
        zoom_out_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Minus), this, SLOT(on_zoom_out_shortcut_triggered()));
        zoom_out_shortcut_->setAutoRepeat(false);
 
+       home_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Home), this, SLOT(on_scroll_to_start_triggered()));
+       home_shortcut_->setAutoRepeat(false);
+
+       end_shortcut_ = new QShortcut(QKeySequence(Qt::Key_End), this, SLOT(on_scroll_to_end_triggered()));
+       end_shortcut_->setAutoRepeat(false);
+
        // Set up the tab area
        new_session_button_ = new QToolButton();
        new_session_button_->setIcon(QIcon::fromTheme("document-new",
@@ -978,6 +984,29 @@ void MainWindow::on_zoom_in_shortcut_triggered()
        zoom_current_view(1);
 }
 
+void MainWindow::on_scroll_to_start_triggered()
+{
+       scroll_to_start_or_end(true);
+}
+
+void MainWindow::on_scroll_to_end_triggered()
+{
+       scroll_to_start_or_end(false);
+}
+
+void MainWindow::scroll_to_start_or_end(bool start)
+{
+       shared_ptr<Session> session = get_tab_session(session_selector_.currentIndex());
+
+       if (!session)
+               return;
+
+       shared_ptr<views::ViewBase> v = session.get()->main_view();
+       views::trace::View *tv =
+               qobject_cast<views::trace::View*>(v.get());
+       tv->set_h_offset(start ? 0 : tv->get_h_scrollbar_maximum());
+}
+
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index 6f2fded904d426a57257780c8be62b461c680c17..141e96e90dd74d8b1e1befd635d49bfee2827ec8 100644 (file)
@@ -109,6 +109,7 @@ private:
        void restore_ui_settings();
 
        void zoom_current_view(double steps);
+       void scroll_to_start_or_end(bool start);
 
        shared_ptr<Session> get_tab_session(int index) const;
 
@@ -152,6 +153,8 @@ private Q_SLOTS:
 
        void on_zoom_out_shortcut_triggered();
        void on_zoom_in_shortcut_triggered();
+       void on_scroll_to_start_triggered();
+       void on_scroll_to_end_triggered();
 
        void on_close_current_tab();
 
@@ -184,6 +187,8 @@ private:
        QShortcut *close_current_tab_shortcut_;
        QShortcut *zoom_in_shortcut_;
        QShortcut *zoom_out_shortcut_;
+       QShortcut *home_shortcut_;
+       QShortcut *end_shortcut_;
 };
 
 } // namespace pv
index 56461e4647effc796cad0895af355c72106ac2d7..f2a3335e6990fe4363996606cf87e70846d0cbba 100644 (file)
@@ -510,6 +510,18 @@ void View::set_v_offset(int offset)
        viewport_->update();
 }
 
+void View::set_h_offset(int offset)
+{
+       scrollarea_->horizontalScrollBar()->setSliderPosition(offset);
+       header_->update();
+       viewport_->update();
+}
+
+int View::get_h_scrollbar_maximum() const
+{
+       return scrollarea_->horizontalScrollBar()->maximum();
+}
+
 unsigned int View::depth() const
 {
        return 0;
index e056805b4d798da23a2f2407ac3d5818e4e0c553..a0e6f6bcc1d237689b3e6bb67afce9600b56166b 100644 (file)
@@ -189,6 +189,16 @@ public:
         */
        void set_v_offset(int offset);
 
+       /**
+        * Sets the visual h-offset.
+        */
+       void set_h_offset(int offset);
+
+       /**
+        * Gets the length of the horizontal scrollbar.
+        */
+       int get_h_scrollbar_maximum() const;
+
        /**
         * Returns the SI prefix to apply to the graticule time markings.
         */