Files
qt-creator/src/plugins/help/helpplugin.cpp

682 lines
25 KiB
C++
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** 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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
2008-12-02 12:01:29 +01:00
#include "helpplugin.h"
#include "bookmarkmanager.h"
#include "centralwidget.h"
2008-12-02 12:01:29 +01:00
#include "docsettingspage.h"
#include "filtersettingspage.h"
#include "generalsettingspage.h"
2010-03-23 17:05:09 +01:00
#include "helpconstants.h"
#include "helpfindsupport.h"
2008-12-02 12:01:29 +01:00
#include "helpindexfilter.h"
#include "helpmode.h"
#include "helpviewer.h"
#include "localhelpmanager.h"
#include "openpagesmanager.h"
#include "openpagesmodel.h"
#include "qtwebkithelpviewer.h"
#include "remotehelpfilter.h"
2008-12-02 12:01:29 +01:00
#include "searchwidget.h"
#include "searchtaskhandler.h"
#include "textbrowserhelpviewer.h"
2008-12-02 12:01:29 +01:00
#ifdef QTC_MAC_NATIVE_HELPVIEWER
#include "macwebkithelpviewer.h"
#endif
#include <bookmarkmanager.h>
#include <contentwindow.h>
#include <indexwindow.h>
#include <app/app_version.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/id.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
2008-12-02 16:19:05 +01:00
#include <coreplugin/minisplitter.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/rightpane.h>
#include <coreplugin/sidebar.h>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/find/findplugin.h>
#include <texteditor/texteditorconstants.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
#include <utils/theme/theme.h>
#include <utils/tooltip/tooltip.h>
#include <QDir>
#include <QFileInfo>
#include <QLibraryInfo>
#include <QTimer>
#include <QTranslator>
#include <qplugin.h>
#include <QRegExp>
#include <QAction>
#include <QComboBox>
#include <QDesktopServices>
#include <QMenu>
#include <QStackedLayout>
#include <QSplitter>
#include <QHelpEngine>
2008-12-02 12:01:29 +01:00
#include <functional>
2008-12-02 12:01:29 +01:00
using namespace Help::Internal;
static const char kExternalWindowStateKey[] = "Help/ExternalWindowState";
static const char kToolTipHelpContext[] = "Help.ToolTip";
using namespace Core;
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
using namespace Utils;
HelpPlugin::HelpPlugin()
: m_mode(0),
2008-12-02 12:01:29 +01:00
m_centralWidget(0),
m_rightPaneSideBarWidget(0),
m_setupNeeded(true),
m_helpManager(0),
m_openPagesManager(0)
2008-12-02 12:01:29 +01:00
{
}
HelpPlugin::~HelpPlugin()
{
delete m_openPagesManager;
delete m_helpManager;
2008-12-02 12:01:29 +01:00
}
bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
2008-12-02 12:01:29 +01:00
{
Q_UNUSED(arguments)
Q_UNUSED(error)
Context modecontext(Constants::C_MODE_HELP);
2008-12-02 12:01:29 +01:00
const QString &locale = ICore::userInterfaceLanguage();
2009-04-20 16:41:06 +02:00
if (!locale.isEmpty()) {
QTranslator *qtr = new QTranslator(this);
QTranslator *qhelptr = new QTranslator(this);
const QString &creatorTrPath = ICore::resourcePath()
+ QLatin1String("/translations");
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
const QString &trFile = QLatin1String("assistant_") + locale;
const QString &helpTrFile = QLatin1String("qt_help_") + locale;
if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
qApp->installTranslator(qtr);
if (qhelptr->load(helpTrFile, qtTrPath) || qhelptr->load(helpTrFile, creatorTrPath))
qApp->installTranslator(qhelptr);
2009-04-20 16:41:06 +02:00
}
m_helpManager = new LocalHelpManager(this);
m_openPagesManager = new OpenPagesManager(this);
addAutoReleasedObject(m_docSettingsPage = new DocSettingsPage());
addAutoReleasedObject(m_filterSettingsPage = new FilterSettingsPage());
addAutoReleasedObject(new GeneralSettingsPage());
addAutoReleasedObject(m_searchTaskHandler = new SearchTaskHandler);
m_centralWidget = new CentralWidget(modecontext);
connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this,
SLOT(updateSideBarSource(QUrl)));
connect(m_centralWidget, &CentralWidget::closeButtonClicked,
&OpenPagesManager::instance(), &OpenPagesManager::closeCurrentPage);
connect(LocalHelpManager::instance(), &LocalHelpManager::returnOnCloseChanged,
m_centralWidget, &CentralWidget::updateCloseButton);
connect(HelpManager::instance(), SIGNAL(helpRequested(QUrl,Core::HelpManager::HelpViewerLocation)),
this, SLOT(handleHelpRequest(QUrl,Core::HelpManager::HelpViewerLocation)));
connect(m_searchTaskHandler, SIGNAL(search(QUrl)), this,
SLOT(showLinkInHelpMode(QUrl)));
connect(m_filterSettingsPage, SIGNAL(filtersChanged()), this,
SLOT(setupHelpEngineIfNeeded()));
connect(HelpManager::instance(), SIGNAL(documentationChanged()), this,
SLOT(setupHelpEngineIfNeeded()));
connect(HelpManager::instance(), SIGNAL(collectionFileChanged()), this,
SLOT(setupHelpEngineIfNeeded()));
2008-12-02 12:01:29 +01:00
connect(ToolTip::instance(), &ToolTip::shown, ICore::instance(), []() {
ICore::addAdditionalContext(Context(kToolTipHelpContext), ICore::ContextPriority::High);
});
connect(ToolTip::instance(), &ToolTip::hidden,ICore::instance(), []() {
ICore::removeAdditionalContext(Context(kToolTipHelpContext));
});
Command *cmd;
QAction *action;
2008-12-02 12:01:29 +01:00
// Add Contents, Index, and Context menu items
action = new QAction(QIcon::fromTheme(QLatin1String("help-contents")),
tr(Constants::SB_CONTENTS), this);
cmd = ActionManager::registerAction(action, "Help.ContentsMenu");
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
connect(action, SIGNAL(triggered()), this, SLOT(activateContents()));
action = new QAction(tr(Constants::SB_INDEX), this);
cmd = ActionManager::registerAction(action, "Help.IndexMenu");
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
connect(action, SIGNAL(triggered()), this, SLOT(activateIndex()));
action = new QAction(tr("Context Help"), this);
cmd = ActionManager::registerAction(action, Help::Constants::CONTEXT_HELP,
Context(kToolTipHelpContext, Core::Constants::C_GLOBAL));
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
connect(action, SIGNAL(triggered()), this, SLOT(showContextHelp()));
2008-12-02 12:01:29 +01:00
action = new QAction(tr("Technical Support"), this);
cmd = ActionManager::registerAction(action, "Help.TechSupport");
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_SUPPORT);
connect(action, SIGNAL(triggered()), this, SLOT(slotOpenSupportPage()));
action = new QAction(tr("Report Bug..."), this);
cmd = ActionManager::registerAction(action, "Help.ReportBug");
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_SUPPORT);
connect(action, SIGNAL(triggered()), this, SLOT(slotReportBug()));
if (ActionContainer *windowMenu = ActionManager::actionContainer(Core::Constants::M_WINDOW)) {
// reuse EditorManager constants to avoid a second pair of menu actions
// Goto Previous In History Action
action = new QAction(this);
Command *ctrlTab = ActionManager::registerAction(action, Core::Constants::GOTOPREVINHISTORY,
modecontext);
windowMenu->addAction(ctrlTab, Core::Constants::G_WINDOW_NAVIGATE);
connect(action, SIGNAL(triggered()), &OpenPagesManager::instance(),
SLOT(gotoPreviousPage()));
// Goto Next In History Action
action = new QAction(this);
Command *ctrlShiftTab = ActionManager::registerAction(action, Core::Constants::GOTONEXTINHISTORY,
modecontext);
windowMenu->addAction(ctrlShiftTab, Core::Constants::G_WINDOW_NAVIGATE);
connect(action, SIGNAL(triggered()), &OpenPagesManager::instance(),
SLOT(gotoNextPage()));
}
auto helpIndexFilter = new HelpIndexFilter();
addAutoReleasedObject(helpIndexFilter);
connect(helpIndexFilter, &HelpIndexFilter::linkActivated,
this, &HelpPlugin::showLinkInHelpMode);
connect(helpIndexFilter, &HelpIndexFilter::linksActivated,
this, &HelpPlugin::showLinksInHelpMode);
RemoteHelpFilter *remoteHelpFilter = new RemoteHelpFilter();
addAutoReleasedObject(remoteHelpFilter);
connect(remoteHelpFilter, SIGNAL(linkActivated(QUrl)), this,
SLOT(showLinkInHelpMode(QUrl)));
QDesktopServices::setUrlHandler(QLatin1String("qthelp"), HelpManager::instance(), "handleHelpRequest");
connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*,Core::IMode*)),
this, SLOT(modeChanged(Core::IMode*,Core::IMode*)));
m_mode = new HelpMode;
m_mode->setWidget(m_centralWidget);
addAutoReleasedObject(m_mode);
2008-12-02 12:01:29 +01:00
return true;
}
void HelpPlugin::extensionsInitialized()
{
QStringList filesToRegister;
// we might need to register creators inbuild help
filesToRegister.append(ICore::documentationPath() + QLatin1String("/qtcreator.qch"));
HelpManager::registerDocumentation(filesToRegister);
}
ExtensionSystem::IPlugin::ShutdownFlag HelpPlugin::aboutToShutdown()
{
if (m_externalWindow)
delete m_externalWindow.data();
if (m_centralWidget)
delete m_centralWidget;
if (m_rightPaneSideBarWidget)
delete m_rightPaneSideBarWidget;
return SynchronousShutdown;
}
void HelpPlugin::resetFilter()
{
const QString &filterInternal = QString::fromLatin1("Qt Creator %1.%2.%3")
.arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR).arg(IDE_VERSION_RELEASE);
QRegExp filterRegExp(QLatin1String("Qt Creator \\d*\\.\\d*\\.\\d*"));
QHelpEngineCore *engine = &LocalHelpManager::helpEngine();
const QStringList &filters = engine->customFilters();
foreach (const QString &filter, filters) {
if (filterRegExp.exactMatch(filter) && filter != filterInternal)
engine->removeCustomFilter(filter);
}
// we added a filter at some point, remove previously added filter
if (engine->customValue(Help::Constants::WeAddedFilterKey).toInt() == 1) {
const QString &filter =
engine->customValue(Help::Constants::PreviousFilterNameKey).toString();
if (!filter.isEmpty())
engine->removeCustomFilter(filter);
}
// potentially remove a filter with new name
const QString filterName = tr("Unfiltered");
engine->removeCustomFilter(filterName);
engine->addCustomFilter(filterName, QStringList());
engine->setCustomValue(Help::Constants::WeAddedFilterKey, 1);
engine->setCustomValue(Help::Constants::PreviousFilterNameKey, filterName);
engine->setCurrentFilter(filterName);
LocalHelpManager::updateFilterModel();
connect(engine, &QHelpEngineCore::setupFinished,
LocalHelpManager::instance(), &LocalHelpManager::updateFilterModel);
}
void HelpPlugin::saveExternalWindowSettings()
2008-12-02 12:01:29 +01:00
{
if (!m_externalWindow)
return;
m_externalWindowState = m_externalWindow->geometry();
QSettings *settings = ICore::settings();
settings->setValue(QLatin1String(kExternalWindowStateKey),
qVariantFromValue(m_externalWindowState));
}
2008-12-02 12:01:29 +01:00
HelpWidget *HelpPlugin::createHelpWidget(const Context &context, HelpWidget::WidgetStyle style)
{
HelpWidget *widget = new HelpWidget(context, style);
connect(widget->currentViewer(), SIGNAL(loadFinished()),
this, SLOT(highlightSearchTermsInContextHelp()));
connect(widget, SIGNAL(openHelpMode(QUrl)),
this, SLOT(showLinkInHelpMode(QUrl)));
connect(widget, SIGNAL(closeButtonClicked()),
this, SLOT(slotHideRightPane()));
connect(widget, SIGNAL(aboutToClose()),
this, SLOT(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;
}
void HelpPlugin::createRightPaneContextViewer()
{
if (m_rightPaneSideBarWidget)
return;
m_rightPaneSideBarWidget = createHelpWidget(Context(Constants::C_HELP_SIDEBAR),
HelpWidget::SideBarWidget);
}
HelpViewer *HelpPlugin::externalHelpViewer()
{
if (m_externalWindow)
return m_externalWindow->currentViewer();
doSetupIfNeeded();
m_externalWindow = createHelpWidget(Context(Constants::C_HELP_EXTERNAL),
HelpWidget::ExternalWindow);
if (m_externalWindowState.isNull()) {
QSettings *settings = ICore::settings();
m_externalWindowState = settings->value(QLatin1String(kExternalWindowStateKey)).toRect();
}
if (m_externalWindowState.isNull())
m_externalWindow->resize(650, 700);
else
m_externalWindow->setGeometry(m_externalWindowState);
m_externalWindow->show();
m_externalWindow->setFocus();
return m_externalWindow->currentViewer();
2008-12-02 12:01:29 +01:00
}
HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
{
// check for backends
typedef std::function<HelpViewer *()> ViewerFactory;
QHash<QString, ViewerFactory> factories; // id -> factory
#ifdef QTC_MAC_NATIVE_HELPVIEWER
factories.insert(QLatin1String("native"), []() { return new MacWebKitHelpViewer(); });
#endif
#ifndef QT_NO_WEBKIT
factories.insert(QLatin1String("qtwebkit"), []() { return new QtWebKitHelpViewer(); });
#endif
factories.insert(QLatin1String("textbrowser"), []() { return new TextBrowserHelpViewer(); });
ViewerFactory factory;
// TODO: Visual Studio < 2013 has a bug in std::function's operator bool, which in this case
// leads to succeeding boolean checks on factory which should not succeed.
// So we may not check against "if (!factory)"
bool factoryFound = false;
// check requested backend
const QString backend = QLatin1String(qgetenv("QTC_HELPVIEWER_BACKEND"));
if (!backend.isEmpty()) {
if (!factories.contains(backend)) {
qWarning("Help viewer backend \"%s\" not found, using default.", qPrintable(backend));
} else {
factory = factories.value(backend);
factoryFound = true;
}
}
// default setting
#ifdef QTC_MAC_NATIVE_HELPVIEWER_DEFAULT
if (!factoryFound && factories.contains(QLatin1String("native"))) {
factory = factories.value(QLatin1String("native"));
factoryFound = true;
}
#endif
if (!factoryFound && factories.contains(QLatin1String("qtwebkit"))) {
factory = factories.value(QLatin1String("qtwebkit"));
factoryFound = true;
}
if (!factoryFound && factories.contains(QLatin1String("textbrowser"))) {
factory = factories.value(QLatin1String("textbrowser"));
factoryFound = true;
}
QTC_ASSERT(factoryFound, return 0);
HelpViewer *viewer = factory();
// initialize font
viewer->setViewerFont(LocalHelpManager::fallbackFont());
connect(LocalHelpManager::instance(), &LocalHelpManager::fallbackFontChanged,
viewer, &HelpViewer::setViewerFont);
// initialize zoom
viewer->setScale(zoom);
// add find support
Aggregation::Aggregate *agg = new Aggregation::Aggregate();
agg->add(viewer);
agg->add(new HelpViewerFindSupport(viewer));
return viewer;
}
2009-01-28 13:57:42 +01:00
void HelpPlugin::activateHelpMode()
{
ModeManager::activateMode(Id(Constants::ID_MODE_HELP));
2009-01-28 13:57:42 +01:00
}
void HelpPlugin::showLinkInHelpMode(const QUrl &source)
2008-12-02 12:01:29 +01:00
{
2009-01-28 13:57:42 +01:00
activateHelpMode();
ICore::raiseWindow(m_mode->widget());
2008-12-02 12:01:29 +01:00
m_centralWidget->setSource(source);
m_centralWidget->setFocus();
}
void HelpPlugin::showLinksInHelpMode(const QMap<QString, QUrl> &links, const QString &key)
{
activateHelpMode();
ICore::raiseWindow(m_mode->widget());
m_centralWidget->showTopicChooser(links, key);
}
2008-12-02 12:01:29 +01:00
void HelpPlugin::slotHideRightPane()
{
RightPaneWidget::instance()->setShown(false);
2008-12-02 12:01:29 +01:00
}
void HelpPlugin::modeChanged(IMode *mode, IMode *old)
2008-12-02 12:01:29 +01:00
{
Q_UNUSED(old)
if (mode == m_mode) {
qApp->setOverrideCursor(Qt::WaitCursor);
2010-08-25 16:18:52 +02:00
doSetupIfNeeded();
2008-12-02 12:01:29 +01:00
qApp->restoreOverrideCursor();
}
}
void HelpPlugin::updateSideBarSource()
{
if (HelpViewer *viewer = m_centralWidget->currentViewer()) {
const QUrl &url = viewer->source();
if (url.isValid())
updateSideBarSource(url);
}
}
void HelpPlugin::updateSideBarSource(const QUrl &newUrl)
{
if (m_rightPaneSideBarWidget) {
// This is called when setSource on the central widget is called.
// Avoid nested setSource calls (even of different help viewers) by scheduling the
// sidebar viewer update on the event loop (QTCREATORBUG-12742)
QMetaObject::invokeMethod(m_rightPaneSideBarWidget->currentViewer(), "setSource",
Qt::QueuedConnection, Q_ARG(QUrl, newUrl));
}
}
void HelpPlugin::setupHelpEngineIfNeeded()
{
LocalHelpManager::setEngineNeedsUpdate();
if (ModeManager::currentMode() == m_mode
|| LocalHelpManager::contextHelpOption() == HelpManager::ExternalHelpAlways)
LocalHelpManager::setupGuiHelpEngine();
}
bool HelpPlugin::canShowHelpSideBySide() const
2008-12-02 12:01:29 +01:00
{
RightPanePlaceHolder *placeHolder = RightPanePlaceHolder::current();
if (!placeHolder)
return false;
if (placeHolder->isVisible())
return true;
IEditor *editor = EditorManager::currentEditor();
if (!editor)
return true;
QTC_ASSERT(editor->widget(), return true);
if (!editor->widget()->isVisible())
return true;
if (editor->widget()->width() < 800)
return false;
return true;
}
HelpViewer *HelpPlugin::viewerForHelpViewerLocation(HelpManager::HelpViewerLocation location)
{
HelpManager::HelpViewerLocation actualLocation = location;
if (location == HelpManager::SideBySideIfPossible)
actualLocation = canShowHelpSideBySide() ? HelpManager::SideBySideAlways
: HelpManager::HelpModeAlways;
if (actualLocation == HelpManager::ExternalHelpAlways)
return externalHelpViewer();
if (actualLocation == HelpManager::SideBySideAlways) {
createRightPaneContextViewer();
RightPaneWidget::instance()->setWidget(m_rightPaneSideBarWidget);
RightPaneWidget::instance()->setShown(true);
return m_rightPaneSideBarWidget->currentViewer();
2009-06-02 17:22:14 +02:00
}
QTC_CHECK(actualLocation == HelpManager::HelpModeAlways);
activateHelpMode(); // should trigger an createPage...
HelpViewer *viewer = m_centralWidget->currentViewer();
if (!viewer)
viewer = OpenPagesManager::instance().createPage();
return viewer;
}
HelpViewer *HelpPlugin::viewerForContextHelp()
{
return viewerForHelpViewerLocation(LocalHelpManager::contextHelpOption());
}
static QUrl findBestLink(const QMap<QString, QUrl> &links, QString *highlightId)
{
if (highlightId)
highlightId->clear();
if (links.isEmpty())
return QUrl();
QUrl source = links.constBegin().value();
// workaround to show the latest Qt version
int version = 0;
QRegExp exp(QLatin1String("(\\d+)"));
foreach (const QUrl &link, links) {
const QString &authority = link.authority();
if (authority.startsWith(QLatin1String("com.trolltech."))
|| authority.startsWith(QLatin1String("org.qt-project."))) {
if (exp.indexIn(authority) >= 0) {
const int tmpVersion = exp.cap(1).toInt();
if (tmpVersion > version) {
source = link;
version = tmpVersion;
if (highlightId)
*highlightId = source.fragment();
}
}
}
}
return source;
}
void HelpPlugin::showContextHelp()
{
// Find out what to show
QString contextHelpId = Utils::ToolTip::contextHelpId();
IContext *context = ICore::currentContextObject();
if (contextHelpId.isEmpty() && context)
contextHelpId = context->contextHelpId();
// get the viewer after getting the help id,
// because a new window might be opened and therefore focus be moved
HelpViewer *viewer = viewerForContextHelp();
QTC_ASSERT(viewer, return);
QMap<QString, QUrl> links = HelpManager::linksForIdentifier(contextHelpId);
// Maybe the id is already an URL
if (links.isEmpty() && LocalHelpManager::isValidUrl(contextHelpId))
links.insert(contextHelpId, contextHelpId);
QUrl source = findBestLink(links, &m_contextHelpHighlightId);
if (!source.isValid()) {
// No link found or no context object
viewer->setSource(QUrl(Help::Constants::AboutBlank));
viewer->setHtml(tr("<html><head><title>No Documentation</title>"
"</head><body><br/><center>"
"<font color=\"%1\"><b>%2</b></font><br/>"
"<font color=\"%3\">No documentation available.</font>"
"</center></body></html>")
.arg(creatorTheme()->color(Theme::TextColorNormal).name())
.arg(contextHelpId)
.arg(creatorTheme()->color(Theme::TextColorNormal).name()));
} else {
const QUrl &oldSource = viewer->source();
if (source != oldSource) {
viewer->stop();
viewer->setSource(source); // triggers loadFinished which triggers id highlighting
2009-06-02 17:22:14 +02:00
} else {
viewer->scrollToAnchor(source.fragment());
2008-12-02 12:01:29 +01:00
}
viewer->setFocus();
ICore::raiseWindow(viewer);
2008-12-02 12:01:29 +01:00
}
}
void HelpPlugin::activateIndex()
{
2009-01-28 13:57:42 +01:00
activateHelpMode();
m_centralWidget->activateSideBarItem(QLatin1String(Constants::HELP_INDEX));
2008-12-02 12:01:29 +01:00
}
void HelpPlugin::activateContents()
{
2009-01-28 13:57:42 +01:00
activateHelpMode();
m_centralWidget->activateSideBarItem(QLatin1String(Constants::HELP_CONTENTS));
}
void HelpPlugin::highlightSearchTermsInContextHelp()
{
if (m_contextHelpHighlightId.isEmpty())
return;
HelpViewer *viewer = viewerForContextHelp();
QTC_ASSERT(viewer, return);
viewer->highlightId(m_contextHelpHighlightId);
m_contextHelpHighlightId.clear();
}
void HelpPlugin::handleHelpRequest(const QUrl &url, HelpManager::HelpViewerLocation location)
2008-12-02 12:01:29 +01:00
{
if (HelpViewer::launchWithExternalApp(url))
return;
QString address = url.toString();
if (!HelpManager::findFile(url).isValid()) {
if (address.startsWith(QLatin1String("qthelp://org.qt-project."))
|| address.startsWith(QLatin1String("qthelp://com.nokia."))
|| address.startsWith(QLatin1String("qthelp://com.trolltech."))) {
// local help not installed, resort to external web help
QString urlPrefix = QLatin1String("http://doc.qt.io/");
if (url.authority() == QLatin1String("org.qt-project.qtcreator"))
urlPrefix.append(QString::fromLatin1("qtcreator"));
else
urlPrefix.append(QLatin1String("latest"));
address = urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/')));
}
}
const QUrl newUrl(address);
HelpViewer *viewer = viewerForHelpViewerLocation(location);
QTC_ASSERT(viewer, return);
viewer->setSource(newUrl);
ICore::raiseWindow(viewer);
}
2008-12-02 12:01:29 +01:00
void HelpPlugin::slotOpenSupportPage()
{
showLinkInHelpMode(QUrl(QLatin1String("qthelp://org.qt-project.qtcreator/doc/technical-support.html")));
}
void HelpPlugin::slotReportBug()
{
QDesktopServices::openUrl(QUrl(QLatin1String("https://bugreports.qt.io")));
}
2010-08-25 16:18:52 +02:00
void HelpPlugin::doSetupIfNeeded()
{
LocalHelpManager::setupGuiHelpEngine();
if (m_setupNeeded) {
resetFilter();
m_setupNeeded = false;
OpenPagesManager::instance().setupInitialPages();
LocalHelpManager::bookmarkManager().setupBookmarkModels();
}
}