changeset 24762:ed2d9ef336a7

resize varible editor model on scrollbar actions * variable-editor.h, variable-editor.cc (var_editor_tab::handle_horizontal_scroll_action, var_editor_tab::handle_vertical_scroll_action): New slots. (var_editor_tab_widget::var_editor_tab_widget): Connect signals and slots for scrollbar actions.
author John W. Eaton <jwe@octave.org>
date Wed, 14 Feb 2018 23:50:55 -0500
parents d7c3918955e6
children 95142fc85564
files libgui/src/variable-editor.cc libgui/src/variable-editor.h
diffstat 2 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/variable-editor.cc	Wed Feb 14 23:46:41 2018 -0500
+++ b/libgui/src/variable-editor.cc	Wed Feb 14 23:50:55 2018 -0500
@@ -35,6 +35,7 @@
 #include <QLabel>
 #include <QMenu>
 #include <QPalette>
+#include <QScrollBar>
 #include <QSignalMapper>
 #include <QStackedWidget>
 #include <QTableView>
@@ -154,6 +155,54 @@
     }
 }
 
+void
+var_editor_tab::handle_horizontal_scroll_action (int action)
+{
+  if (action == QAbstractSlider::SliderSingleStepAdd
+      || action == QAbstractSlider::SliderPageStepAdd
+      || action == QAbstractSlider::SliderToMaximum
+      || action == QAbstractSlider::SliderMove)
+    {
+      QTableView *edit_view = get_edit_view ();
+
+      if (edit_view)
+        {
+          QScrollBar *sb = edit_view->horizontalScrollBar ();
+
+          if (sb && sb->value () == sb->maximum ())
+            {
+              int new_cols = m_model->display_columns () + 16;
+
+              m_model->maybe_resize_columns (new_cols);
+            }
+        }
+    }
+}
+
+void
+var_editor_tab::handle_vertical_scroll_action (int action)
+{
+  if (action == QAbstractSlider::SliderSingleStepAdd
+      || action == QAbstractSlider::SliderPageStepAdd
+      || action == QAbstractSlider::SliderToMaximum
+      || action == QAbstractSlider::SliderMove)
+    {
+      QTableView *edit_view = get_edit_view ();
+
+      if (edit_view)
+        {
+          QScrollBar *sb = edit_view->verticalScrollBar ();
+
+          if (sb && sb->value () == sb->maximum ())
+            {
+              int new_rows = m_model->display_rows () + 16;
+
+              m_model->maybe_resize_rows (new_rows);
+            }
+        }
+    }
+}
+
 // Functions for reimplemented tab widget.
 
 var_editor_tab_widget::var_editor_tab_widget (QWidget *p)
@@ -440,6 +489,15 @@
   connect (table, SIGNAL (doubleClicked (const QModelIndex&)),
            this, SLOT (double_click (const QModelIndex&)));
 
+  table->setHorizontalScrollMode (QAbstractItemView::ScrollPerPixel);
+  table->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel);
+
+  connect (table->horizontalScrollBar (), SIGNAL (actionTriggered (int)),
+           page, SLOT (handle_horizontal_scroll_action (int)));
+
+  connect (table->verticalScrollBar (), SIGNAL (actionTriggered (int)),
+           page, SLOT (handle_vertical_scroll_action (int)));
+
   table->setFont (m_font);
   table->setStyleSheet (m_stylesheet);
   table->setAlternatingRowColors (m_alternate_rows);
--- a/libgui/src/variable-editor.h	Wed Feb 14 23:46:41 2018 -0500
+++ b/libgui/src/variable-editor.h	Wed Feb 14 23:50:55 2018 -0500
@@ -80,6 +80,10 @@
 
   void set_editable (bool);
 
+  void handle_horizontal_scroll_action (int action);
+
+  void handle_vertical_scroll_action (int action);
+
 private:
 
   variable_editor_model *m_model;