exporting patch:
# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1523324127 18000
#      Mon Apr 09 20:35:27 2018 -0500
# Branch stable
# Node ID 7957d1368c57a3ee326b4839c02003c26ff7903e
# Parent  df4e64464f380521414cc96036a6f98f54adb379
Change virtual focus() to use of Qt's virtual focusInEvent() (bug #53443)

* file-editor.cc (file_editor::focus): Rename as focusInEvent with proper
  input variable.  Call the base class focusInEvent() with the input variable
  instead of base class focus().
  (file_editor::set_focus): Rather than call base class focus(), simply call
  QWidget setFocus().
  (file_editor::request_new_file): Ditto.
  (file_editor::handle_tab_remove_request): Ditto.
  (file_editor::active_tab_changed): Ditto.
  (file_editor::handle_visibility): Ditto.
  (file_editor::request_open_file): Ditto.

* file-editor.h (file_editor::focus): Removed.
  (file_editor::focusInEvent): Added.  Protected virtual override of the base
  class event handler.

* main-window.cc (main_window::focus_command_window): Call the command
  window's setFocus() routine rather than its focus() routine.
  (main_window::construct_window_menu_item): Change the connection from action
  signal triggered() from widget's focus() to its setFocus() slot.
  (main_window::construct_documentation_menu): Connect menu action signal to
  m_doc_browser_window's setFocus() slot rather than focus() slot.

* octave-dock-widget.cc (octave_dock_widget::focusInEvent): Added.  New virtual
  override of base class routine that will do the same steps that focus()
  routine used to do.
  (octave_dock_widget::make_widget): Replaced call to focus() with call to
  setFocus().
  (octave_dock_widget::change_floating): Ditto.
  (octave_dock_widget::set_focus_predecessor): Call m_predecessor_widget's
  setFocus() routine rather than its focus() routine.

* octave-dock-widget.h (octave_dock_widget::focusInEvent): Declaration of
  protected virtual override of base class function.
  (octave_dock_widget::focus): Removed.
  (octave_dock_widget::handle_visibility): Change call to focus() to call to
  setFocus().

* octave-gui.cc (gui_application::execute): Removed redundant call to main
  window's focus_command_window() routine.

* terminal-dock-widget.cc (terminal_dock_widget::terminal_dock_widget): Remove
  the setFocusProxy() that was preventing the focusInEvent() from occurring.
  (terminal_dock_widget::focus): Rename this routine focusInEvent() with the
  proper input to be a virtual override.  Call the base class's virtual
  focusInEvent() rather than focus().

* terminal-dock-widget.h (terminal_dock_widget::focus): Removed.
  (terminal_dock_widget::focusInEvent): Added.  Declaration of virtual
  override of base class event handler.

* variable-editor.cc (variable_editor::edit_variable): Change the call to
  parent widget's show() routine to parent widget's setFocus() routine.  Drop
  the calls to tab_to_front().
  (variable_editor::tab_to_front): Removed.

* variable-editor.h (variable_editor::tab_to_front): Removed.

diff --git a/libgui/src/m-editor/file-editor.cc b/libgui/src/m-editor/file-editor.cc
--- a/libgui/src/m-editor/file-editor.cc
+++ b/libgui/src/m-editor/file-editor.cc
@@ -295,12 +295,12 @@ namespace octave
       request_open_file (s_data.at (n).file_name, s_data.at (n).encoding);
   }
 
-  void file_editor::focus (void)
+  void file_editor::focusInEvent (QFocusEvent *ev)
   {
     if (m_no_focus)
       return;  // No focus for the editor if external open/close request
 
-    octave_dock_widget::focus ();
+    octave_dock_widget::focusInEvent (ev);
 
     // set focus to current tab
     QWidget *fileEditorTab = m_tab_widget->currentWidget ();
@@ -310,7 +310,7 @@ namespace octave
 
   void file_editor::set_focus (QWidget *fet)
   {
-    octave_dock_widget::focus ();
+    setFocus ();
 
     // set focus to desired tab
     if (fet)
@@ -424,7 +424,7 @@ namespace octave
       {
         add_file_editor_tab (fileEditorTab, "");  // new tab with empty title
         fileEditorTab->new_file (commands);       // title is updated here
-        focus ();                                 // focus editor and new tab
+        setFocus ();                              // focus editor and new tab
       }
   }
 
@@ -762,7 +762,7 @@ namespace octave
       }
     check_actions ();
 
-    focus ();     // focus stays in editor when tab is closed
+    setFocus ();    // focus stays in editor when tab is closed
 
   }
 
@@ -778,7 +778,7 @@ namespace octave
   void file_editor::active_tab_changed (int index)
   {
     emit fetab_change_request (m_tab_widget->widget (index));
-    focus ();
+    setFocus ();
   }
 
   void file_editor::handle_editor_state_changed (bool copy_available,
@@ -1135,7 +1135,7 @@ namespace octave
     empty_script (false, visible);
 
     if (visible && ! isFloating ())
-      focus ();
+      setFocus ();
 
   }
 
@@ -1214,7 +1214,7 @@ namespace octave
             if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ()))
               {
                 emit fetab_set_focus (tab);
-                focus ();
+                setFocus ();
               }
           }
         else
@@ -1341,7 +1341,7 @@ namespace octave
             if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ()))
               {
                 // really show editor and the current editor tab
-                focus ();
+                setFocus ();
                 emit file_loaded_signal ();
               }
           }
diff --git a/libgui/src/m-editor/file-editor.h b/libgui/src/m-editor/file-editor.h
--- a/libgui/src/m-editor/file-editor.h
+++ b/libgui/src/m-editor/file-editor.h
@@ -177,7 +177,6 @@ namespace octave
 
   public slots:
 
-    void focus (void);
     void set_focus (QWidget *fet);
     void enable_menu_shortcuts (bool);
     bool check_closing (void);
@@ -308,6 +307,7 @@ namespace octave
     void closeEvent (QCloseEvent *event);
     void dragEnterEvent (QDragEnterEvent *event);
     void dropEvent (QDropEvent *event);
+    void focusInEvent (QFocusEvent *ev);
 
   private:
 
diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -284,7 +284,7 @@ namespace octave
 
   void main_window::focus_command_window (void)
   {
-    m_command_window->focus ();
+    m_command_window->setFocus ();
   }
 
   // catch focus changes and determine the active dock widget
@@ -2312,7 +2312,7 @@ namespace octave
         else
           {
             // action for focus of dock widget
-            connect (action, SIGNAL (triggered (void)), widget, SLOT (focus (void)));
+            connect (action, SIGNAL (triggered (void)), widget, SLOT (setFocus (void)));
           }
       }
 
@@ -2404,7 +2404,7 @@ namespace octave
     QMenu *doc_menu = p->addMenu (tr ("Documentation"));
 
     m_ondisk_doc_action = add_action (doc_menu, QIcon (),
-                                      tr ("On Disk"), SLOT (focus ()), m_doc_browser_window);
+                                      tr ("On Disk"), SLOT (setFocus ()), m_doc_browser_window);
 
     m_online_doc_action = add_action (doc_menu, QIcon (),
                                       tr ("Online"), SLOT (open_online_documentation_page ()));
diff --git a/libgui/src/octave-dock-widget.cc b/libgui/src/octave-dock-widget.cc
--- a/libgui/src/octave-dock-widget.cc
+++ b/libgui/src/octave-dock-widget.cc
@@ -210,7 +210,7 @@ namespace octave
         // recover old window states, hide and re-show new added widget
         m_parent->restoreState (settings->value ("MainWindow/windowState").toByteArray ());
         setFloating (false);
-        focus ();
+        setFocus ();
         QApplication::setActiveWindow (this);
         m_title_widget->setToolTip ("");
       }
@@ -251,6 +251,17 @@ namespace octave
   }
 
   void
+  octave_dock_widget::focusInEvent (QFocusEvent *ev)
+  {
+    if (! isVisible ())
+      setVisible (true);
+
+    activateWindow ();
+    raise ();
+    label_dock_widget::focusInEvent (ev);
+  }
+
+  void
   octave_dock_widget::handle_settings (const QSettings *settings)
   {
     m_custom_style
@@ -362,7 +373,7 @@ namespace octave
     else
       {
         make_window ();
-        focus ();
+        setFocus ();
       }
   }
 
@@ -452,7 +463,7 @@ namespace octave
   octave_dock_widget::set_focus_predecessor (void)
   {
     if (m_predecessor_widget)    // only != 0 if widget was tabbed
-      m_predecessor_widget->focus ();
+      m_predecessor_widget->setFocus ();
 
     m_predecessor_widget = nullptr;
     // FIXME: Until cset bda0c5b38bda, the wrong keys "Dockwidget/..." were used
diff --git a/libgui/src/octave-dock-widget.h b/libgui/src/octave-dock-widget.h
--- a/libgui/src/octave-dock-widget.h
+++ b/libgui/src/octave-dock-widget.h
@@ -97,22 +97,14 @@ namespace octave
 
     QWidget * focusWidget (void);
 
+    void focusInEvent (QFocusEvent *ev);
+
   public slots:
 
-    virtual void focus (void)
-    {
-      if (! isVisible ())
-        setVisible (true);
-
-      setFocus ();
-      activateWindow ();
-      raise ();
-    }
-
     virtual void handle_visibility (bool visible)
     {
       if (visible && ! isFloating ())
-        focus ();
+        setFocus ();
     }
 
     virtual void notice_settings (const QSettings*) { }
diff --git a/libgui/src/octave-gui.cc b/libgui/src/octave-gui.cc
--- a/libgui/src/octave-gui.cc
+++ b/libgui/src/octave-gui.cc
@@ -192,8 +192,6 @@ namespace octave
 
         w.connect_visibility_changed ();
 
-        w.focus_command_window ();
-
         gui_running (true);
       }
     else
diff --git a/libgui/src/terminal-dock-widget.cc b/libgui/src/terminal-dock-widget.cc
--- a/libgui/src/terminal-dock-widget.cc
+++ b/libgui/src/terminal-dock-widget.cc
@@ -43,7 +43,6 @@ namespace octave
     set_title (tr ("Command Window"));
 
     setWidget (m_terminal);
-    setFocusProxy (m_terminal);
 
     connect (m_terminal, SIGNAL (interrupt_signal (void)),
              this, SLOT (terminal_interrupt (void)));
@@ -90,9 +89,9 @@ namespace octave
     return w->hasFocus ();
   }
 
-  void terminal_dock_widget::focus (void)
+  void terminal_dock_widget::focusInEvent (QFocusEvent *ev)
   {
-    octave_dock_widget::focus ();
+    octave_dock_widget::focusInEvent (ev);
 
     QWidget *w = widget ();
 
diff --git a/libgui/src/terminal-dock-widget.h b/libgui/src/terminal-dock-widget.h
--- a/libgui/src/terminal-dock-widget.h
+++ b/libgui/src/terminal-dock-widget.h
@@ -43,12 +43,14 @@ namespace octave
 
     bool has_focus (void) const;
 
-    void focus (void);
-
   signals:
 
     void interrupt_signal (void);
 
+  protected:
+
+    void focusInEvent (QFocusEvent *ev);
+
   protected slots:
 
     void terminal_interrupt (void);
diff --git a/libgui/src/variable-editor.cc b/libgui/src/variable-editor.cc
--- a/libgui/src/variable-editor.cc
+++ b/libgui/src/variable-editor.cc
@@ -1080,11 +1080,10 @@ namespace octave
           }
 
         // Put existing variable in focus and raise
-        m_main->parentWidget ()->show ();
+        m_main->parentWidget ()->setFocus ();
         existing_qdw->show ();
         existing_qdw->raise ();
         existing_qdw->activateWindow ();
-        tab_to_front ();
         existing_qdw->setFocus ();
 
         return;
@@ -1183,36 +1182,14 @@ namespace octave
     if (viewlist.size () == 1)
       m_tool_bar->setEnabled (true);
 
-    m_main->parentWidget ()->show ();
+    m_main->parentWidget ()->setFocus ();
     page->show ();
     page->raise ();
     page->activateWindow ();
-    tab_to_front ();
     page->setFocus ();
   }
 
   void
-  variable_editor::tab_to_front (void)
-  {
-    if (parent () != nullptr)
-      {
-        QList<QTabBar *> barlist = main_win ()->findChildren<QTabBar *> ();
-
-        foreach (QTabBar *tbar, barlist)
-          {
-            for (int i=0; i < tbar->count (); i++)
-              {
-                  if ((QWidget *) tbar->tabData (i).toULongLong () == this)
-                  {
-                    tbar->setCurrentIndex (i);
-                    return;
-                  }
-              }
-          }
-      }
-  }
-
-  void
   variable_editor::refresh (void)
   {
     emit refresh_signal ();
diff --git a/libgui/src/variable-editor.h b/libgui/src/variable-editor.h
--- a/libgui/src/variable-editor.h
+++ b/libgui/src/variable-editor.h
@@ -270,8 +270,6 @@ namespace octave
 
     static QStringList color_names (void);
 
-    void tab_to_front (void);
-
   public slots:
 
     void callUpdate (const QModelIndex&, const QModelIndex&);
