From 35be3a3b027012a062d4bcba2a533a6aaa017e2f Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Tue, 14 Jul 2009 13:20:26 +0200
Subject: [PATCH] customize context help. The three modes are:  - show
 side-by-side if possible  - always show side-by-side  - always show full help

The default is "show side-by-side if possible". It's currently considered
possible if the editor is at least 800 pixels wide.
---
 src/plugins/help/generalsettingspage.cpp |  7 +++
 src/plugins/help/generalsettingspage.ui  | 62 +++++++++++++++++++-----
 src/plugins/help/helpplugin.cpp          | 30 +++++++++++-
 3 files changed, 85 insertions(+), 14 deletions(-)

diff --git a/src/plugins/help/generalsettingspage.cpp b/src/plugins/help/generalsettingspage.cpp
index 61a93ba8518..fe2630088f6 100644
--- a/src/plugins/help/generalsettingspage.cpp
+++ b/src/plugins/help/generalsettingspage.cpp
@@ -110,6 +110,10 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
 
     int index = m_helpEngine->customValue(QLatin1String("StartOption"), 2).toInt();
     m_ui.helpStartComboBox->setCurrentIndex(index);
+
+    index = m_helpEngine->customValue(QLatin1String("ContextHelpOption"), 0).toInt();
+    m_ui.contextHelpComboBox->setCurrentIndex(index);
+
     
     connect(m_ui.currentPageButton, SIGNAL(clicked()), this, SLOT(setCurrentPage()));
     connect(m_ui.blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage()));
@@ -165,6 +169,9 @@ void GeneralSettingsPage::apply()
 
     int startOption = m_ui.helpStartComboBox->currentIndex();
     m_helpEngine->setCustomValue(QLatin1String("StartOption"), startOption);
+
+    int contextHelpOption = m_ui.contextHelpComboBox->currentIndex();
+    m_helpEngine->setCustomValue(QLatin1String("ContextHelpOption"), contextHelpOption);
 }
 
 void GeneralSettingsPage::finish()
diff --git a/src/plugins/help/generalsettingspage.ui b/src/plugins/help/generalsettingspage.ui
index 5d4b58a8c69..5987bbfdfaa 100644
--- a/src/plugins/help/generalsettingspage.ui
+++ b/src/plugins/help/generalsettingspage.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>447</width>
-    <height>300</height>
+    <width>593</width>
+    <height>371</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -140,9 +140,9 @@
      </property>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
-       <layout class="QHBoxLayout" name="horizontalLayout_5">
-        <item>
-         <widget class="QLabel" name="label_2">
+       <layout class="QGridLayout" name="gridLayout">
+        <item row="0" column="0">
+         <widget class="QLabel" name="label_3">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
             <horstretch>0</horstretch>
@@ -150,12 +150,12 @@
            </sizepolicy>
           </property>
           <property name="text">
-           <string>On help start:</string>
+           <string>On context help:</string>
           </property>
          </widget>
         </item>
-        <item>
-         <widget class="QComboBox" name="helpStartComboBox">
+        <item row="0" column="1">
+         <widget class="QComboBox" name="contextHelpComboBox">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
             <horstretch>0</horstretch>
@@ -164,22 +164,22 @@
           </property>
           <item>
            <property name="text">
-            <string>Show my home page</string>
+            <string>Show side-by-side if possible</string>
            </property>
           </item>
           <item>
            <property name="text">
-            <string>Show a blank page</string>
+            <string>Always show side-by-side</string>
            </property>
           </item>
           <item>
            <property name="text">
-            <string>Show my tabs from last session</string>
+            <string>Always start full help</string>
            </property>
           </item>
          </widget>
         </item>
-        <item>
+        <item row="0" column="2">
          <spacer name="horizontalSpacer_3">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
@@ -192,6 +192,44 @@
           </property>
          </spacer>
         </item>
+        <item row="1" column="0">
+         <widget class="QLabel" name="label_2">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="text">
+           <string>On help start:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="1">
+         <widget class="QComboBox" name="helpStartComboBox">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <item>
+           <property name="text">
+            <string>Show my home page</string>
+           </property>
+          </item>
+          <item>
+           <property name="text">
+            <string>Show a blank page</string>
+           </property>
+          </item>
+          <item>
+           <property name="text">
+            <string>Show my tabs from last session</string>
+           </property>
+          </item>
+         </widget>
+        </item>
        </layout>
       </item>
       <item>
diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp
index a110130675d..fb1f5cf1bb0 100644
--- a/src/plugins/help/helpplugin.cpp
+++ b/src/plugins/help/helpplugin.cpp
@@ -53,6 +53,7 @@
 #include <coreplugin/rightpane.h>
 #include <coreplugin/sidebar.h>
 #include <coreplugin/welcomemode.h>
+#include <coreplugin/editormanager/editormanager.h>
 
 #include <texteditor/texteditorconstants.h>
 
@@ -732,12 +733,35 @@ void HelpPlugin::activateContext()
     }
 
     HelpViewer *viewer = 0;
-    if (placeHolder && !Core::RightPaneWidget::instance()->hasFocus()) {
+
+
+
+    bool showSideBySide = false;
+
+    switch (m_helpEngine->customValue(QLatin1String("ContextHelpOption"), 0).toInt())
+    {
+    case 0: // side by side if possible
+        {
+            if (Core::IEditor *editor = Core::EditorManager::instance()->currentEditor()) {
+                if (editor->widget() && editor->widget()->isVisible() && editor->widget()->width() < 800 )
+                    break;
+            }
+        }
+        // fall through
+    case 1: // side by side
+        showSideBySide = true;
+        break;
+    default: // help mode
+        break;
+    }
+
+    if (placeHolder && showSideBySide && !Core::RightPaneWidget::instance()->hasFocus()) {
         Core::RightPaneWidget::instance()->setShown(true);
         viewer = m_helpViewerForSideBar;
     } else {
+        if (!m_centralWidget->currentHelpViewer())
+            activateHelpMode();
         viewer = m_centralWidget->currentHelpViewer();
-        activateHelpMode();
     }
 
     if (viewer) {
@@ -753,6 +777,8 @@ void HelpPlugin::activateContext()
                 viewer->setSource(source);
             viewer->setFocus();
         }
+        if (viewer != m_helpViewerForSideBar)
+            activateHelpMode();
     }
 }
 
-- 
GitLab