diff libgui/src/workspace-view.cc @ 20605:734d446560a8

possibility to hide filters in history and workspace view (bug#45428) * history_dock_widget.cc(construct): use settings file for show/hide the filter; (~history_dock_widget): save current filter state to settings file; (ctxMenu): add menu entry for showing/hiding the filter; (handle_contextmenu_filter): slot for the new menu entry * history-dock-widget.h: new slot for new menu entry, new class variables for filter and show/hide-state * workspace-view.cc(workspace_view): use settings file for show/hide the filter; (~workspace_view): save current filter state to settings file; (contextmenu_requested): add menu entry for showing/hiding the filter; (handle_contextmenu_filter): slot for the new menu entry * workspace-view.h: new slot for new menu entry, new class variables for filter and show/hide-state
author Torsten <ttl@justmail.de>
date Wed, 07 Oct 2015 21:01:25 +0200
parents 2b28f509b645
children
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc	Wed Oct 07 07:41:44 2015 -0700
+++ b/libgui/src/workspace-view.cc	Wed Oct 07 21:01:25 2015 +0200
@@ -75,23 +75,32 @@
   // Set an empty widget, so we can assign a layout to it.
   setWidget (new QWidget (this));
 
-  // Create a new layout and add widgets to it.
-  QVBoxLayout *vbox_layout = new QVBoxLayout ();
-  QHBoxLayout *hbox_layout = new QHBoxLayout ();
-  hbox_layout->addWidget (filter_label);
-  hbox_layout->addWidget (_filter_checkbox);
-  hbox_layout->addWidget (_filter);
-  vbox_layout->addLayout (hbox_layout);
-  vbox_layout->addWidget (view);
-  vbox_layout->setMargin (2);
+  // Create the layouts
+  _filter_widget = new QWidget (this);
+  QHBoxLayout *filter_layout = new QHBoxLayout ();
+
+  filter_layout->addWidget (filter_label);
+  filter_layout->addWidget (_filter_checkbox);
+  filter_layout->addWidget (_filter);
+  filter_layout->setMargin(0);
+  _filter_widget->setLayout (filter_layout);
+
+  QVBoxLayout *ws_layout = new QVBoxLayout ();
+  ws_layout->addWidget (_filter_widget);
+  ws_layout->addWidget (view);
+
+  QSettings *settings = resource_manager::get_settings ();
+
+  _filter_shown = settings->value ("workspaceview/filter_shown",true).toBool();
+  _filter_widget->setVisible (_filter_shown);
+
+  ws_layout->setMargin (2);
 
   // Set the empty widget to have our layout.
-  widget ()->setLayout (vbox_layout);
+  widget ()->setLayout (ws_layout);
 
   // Initialize collapse/expand state of the workspace subcategories.
 
-  QSettings *settings = resource_manager::get_settings ();
-
   //enable sorting (setting column and order after model was set)
   view->setSortingEnabled (true);
   // Initialize column order and width of the workspace
@@ -129,7 +138,6 @@
 
   connect (this, SIGNAL (command_requested (const QString&)),
            p, SLOT (execute_command_in_terminal (const QString&)));
-
 }
 
 workspace_view::~workspace_view (void)
@@ -146,6 +154,7 @@
 
   settings->setValue ("workspaceview/filter_active",
                       _filter_checkbox->isChecked ());
+  settings->setValue ("workspaceview/filter_shown", _filter_shown);
 
   QStringList mru;
   for (int i = 0; i < _filter->count (); i++)
@@ -263,8 +272,18 @@
       menu.addAction ("stem (" + var_name + ")", this,
                       SLOT (handle_contextmenu_stem ()));
 
-      menu.exec (view->mapToGlobal (qpos));
+      menu.addSeparator ();
+
     }
+
+  if (_filter_shown)
+    menu.addAction (tr ("Hide filter"), this,
+                    SLOT (handle_contextmenu_filter ()));
+  else
+    menu.addAction (tr ("Show filter"), this,
+                    SLOT (handle_contextmenu_filter ()));
+
+  menu.exec (view->mapToGlobal (qpos));
 }
 
 void
@@ -359,6 +378,13 @@
 }
 
 void
+workspace_view::handle_contextmenu_filter (void)
+{
+  _filter_shown = not _filter_shown;
+  _filter_widget->setVisible (_filter_shown);
+}
+
+void
 workspace_view::handle_model_changed (void)
 {
 //  view->resizeRowsToContents ();