changeset 25976:a7cc5b7a3d22

provide shortcuts for zooming into the doc browser (bug #54877) * documentation.cc (documentation::documentation): initialize new shortcuts with values for editor zoom shortcuts and connect them to the related slots of the documentation_browser; (documentation_browser::documentation_browser): initialize the new class variable for storing the current zoom level (documentation_browser::zoom_in): new slot for zooming in; (documentation_browser::zoom_out): new slot for zooming out; (documentation_browser::zoom_normal): new slot for resetting the zoom level * documentation.h: updated some comments; (class documentation_browser): new slots for zooming in, out and resetting, new constants for min and max zoom level, new class variable for storing the current zoom level; (class documentation): new shortcuts for zooming in, out and resetting * shortcut-manager.cc (do_fill_treewidget): new section for zooming in editor and doc browser, add zoom shortcuts to this section
author Torsten <mttl@mailbox.org>
date Mon, 29 Oct 2018 21:25:13 +0100
parents 9fdc4c435a15
children 42589c359daf
files libgui/src/documentation.cc libgui/src/documentation.h libgui/src/shortcut-manager.cc
diffstat 3 files changed, 79 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/documentation.cc	Mon Oct 29 10:09:32 2018 -0700
+++ b/libgui/src/documentation.cc	Mon Oct 29 21:25:13 2018 +0100
@@ -57,7 +57,10 @@
     : QSplitter (Qt::Horizontal, p),
       m_show_shortcut (new QShortcut (p)),
       m_findnext_shortcut (new QShortcut (p)),
-      m_findprev_shortcut (new QShortcut (p))
+      m_findprev_shortcut (new QShortcut (p)),
+      m_zoom_in_shortcut (new QShortcut (p)),
+      m_zoom_out_shortcut (new QShortcut (p)),
+      m_zoom_normal_shortcut (new QShortcut (p))
   {
     // Get original collection
     QString collection = getenv ("OCTAVE_QTHELP_COLLECTION");
@@ -163,6 +166,17 @@
     find_footer->hide ();
     m_search_anchor_position = 0;
 
+    // Zoom Shortcuts
+    m_zoom_in_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
+    connect (m_zoom_in_shortcut, SIGNAL (activated (void)),
+             m_doc_browser, SLOT (zoom_in (void)));
+    m_zoom_out_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
+    connect (m_zoom_out_shortcut, SIGNAL (activated (void)),
+             m_doc_browser, SLOT (zoom_out (void)));
+    m_zoom_normal_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
+    connect (m_zoom_normal_shortcut, SIGNAL (activated (void)),
+             m_doc_browser, SLOT (zoom_normal (void)));
+
     // Layout contents, index and search
     QTabWidget *navi = new QTabWidget (this);
     navi->setTabsClosable (false);
@@ -372,6 +386,9 @@
     shortcut_manager::shortcut (m_show_shortcut, "editor_edit:find_replace");
     shortcut_manager::shortcut (m_findnext_shortcut, "editor_edit:find_next");
     shortcut_manager::shortcut (m_findprev_shortcut, "editor_edit:find_previous");
+    shortcut_manager::shortcut (m_zoom_in_shortcut, "editor_view:zoom_in");
+    shortcut_manager::shortcut (m_zoom_out_shortcut, "editor_view:zoom_out");
+    shortcut_manager::shortcut (m_zoom_normal_shortcut, "editor_view:zoom_normal");
   }
 
   void documentation::copyClipboard (void)
@@ -551,7 +568,7 @@
 
   // The documentation browser
   documentation_browser::documentation_browser (QHelpEngine *he, QWidget *p)
-    : QTextBrowser (p), m_help_engine (he)
+    : QTextBrowser (p), m_help_engine (he), m_zoom_level (0)
   { }
 
   documentation_browser::~documentation_browser (void)
@@ -573,4 +590,28 @@
     else
       return QTextBrowser::loadResource(type, url);
   }
+
+  void documentation_browser::zoom_in (void)
+  {
+    if (m_zoom_level < max_zoom_level)
+      {
+        zoomIn ();
+        m_zoom_level++;
+      }
+  }
+
+  void documentation_browser::zoom_out (void)
+  {
+    if (m_zoom_level > min_zoom_level)
+      {
+        zoomOut ();
+        m_zoom_level--;
+      }
+  }
+
+  void documentation_browser::zoom_normal (void)
+  {
+    zoomIn (- m_zoom_level);
+    m_zoom_level = 0;
+  }
 }
--- a/libgui/src/documentation.h	Mon Oct 29 10:09:32 2018 -0700
+++ b/libgui/src/documentation.h	Mon Oct 29 21:25:13 2018 +0100
@@ -33,7 +33,8 @@
 
 namespace octave
 {
-  // The documentation browser
+  //! Documentation browser derived from Textbrowser
+
   class documentation_browser : public QTextBrowser
   {
     Q_OBJECT
@@ -51,13 +52,33 @@
                                const QString& keyword = QString ());
     void notice_settings (const QSettings *settings);
 
+    //! Zooming in and out while taking care of the zoom level
+    //!@{
+    void zoom_in (void);
+    void zoom_out (void);
+    void zoom_normal (void);
+    //!@}
+
   private:
 
     QHelpEngine *m_help_engine;
+
+    //! Store the current zoom level
+    int m_zoom_level;
+
+    //! Minimal and maximal zoom level avoiding calling
+    //! zoom_in and zoom_out without actually zooming but
+    //! with changing the stored zoom level
+    enum
+    {
+      min_zoom_level = -5,
+      max_zoom_level = 10
+    };
   };
 
 
-  // The documentaiton main class (splitter)
+  //! The documentaiton main class derived from QSplitter
+
   class documentation : public QSplitter
   {
     Q_OBJECT
@@ -105,9 +126,13 @@
     int m_search_anchor_position;
     QComboBox *m_filter;
     QString m_collection;
+
     QShortcut *m_show_shortcut;
     QShortcut *m_findnext_shortcut;
     QShortcut *m_findprev_shortcut;
+    QShortcut *m_zoom_in_shortcut;
+    QShortcut *m_zoom_out_shortcut;
+    QShortcut *m_zoom_normal_shortcut;
   };
 }
 
--- a/libgui/src/shortcut-manager.cc	Mon Oct 29 10:09:32 2018 -0700
+++ b/libgui/src/shortcut-manager.cc	Mon Oct 29 21:25:13 2018 +0100
@@ -552,6 +552,8 @@
     main_tabs->setText (0, tr ("Tab Handling in Dock Widgets"));
     QTreeWidgetItem *main_find = new QTreeWidgetItem (main);
     main_find->setText (0, tr ("Find & Replace in Dock Widgets"));
+    QTreeWidgetItem *main_zoom = new QTreeWidgetItem (main);
+    main_zoom->setText (0, tr ("Zooming in Editor and Documentation"));
 
     m_level_hash["main_file"]   = main_file;
     m_level_hash["main_edit"]   = main_edit;
@@ -562,6 +564,7 @@
     m_level_hash["main_tabs"]   = main_tabs;
     m_level_hash["editor_tabs"]   = main_tabs;
     m_level_hash["editor_find"]   = main_find;
+    m_level_hash["editor_zoom"]   = main_zoom;
 
     QTreeWidgetItem *editor = new QTreeWidgetItem (tree_view);
     editor->setText (0, tr ("Editor"));
@@ -609,6 +612,12 @@
             if (sc.m_settings_key.contains ("editor_edit:find"))
               section = main_find;
           }
+        if (section == editor_view)
+          {
+            // Zooming now in global zoom handling section
+            if (sc.m_settings_key.contains ("editor_view:zoom"))
+              section = main_zoom;
+          }
 
         QTreeWidgetItem *tree_item = new QTreeWidgetItem (section);