diff libgui/src/workspace-view.cc @ 16572:17941fedd4ce

Change workspace row height to font height. * main-window.cc (main_window::construct): Connect workspace_model signal to workspace_view slot. * workspace-view.cc, workspace-view.h (workspace_view::workspace_view): New variable view_previous_row_count initialized to zero. (workspace_view::contextmenu_requested): Rename pos from shadow to qpos. (workspace_view::handle_model_changed): New slot to adjust appearance.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Fri, 12 Apr 2013 03:48:56 -0500
parents d5ae5aa80d42
children 1a1f8199b5bb
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc	Fri Apr 26 14:25:09 2013 +0200
+++ b/libgui/src/workspace-view.cc	Fri Apr 12 03:48:56 2013 -0500
@@ -49,6 +49,7 @@
 
   view->setWordWrap (false);
   view->setContextMenuPolicy (Qt::CustomContextMenu);
+  view_previous_row_count = 0;
 
   // Set an empty widget, so we can assign a layout to it.
   setWidget (new QWidget (this));
@@ -96,11 +97,11 @@
 }
 
 void
-workspace_view::contextmenu_requested (const QPoint& pos)
+workspace_view::contextmenu_requested (const QPoint& qpos)
 {
   QMenu menu (this);
 
-  QModelIndex index = view->indexAt (pos);
+  QModelIndex index = view->indexAt (qpos);
   QAbstractItemModel *m = view->model ();
 
   // if it isnt Local, Glocal etc, allow the ctx menu
@@ -137,7 +138,7 @@
       menu.addAction ("stem(" + var_name + ")", this,
                       SLOT (handle_contextmenu_stem ()));
 
-      menu.exec (view->mapToGlobal (pos));
+      menu.exec (view->mapToGlobal (qpos));
     }
 }
 
@@ -228,3 +229,16 @@
       emit command_requested (cmdname + "(" + var_name + ")\n");
     }
 }
+
+void
+workspace_view::handle_model_changed (void)
+{
+  // Just modify those rows that have been added rather than go through
+  // the whole list.  For-loop test will handle when number of rows reduced.
+  QFontMetrics fm = view->fontMetrics ();
+  int row_height =  fm.height ();
+  int new_row_count = view->model ()->rowCount ();
+  for (int i = view_previous_row_count; i < new_row_count; i++)
+    view->setRowHeight (i, row_height);
+  view_previous_row_count = new_row_count;
+}