forked from qt-creator/qt-creator
Help: Get rid of special CentralWidget class for help mode viewer
Change-Id: Id733eb0449cdaed5901e4144089c8adaaf07d7a9 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
@@ -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
|
@@ -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());
|
||||
}
|
||||
|
@@ -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 \
|
||||
|
@@ -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",
|
||||
|
@@ -25,8 +25,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "centralwidget.h"
|
||||
|
||||
#include <coreplugin/find/ifindsupport.h>
|
||||
|
||||
namespace Help {
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "helpindexfilter.h"
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpicons.h"
|
||||
#include "helpmanager.h"
|
||||
#include "topicchooser.h"
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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();
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpviewer.h"
|
||||
#include "openpagesmanager.h"
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "openpagesswitcher.h"
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "openpageswidget.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpviewer.h"
|
||||
#include "openpagesmanager.h"
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "contentwindow.h"
|
||||
|
||||
#include <centralwidget.h>
|
||||
#include <helpviewer.h>
|
||||
#include <localhelpmanager.h>
|
||||
#include <openpagesmanager.h>
|
||||
|
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "topicchooser.h"
|
||||
|
||||
#include <centralwidget.h>
|
||||
#include <helpviewer.h>
|
||||
#include <localhelpmanager.h>
|
||||
#include <openpagesmanager.h>
|
||||
|
Reference in New Issue
Block a user