changeset 19603:9b90d8579c61

maint: Periodic merge of gui-release to default.
author Rik <rik@octave.org>
date Mon, 12 Jan 2015 09:17:35 -0800
parents c36c22808d11 (current diff) f88ee85d4da9 (diff)
children 62ca016dbb2a
files libgui/src/history-dock-widget.cc scripts/plot/util/private/__ghostscript__.m scripts/plot/util/private/__print_parse_opts__.m
diffstat 5 files changed, 128 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/history-dock-widget.cc	Mon Jan 12 13:44:24 2015 +0100
+++ b/libgui/src/history-dock-widget.cc	Mon Jan 12 09:17:35 2015 -0800
@@ -30,7 +30,11 @@
 #include <QMenu>
 #include <QScrollBar>
 #include <QDesktopWidget>
+#include <QCompleter>
+#include <QLabel>
+
 #include "error.h"
+#include "resource-manager.h"
 
 #include "cmd-hist.h"
 
@@ -71,29 +75,58 @@
            SIGNAL (customContextMenuRequested (const QPoint &)), this,
            SLOT (ctxMenu (const QPoint &)));
 
-  _filter_line_edit = new QLineEdit (this);
-  _filter_line_edit->setStatusTip (
-    tr ("Enter text to filter the command history."));
-  QVBoxLayout *vbox_layout = new QVBoxLayout ();
+  _filter = new QComboBox (this);
+  _filter->setToolTip (tr ("Enter text to filter the command history"));
+  _filter->setEditable (true);
+  _filter->setMaxCount (MaxFilterHistory);
+  _filter->setInsertPolicy (QComboBox::NoInsert);
+  _filter->setSizeAdjustPolicy (
+            QComboBox::AdjustToMinimumContentsLengthWithIcon);
+  QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Maximum);
+  _filter->setSizePolicy (sizePol);
+  _filter->completer ()->setCaseSensitivity (Qt::CaseSensitive);
+
+  QLabel *filter_label = new QLabel (tr ("Filter"));
+
+  _filter_checkbox = new QCheckBox ();
 
   setWindowIcon (QIcon (":/actions/icons/logo.png"));
   set_title (tr ("Command History"));
   setWidget (new QWidget ());
 
+  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 (_history_list_view);
-  vbox_layout->addWidget (_filter_line_edit);
   vbox_layout->setMargin (2);
 
   widget ()->setLayout (vbox_layout);
 
-  connect (_filter_line_edit, SIGNAL (textEdited (QString)),
-           &_sort_filter_proxy_model, SLOT (setFilterWildcard (QString)));
+  setFocusProxy (_filter->lineEdit ());
+
+  // Init state of the filter
+  QSettings *settings = resource_manager::get_settings ();
+  _filter->addItems (settings->value ("history_dock_widget/mru_list").toStringList ());
+
+  bool filter_state =
+            settings->value ("history_dock_widget/filter_active", false).toBool ();
+  _filter_checkbox->setChecked (filter_state);
+  filter_activate (filter_state);
+
+  // Connect signals and slots
+  connect (_filter, SIGNAL (editTextChanged (const QString&)),
+           &_sort_filter_proxy_model, SLOT (setFilterWildcard (const QString&)));
+  connect (_filter_checkbox, SIGNAL (toggled (bool)),
+           this, SLOT (filter_activate (bool)));
+  connect (_filter->lineEdit (), SIGNAL (editingFinished ()),
+           this, SLOT (update_filter_history ()));
 
   connect (_history_list_view, SIGNAL (doubleClicked (QModelIndex)),
            this, SLOT (handle_double_click (QModelIndex)));
 
-  setFocusProxy (_filter_line_edit);
-
   // shrink max. displayed entry size to desktop width
   QSize screen = QDesktopWidget ().screenGeometry ().size ();
   int w = screen.width ();
@@ -103,6 +136,46 @@
   _history_list_view->setTextElideMode (Qt::ElideRight);
 }
 
+history_dock_widget::~history_dock_widget ()
+{
+  QSettings *settings = resource_manager::get_settings ();
+
+  settings->setValue ("history_dock_widget/filter_active",
+                      _filter_checkbox->isChecked ());
+
+  QStringList mru;
+  for (int i = 0; i < _filter->count (); i++)
+    mru.append (_filter->itemText (i));
+  settings->setValue ("history_dock_widget/mru_list", mru);
+
+  settings->sync ();
+}
+
+void
+history_dock_widget::filter_activate (bool state)
+{
+  _filter->setEnabled (state);
+  _sort_filter_proxy_model.setDynamicSortFilter (state);
+
+  if (state)
+    _sort_filter_proxy_model.setFilterWildcard (_filter->currentText ());
+  else
+    _sort_filter_proxy_model.setFilterWildcard (QString ());
+}
+
+void
+history_dock_widget::update_filter_history ()
+{
+  QString text = _filter->currentText ();   // get current text
+  int index = _filter->findText (text);     // and its actual index
+
+  if (index > -1)
+    _filter->removeItem (index);    // remove if already existing
+
+  _filter->insertItem (0, text);    // (re)insert at beginning
+  _filter->setCurrentIndex (0);
+}
+
 void history_dock_widget::ctxMenu (const QPoint &xpos)
 {
   QMenu menu (this);
@@ -211,31 +284,31 @@
 {
   if (_history_list_view->hasFocus ())
     handle_contextmenu_copy (true);
-  if (_filter_line_edit->hasFocus () && _filter_line_edit->hasSelectedText ())
+  if (_filter->lineEdit ()->hasFocus () && _filter->lineEdit ()->hasSelectedText ())
     {
       QClipboard *clipboard = QApplication::clipboard ();
-      clipboard->setText (_filter_line_edit->selectedText ());
+      clipboard->setText ( _filter->lineEdit ()->selectedText ());
     }
 }
 
 void
 history_dock_widget::pasteClipboard ()
 {
-  if (_filter_line_edit->hasFocus ())
+  if (_filter->lineEdit ()->hasFocus ())
     {
       QClipboard *clipboard = QApplication::clipboard ();
       QString str =  clipboard->text ();
       if (str.length () > 0)
-        _filter_line_edit->insert (str);
+        _filter->lineEdit ()->insert (str);
     }
 }
 
 void
 history_dock_widget::selectAll ()
 {
-  if (_filter_line_edit->hasFocus ())
+  if (_filter->lineEdit ()->hasFocus ())
     {
-        _filter_line_edit->selectAll ();
+        _filter->lineEdit ()->selectAll ();
     }
   if (_history_list_view->hasFocus ())
     {
--- a/libgui/src/history-dock-widget.h	Mon Jan 12 13:44:24 2015 +0100
+++ b/libgui/src/history-dock-widget.h	Mon Jan 12 09:17:35 2015 -0800
@@ -27,6 +27,9 @@
 #include <QListView>
 #include <QSortFilterProxyModel>
 #include <QStringListModel>
+#include <QComboBox>
+#include <QCheckBox>
+
 #include "octave-dock-widget.h"
 
 class history_dock_widget : public octave_dock_widget
@@ -36,6 +39,7 @@
 public:
 
   history_dock_widget (QWidget *parent = 0);
+  ~history_dock_widget ();
 
 public slots:
 
@@ -56,6 +60,9 @@
 
 private slots:
 
+  void update_filter_history ();
+  void filter_activate (bool enable);
+
   void handle_double_click (QModelIndex modelIndex);
   void handle_contextmenu_copy (bool flag);
   void handle_contextmenu_evaluate (bool flag);
@@ -70,11 +77,14 @@
 
   void construct ();
   QListView *_history_list_view;
-  QLineEdit *_filter_line_edit;
   QSortFilterProxyModel _sort_filter_proxy_model;
 
   /** Stores the current history_model. */
   QStringListModel *_history_model;
+
+  QCheckBox *_filter_checkbox;
+  QComboBox *_filter;
+  enum { MaxFilterHistory = 10 };
 };
 
 #endif // HISTORYDOCKWIDGET_H
--- a/libgui/src/workspace-view.cc	Mon Jan 12 13:44:24 2015 +0100
+++ b/libgui/src/workspace-view.cc	Mon Jan 12 09:17:35 2015 -0800
@@ -51,7 +51,7 @@
   setStatusTip (tr ("View the variables in the active workspace."));
 
   _filter = new QComboBox (this);
-  _filter->setToolTip (tr ("Enter the path or filename"));
+  _filter->setToolTip (tr ("Enter text to filter the workspace"));
   _filter->setEditable (true);
   _filter->setMaxCount (MaxFilterHistory);
   _filter->setInsertPolicy (QComboBox::NoInsert);
@@ -88,10 +88,6 @@
   // Set the empty widget to have our layout.
   widget ()->setLayout (vbox_layout);
 
-  // Filter model
-  _filter_model = new QSortFilterProxyModel ();
-  _filter_model->setFilterKeyColumn(0);
-
   // Initialize collapse/expand state of the workspace subcategories.
 
   QSettings *settings = resource_manager::get_settings ();
@@ -144,8 +140,10 @@
 
 void workspace_view::setModel (workspace_model *model)
 {
-  _filter_model->setSourceModel (model);
-  view->setModel (_filter_model);
+  _filter_model.setSourceModel (model);
+  _filter_model.setFilterKeyColumn(0);
+
+  view->setModel (&_filter_model);
   _model = model;
 }
 
@@ -159,7 +157,7 @@
 void
 workspace_view::filter_update (const QString& expression)
 {
-  _filter_model->setFilterRegExp (QRegExp (expression, Qt::CaseSensitive));
+  _filter_model.setFilterWildcard (expression);
   handle_model_changed ();
 }
 
@@ -167,7 +165,7 @@
 workspace_view::filter_activate (bool state)
 {
   _filter->setEnabled (state);
-  _filter_model->setDynamicSortFilter (state);
+  _filter_model.setDynamicSortFilter (state);
 
   if (state)
     filter_update (_filter->currentText ());
@@ -178,9 +176,14 @@
 void
 workspace_view::update_filter_history ()
 {
-  QString text = _filter->currentText ();
-  if (! text.isEmpty () && _filter->findText (text) == -1)
-    _filter->insertItem (0, _filter->currentText ());
+  QString text = _filter->currentText ();   // get current text
+  int index = _filter->findText (text);     // and its actual index
+
+  if (index > -1)
+    _filter->removeItem (index);    // remove if already existing
+
+  _filter->insertItem (0, text);    // (re)insert at beginning
+  _filter->setCurrentIndex (0);
 }
 
 QString
@@ -337,7 +340,7 @@
   // 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 = _filter_model->rowCount ();
+  int new_row_count = _filter_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;
--- a/libgui/src/workspace-view.h	Mon Jan 12 13:44:24 2015 +0100
+++ b/libgui/src/workspace-view.h	Mon Jan 12 09:17:35 2015 -0800
@@ -89,7 +89,7 @@
   int view_previous_row_count;
   workspace_model *_model;
 
-  QSortFilterProxyModel *_filter_model;
+  QSortFilterProxyModel _filter_model;
   QCheckBox *_filter_checkbox;
   QComboBox *_filter;
   enum { MaxFilterHistory = 10 };
--- a/scripts/plot/util/private/__print_parse_opts__.m	Mon Jan 12 13:44:24 2015 +0100
+++ b/scripts/plot/util/private/__print_parse_opts__.m	Mon Jan 12 09:17:35 2015 -0800
@@ -43,7 +43,7 @@
   arg_st.ghostscript.debug = false;
   arg_st.ghostscript.device = "";
   arg_st.ghostscript.epscrop = true;
-  arg_st.ghostscript.level = [];
+  arg_st.ghostscript.level = 2;
   arg_st.ghostscript.output = "";
   arg_st.ghostscript.papersize = "";
   arg_st.ghostscript.pageoffset = [];
@@ -298,13 +298,6 @@
     arg_st.devopt = aliases.(arg_st.devopt);
   endif
 
-  ## FIXME: eps2 & epsc2 needs to be handled
-  if (strcmp (arg_st.devopt, "pswrite"))
-    arg_st.ghostscript.level = 1;
-  elseif (strcmp (arg_st.devopt, "ps2write"))
-    arg_st.ghostscript.level = 2;
-  endif
-
   if ((any (strcmp (arg_st.devopt, gs_device_list))
        && ! arg_st.formatted_for_printing)
       || any (strcmp (arg_st.devopt, {"pswrite", "ps2write", "pdfwrite"})))
@@ -621,15 +614,15 @@
 endfunction
 
 function device_list = gs_device_list ();
-  ## Graphics formats/languages, not priners.
+  ## Graphics formats/languages, not printers.
   device_list = {"bmp16"; "bmp16m"; "bmp256"; "bmp32b"; "bmpgray"; ...
                  "epswrite"; "jpeg"; "jpegcymk"; "jpeggray"; "pbm"; ...
                  "pbmraw"; "pcx16"; "pcx24b"; "pcx256"; "pcx2up"; ...
                  "pcxcmyk"; "pcxgray"; "pcxmono"; "pdfwrite"; "pgm"; ...
                  "pgmraw"; "pgnm"; "pgnmraw"; "png16"; "png16m"; ...
                  "png256"; "png48"; "pngalpha"; "pnggray"; "pngmono"; ...
-                 "pnm"; "pnmraw"; "ppm"; "ppmraw"; "ps2write"; ...
-                 "pswrite"; "tiff12nc"; "tiff24nc"; "tiff32nc"; ...
+                 "pnm"; "pnmraw"; "ppm"; "ppmraw"; "pswrite"; ...
+                 "ps2write"; "tiff12nc"; "tiff24nc"; "tiff32nc"; ...
                  "tiffcrle"; "tiffg3"; "tiffg32d"; "tiffg4"; ...
                  "tiffgray"; "tifflzw"; "tiffpack"; "tiffsep"};
 endfunction
@@ -640,14 +633,14 @@
   ##
   ## eps, epsc, eps2, epsc2 are not included here because those are
   ## are generated by the graphics toolkit.
-  aliases.bmp = "bmp32b";
-  aliases.pdf = "pdfwrite";
-  aliases.png = "png16m";
-  aliases.ps = "pswrite";
-  aliases.ps2 = "ps2write";
-  aliases.psc = "pswrite";
-  aliases.psc2 = "ps2write";
-  aliases.tiff = "tiff24nc";
+  aliases.bmp   = "bmp32b";
+  aliases.pdf   = "pdfwrite";
+  aliases.png   = "png16m";
+  aliases.ps    = "ps2write";
+  aliases.ps2   = "ps2write";
+  aliases.psc   = "ps2write";
+  aliases.psc2  = "ps2write";
+  aliases.tiff  = "tiff24nc";
   aliases.tiffn = "tiff24nc";
 endfunction