aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2019-09-23 16:42:57 +0200
committerEike Ziller <eike.ziller@qt.io>2019-09-24 12:57:56 +0000
commit3b2209b870df9b4820cb15355c01dfb26da00d8b (patch)
tree2be15ff0f135c0016f1beb13df64b12f9edd753c
parent4f19046d7556f596f5fc4db073ff7c0f9a54bbfb (diff)
Help: Get rid of special CentralWidget class for help mode viewer
Change-Id: Id733eb0449cdaed5901e4144089c8adaaf07d7a9 Reviewed-by: hjk <hjk@qt.io>
-rw-r--r--src/plugins/help/CMakeLists.txt1
-rw-r--r--src/plugins/help/centralwidget.cpp69
-rw-r--r--src/plugins/help/centralwidget.h47
-rw-r--r--src/plugins/help/generalsettingspage.cpp13
-rw-r--r--src/plugins/help/help.pro2
-rw-r--r--src/plugins/help/help.qbs1
-rw-r--r--src/plugins/help/helpfindsupport.h2
-rw-r--r--src/plugins/help/helpindexfilter.cpp1
-rw-r--r--src/plugins/help/helpplugin.cpp49
-rw-r--r--src/plugins/help/helpplugin.h2
-rw-r--r--src/plugins/help/helpwidget.cpp36
-rw-r--r--src/plugins/help/helpwidget.h3
-rw-r--r--src/plugins/help/litehtmlhelpviewer.cpp1
-rw-r--r--src/plugins/help/litehtmlhelpviewer.h1
-rw-r--r--src/plugins/help/openpagesswitcher.cpp1
-rw-r--r--src/plugins/help/textbrowserhelpviewer.h1
-rw-r--r--src/shared/help/contentwindow.cpp1
-rw-r--r--src/shared/help/indexwindow.cpp1
18 files changed, 74 insertions, 158 deletions
diff --git a/src/plugins/help/CMakeLists.txt b/src/plugins/help/CMakeLists.txt
index 73122b15dc..ac70c823e2 100644
--- a/src/plugins/help/CMakeLists.txt
+++ b/src/plugins/help/CMakeLists.txt
@@ -4,7 +4,6 @@ add_qtc_plugin(Help
PLUGIN_DEPENDS Core ProjectExplorer
PLUGIN_RECOMMENDS TextEditor
SOURCES
- centralwidget.cpp centralwidget.h
docsettingspage.cpp docsettingspage.h docsettingspage.ui
filtersettingspage.cpp filtersettingspage.h filtersettingspage.ui
generalsettingspage.cpp generalsettingspage.h generalsettingspage.ui
diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp
deleted file mode 100644
index 26e65d16e5..0000000000
--- a/src/plugins/help/centralwidget.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-****************************************************************************/
-
-#include "centralwidget.h"
-
-#include "helpviewer.h"
-#include "localhelpmanager.h"
-
-#include <utils/qtcassert.h>
-
-using namespace Help::Internal;
-
-static CentralWidget *gStaticCentralWidget = nullptr;
-
-// -- CentralWidget
-
-CentralWidget::CentralWidget(const Core::Context &context, QWidget *parent)
- : HelpWidget(context, HelpWidget::ModeWidget, parent)
-{
- QTC_CHECK(!gStaticCentralWidget);
- gStaticCentralWidget = this;
-}
-
-CentralWidget::~CentralWidget()
-{
- // TODO: this shouldn't be done here
- QList<qreal> zoomFactors;
- QStringList currentPages;
- for (int i = 0; i < viewerCount(); ++i) {
- const HelpViewer * const viewer = viewerAt(i);
- const QUrl &source = viewer->source();
- if (source.isValid()) {
- currentPages.append(source.toString());
- zoomFactors.append(viewer->scale());
- }
- }
-
- LocalHelpManager::setLastShownPages(currentPages);
- LocalHelpManager::setLastShownPagesZoom(zoomFactors);
- LocalHelpManager::setLastSelectedTab(currentIndex());
-}
-
-CentralWidget *CentralWidget::instance()
-{
- Q_ASSERT(gStaticCentralWidget);
- return gStaticCentralWidget;
-}
diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h
deleted file mode 100644
index b6fc9d4e89..0000000000
--- a/src/plugins/help/centralwidget.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-****************************************************************************/
-
-#pragma once
-
-#include "helpwidget.h"
-
-#include <coreplugin/find/ifindsupport.h>
-
-namespace Help {
-namespace Internal {
-
-class CentralWidget : public HelpWidget
-{
- Q_OBJECT
-
-public:
- CentralWidget(const Core::Context &context, QWidget *parent = nullptr);
- ~CentralWidget() override;
-
- static CentralWidget *instance();
-};
-
-} // namespace Internal
-} // namespace Help
diff --git a/src/plugins/help/generalsettingspage.cpp b/src/plugins/help/generalsettingspage.cpp
index 93538efc09..4bebdfc9a9 100644
--- a/src/plugins/help/generalsettingspage.cpp
+++ b/src/plugins/help/generalsettingspage.cpp
@@ -25,9 +25,10 @@
#include "generalsettingspage.h"
-#include "centralwidget.h"
#include "helpconstants.h"
+#include "helpplugin.h"
#include "helpviewer.h"
+#include "helpwidget.h"
#include "localhelpmanager.h"
#include "xbelsupport.h"
@@ -105,10 +106,12 @@ QWidget *GeneralSettingsPage::widget()
this, &GeneralSettingsPage::setCurrentPage);
connect(m_ui->blankPageButton, &QPushButton::clicked,
this, &GeneralSettingsPage::setBlankPage);
- connect(m_ui->defaultPageButton, &QPushButton::clicked,
- this, &GeneralSettingsPage::setDefaultPage);
+ connect(m_ui->defaultPageButton,
+ &QPushButton::clicked,
+ this,
+ &GeneralSettingsPage::setDefaultPage);
- HelpViewer *viewer = CentralWidget::instance()->currentViewer();
+ HelpViewer *viewer = HelpPlugin::modeHelpWidget()->currentViewer();
if (!viewer)
m_ui->currentPageButton->setEnabled(false);
@@ -191,7 +194,7 @@ void GeneralSettingsPage::apply()
void GeneralSettingsPage::setCurrentPage()
{
- HelpViewer *viewer = CentralWidget::instance()->currentViewer();
+ HelpViewer *viewer = HelpPlugin::modeHelpWidget()->currentViewer();
if (viewer)
m_ui->homePageLineEdit->setText(viewer->source().toString());
}
diff --git a/src/plugins/help/help.pro b/src/plugins/help/help.pro
index 05f8da1552..f478611295 100644
--- a/src/plugins/help/help.pro
+++ b/src/plugins/help/help.pro
@@ -9,7 +9,6 @@ DEFINES += \
HELP_LIBRARY
HEADERS += \
- centralwidget.h \
docsettingspage.h \
filtersettingspage.h \
generalsettingspage.h \
@@ -32,7 +31,6 @@ HEADERS += \
helpwidget.h
SOURCES += \
- centralwidget.cpp \
docsettingspage.cpp \
filtersettingspage.cpp \
generalsettingspage.cpp \
diff --git a/src/plugins/help/help.qbs b/src/plugins/help/help.qbs
index 7503b442b4..d1458d8470 100644
--- a/src/plugins/help/help.qbs
+++ b/src/plugins/help/help.qbs
@@ -28,7 +28,6 @@ QtcPlugin {
Group {
name: "Sources"
files: [
- "centralwidget.cpp", "centralwidget.h",
"docsettingspage.cpp", "docsettingspage.h", "docsettingspage.ui",
"filtersettingspage.cpp", "filtersettingspage.h", "filtersettingspage.ui",
"generalsettingspage.cpp", "generalsettingspage.h", "generalsettingspage.ui",
diff --git a/src/plugins/help/helpfindsupport.h b/src/plugins/help/helpfindsupport.h
index daf63fe2a5..d2ce974b33 100644
--- a/src/plugins/help/helpfindsupport.h
+++ b/src/plugins/help/helpfindsupport.h
@@ -25,8 +25,6 @@
#pragma once
-#include "centralwidget.h"
-
#include <coreplugin/find/ifindsupport.h>
namespace Help {
diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp
index 42467934b7..c58c654320 100644
--- a/src/plugins/help/helpindexfilter.cpp
+++ b/src/plugins/help/helpindexfilter.cpp
@@ -25,7 +25,6 @@
#include "helpindexfilter.h"
-#include "centralwidget.h"
#include "helpicons.h"
#include "helpmanager.h"
#include "topicchooser.h"
diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp
index cc1357ca4b..fdbe8a154f 100644
--- a/src/plugins/help/helpplugin.cpp
+++ b/src/plugins/help/helpplugin.cpp
@@ -26,7 +26,6 @@
#include "helpplugin.h"
#include "bookmarkmanager.h"
-#include "centralwidget.h"
#include "docsettingspage.h"
#include "filtersettingspage.h"
#include "generalsettingspage.h"
@@ -37,11 +36,12 @@
#include "helpmanager.h"
#include "helpmode.h"
#include "helpviewer.h"
+#include "helpwidget.h"
#include "localhelpmanager.h"
#include "openpagesmanager.h"
#include "remotehelpfilter.h"
-#include "searchwidget.h"
#include "searchtaskhandler.h"
+#include "searchwidget.h"
#include "topicchooser.h"
#include <bookmarkmanager.h>
@@ -118,7 +118,6 @@ public:
void saveExternalWindowSettings();
void showLinksInCurrentViewer(const QMap<QString, QUrl> &links, const QString &key);
- void slotHideRightPane();
void updateSideBarSource(const QUrl &newUrl);
@@ -144,8 +143,10 @@ public:
void doSetupIfNeeded();
HelpMode m_mode;
- CentralWidget *m_centralWidget = nullptr;
+ HelpWidget *m_centralWidget = nullptr;
HelpWidget *m_rightPaneSideBarWidget = nullptr;
+ QPointer<HelpWidget> m_externalWindow;
+ QRect m_externalWindowState;
DocSettingsPage m_docSettingsPage;
FilterSettingsPage m_filterSettingsPage;
@@ -155,9 +156,6 @@ public:
bool m_setupNeeded = true;
LocalHelpManager m_localHelpManager;
- QPointer<HelpWidget> m_externalWindow;
- QRect m_externalWindowState;
-
HelpIndexFilter helpIndexFilter;
RemoteHelpFilter remoteHelpFilter;
};
@@ -209,16 +207,9 @@ HelpPluginPrivate::HelpPluginPrivate()
QCoreApplication::installTranslator(qhelptr);
}
- m_centralWidget = new CentralWidget(Context("Help.CentralHelpWidget"));
+ m_centralWidget = createHelpWidget(Context("Help.CentralHelpWidget"), HelpWidget::ModeWidget);
connect(m_centralWidget, &HelpWidget::sourceChanged,
this, &HelpPluginPrivate::updateSideBarSource);
- connect(m_centralWidget,
- &CentralWidget::closeButtonClicked,
- m_centralWidget->openPagesManager(),
- &OpenPagesManager::closeCurrentPage);
-
- connect(LocalHelpManager::instance(), &LocalHelpManager::returnOnCloseChanged,
- m_centralWidget, &CentralWidget::updateCloseButton);
connect(HelpManager::instance(), &HelpManager::helpRequested,
this, &HelpPluginPrivate::showHelpUrl);
connect(&m_searchTaskHandler, &SearchTaskHandler::search,
@@ -406,14 +397,19 @@ HelpWidget *HelpPluginPrivate::createHelpWidget(const Context &context, HelpWidg
connect(widget, &HelpWidget::openHelpMode, this, [this](const QUrl &url) {
showHelpUrl(url, Core::HelpManager::HelpModeAlways);
});
- connect(widget, &HelpWidget::closeButtonClicked, this, &HelpPluginPrivate::slotHideRightPane);
+ connect(LocalHelpManager::instance(),
+ &LocalHelpManager::returnOnCloseChanged,
+ widget,
+ &HelpWidget::updateCloseButton);
+ connect(widget, &HelpWidget::closeButtonClicked, this, [this, widget] {
+ if (widget->viewerCount() == 1 && LocalHelpManager::returnOnClose())
+ ModeManager::activateMode(Core::Constants::MODE_EDIT);
+ if (widget->widgetStyle() == HelpWidget::SideBarWidget)
+ RightPaneWidget::instance()->setShown(false);
+ });
connect(widget, &HelpWidget::aboutToClose,
this, &HelpPluginPrivate::saveExternalWindowSettings);
- // force setup, as we might have never switched to full help mode
- // thus the help engine might still run without collection file setup
- LocalHelpManager::setupGuiHelpEngine();
-
return widget;
}
@@ -470,6 +466,11 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
return viewer;
}
+HelpWidget *HelpPlugin::modeHelpWidget()
+{
+ return dd->m_centralWidget;
+}
+
void HelpPluginPrivate::showLinksInCurrentViewer(const QMap<QString, QUrl> &links, const QString &key)
{
if (links.size() < 1)
@@ -478,11 +479,6 @@ void HelpPluginPrivate::showLinksInCurrentViewer(const QMap<QString, QUrl> &link
widget->showLinks(links, key);
}
-void HelpPluginPrivate::slotHideRightPane()
-{
- RightPaneWidget::instance()->setShown(false);
-}
-
void HelpPluginPrivate::modeChanged(Core::Id mode, Core::Id old)
{
Q_UNUSED(old)
@@ -556,6 +552,9 @@ HelpViewer *HelpPluginPrivate::viewerForHelpViewerLocation(
actualLocation = canShowHelpSideBySide() ? Core::HelpManager::SideBySideAlways
: Core::HelpManager::HelpModeAlways;
+ // force setup, as we might have never switched to full help mode
+ // thus the help engine might still run without collection file setup
+ LocalHelpManager::setupGuiHelpEngine();
if (actualLocation == Core::HelpManager::ExternalHelpAlways)
return externalHelpViewer();
diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h
index dfba86fcc7..3ce8f77fb1 100644
--- a/src/plugins/help/helpplugin.h
+++ b/src/plugins/help/helpplugin.h
@@ -35,6 +35,7 @@ QT_END_NAMESPACE
namespace Help {
namespace Internal {
+class HelpWidget;
class HelpViewer;
class HelpPlugin : public ExtensionSystem::IPlugin
@@ -48,6 +49,7 @@ public:
static void showHelpUrl(const QUrl &url, Core::HelpManager::HelpViewerLocation location);
static HelpViewer *createHelpViewer(qreal zoom);
+ static HelpWidget *modeHelpWidget();
private:
bool initialize(const QStringList &arguments, QString *errorMessage) final;
diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp
index 973b0fe9ad..9766b2f3b4 100644
--- a/src/plugins/help/helpwidget.cpp
+++ b/src/plugins/help/helpwidget.cpp
@@ -332,6 +332,10 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
: Utils::Icons::CLOSE_SPLIT_RIGHT;
m_closeAction = new QAction(icon.icon(), QString(), toolBar);
connect(m_closeAction, &QAction::triggered, this, &HelpWidget::closeButtonClicked);
+ connect(m_closeAction, &QAction::triggered, this, [this] {
+ if (viewerCount() > 1)
+ closeCurrentPage();
+ });
button = new QToolButton;
button->setDefaultAction(m_closeAction);
layout->addWidget(button);
@@ -354,6 +358,7 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
HelpWidget::~HelpWidget()
{
+ saveState();
if (m_sideBar) {
m_sideBar->saveSettings(Core::ICore::settings(), sideBarSettingsKey());
Core::ActionManager::unregisterAction(m_contentsAction, Constants::HELP_CONTENTS);
@@ -388,6 +393,11 @@ QAbstractItemModel *HelpWidget::model()
return &m_model;
}
+HelpWidget::WidgetStyle HelpWidget::widgetStyle() const
+{
+ return m_style;
+}
+
void HelpWidget::addSideBar()
{
QMap<QString, Core::Command *> shortcutMap;
@@ -705,6 +715,32 @@ void HelpWidget::helpModeButtonClicked()
close();
}
+void HelpWidget::closeCurrentPage()
+{
+ removeViewerAt(currentIndex());
+}
+
+void HelpWidget::saveState() const
+{
+ // TODO generalize
+ if (m_style == ModeWidget) {
+ QList<qreal> zoomFactors;
+ QStringList currentPages;
+ for (int i = 0; i < viewerCount(); ++i) {
+ const HelpViewer *const viewer = viewerAt(i);
+ const QUrl &source = viewer->source();
+ if (source.isValid()) {
+ currentPages.append(source.toString());
+ zoomFactors.append(viewer->scale());
+ }
+ }
+
+ LocalHelpManager::setLastShownPages(currentPages);
+ LocalHelpManager::setLastShownPagesZoom(zoomFactors);
+ LocalHelpManager::setLastSelectedTab(currentIndex());
+ }
+}
+
void HelpWidget::updateCloseButton()
{
if (m_style == ModeWidget) {
diff --git a/src/plugins/help/helpwidget.h b/src/plugins/help/helpwidget.h
index afd0688e8a..603e333876 100644
--- a/src/plugins/help/helpwidget.h
+++ b/src/plugins/help/helpwidget.h
@@ -81,6 +81,7 @@ public:
~HelpWidget() override;
QAbstractItemModel *model();
+ WidgetStyle widgetStyle() const;
HelpViewer *currentViewer() const;
int currentIndex() const;
@@ -122,6 +123,8 @@ private:
void updateForwardMenu();
void updateWindowTitle();
void helpModeButtonClicked();
+ void closeCurrentPage();
+ void saveState() const;
void goHome();
void addBookmark();
diff --git a/src/plugins/help/litehtmlhelpviewer.cpp b/src/plugins/help/litehtmlhelpviewer.cpp
index de86df33a5..dcc2673895 100644
--- a/src/plugins/help/litehtmlhelpviewer.cpp
+++ b/src/plugins/help/litehtmlhelpviewer.cpp
@@ -36,6 +36,7 @@
#include <QScrollBar>
#include <QTimer>
#include <QVBoxLayout>
+#include <QWheelEvent>
#include <QDebug>
diff --git a/src/plugins/help/litehtmlhelpviewer.h b/src/plugins/help/litehtmlhelpviewer.h
index 7161abd7ce..0e35d79ddb 100644
--- a/src/plugins/help/litehtmlhelpviewer.h
+++ b/src/plugins/help/litehtmlhelpviewer.h
@@ -25,7 +25,6 @@
#pragma once
-#include "centralwidget.h"
#include "helpviewer.h"
#include "openpagesmanager.h"
diff --git a/src/plugins/help/openpagesswitcher.cpp b/src/plugins/help/openpagesswitcher.cpp
index 50ffad3b30..20117828a7 100644
--- a/src/plugins/help/openpagesswitcher.cpp
+++ b/src/plugins/help/openpagesswitcher.cpp
@@ -25,7 +25,6 @@
#include "openpagesswitcher.h"
-#include "centralwidget.h"
#include "openpageswidget.h"
#include <utils/hostosinfo.h>
diff --git a/src/plugins/help/textbrowserhelpviewer.h b/src/plugins/help/textbrowserhelpviewer.h
index 52d5b7ce2b..0864431787 100644
--- a/src/plugins/help/textbrowserhelpviewer.h
+++ b/src/plugins/help/textbrowserhelpviewer.h
@@ -25,7 +25,6 @@
#pragma once
-#include "centralwidget.h"
#include "helpviewer.h"
#include "openpagesmanager.h"
diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp
index 16f7aaccbd..067627c03b 100644
--- a/src/shared/help/contentwindow.cpp
+++ b/src/shared/help/contentwindow.cpp
@@ -25,7 +25,6 @@
#include "contentwindow.h"
-#include <centralwidget.h>
#include <helpviewer.h>
#include <localhelpmanager.h>
#include <openpagesmanager.h>
diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp
index 324a071ab6..f55ce3091b 100644
--- a/src/shared/help/indexwindow.cpp
+++ b/src/shared/help/indexwindow.cpp
@@ -27,7 +27,6 @@
#include "topicchooser.h"
-#include <centralwidget.h>
#include <helpviewer.h>
#include <localhelpmanager.h>
#include <openpagesmanager.h>