diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-08-07 17:21:38 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-09-30 08:25:18 +0000 |
commit | 6ed775f56a17a6fc3bb48323bd43373d8589b7b0 (patch) | |
tree | b571442b4a954a56d3b9e5f9964196f064cf239e /src/plugins/help/helpplugin.cpp | |
parent | 6781e3c96b987024a0a4a7b4cdef213668adc286 (diff) | |
download | qt-creator-6ed775f56a17a6fc3bb48323bd43373d8589b7b0.tar.gz |
Fix wrong context help if tool tip was not shown for focus widget
The tool tip never has focus, so it cannot become the IContext that is
checked for context help. So, integrate the help id into Utils::ToolTip
and check the tool tip first when checking for context help.
As a side effect the [F1] button and help id for the tool tip is now also
available for use outside of the text editors.
Task-number: QTCREATORBUG-5345
Change-Id: Id975703caf161d1183c247e8ad8bb693b90fd306
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
Diffstat (limited to 'src/plugins/help/helpplugin.cpp')
-rw-r--r-- | src/plugins/help/helpplugin.cpp | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index b8a83150c2..c51d5aa721 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -78,6 +78,7 @@ #include <utils/qtcassert.h> #include <utils/styledbar.h> #include <utils/theme/theme.h> +#include <utils/tooltip/tooltip.h> #include <QDir> #include <QFileInfo> @@ -101,6 +102,7 @@ using namespace Help::Internal; static const char kExternalWindowStateKey[] = "Help/ExternalWindowState"; +static const char kToolTipHelpContext[] = "Help.ToolTip"; using namespace Core; using namespace Utils; @@ -169,6 +171,13 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) connect(HelpManager::instance(), SIGNAL(collectionFileChanged()), this, SLOT(setupHelpEngineIfNeeded())); + 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; @@ -185,7 +194,8 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) connect(action, SIGNAL(triggered()), this, SLOT(activateIndex())); action = new QAction(tr("Context Help"), this); - cmd = ActionManager::registerAction(action, Help::Constants::CONTEXT_HELP); + 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); cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1)); connect(action, SIGNAL(triggered()), this, SLOT(showContextHelp())); @@ -560,40 +570,43 @@ static QUrl findBestLink(const QMap<QString, QUrl> &links, QString *highlightId) void HelpPlugin::showContextHelp() { // Find out what to show - QMap<QString, QUrl> links; - QString idFromContext; - if (IContext *context = ICore::currentContextObject()) { - idFromContext = context->contextHelpId(); - links = HelpManager::linksForIdentifier(idFromContext); - // Maybe the id is already an URL - if (links.isEmpty() && LocalHelpManager::isValidUrl(idFromContext)) - links.insert(idFromContext, idFromContext); - } + 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); - if (HelpViewer *viewer = viewerForContextHelp()) { - 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(idFromContext) - .arg(creatorTheme()->color(Theme::TextColorNormal).name())); + 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 } else { - const QUrl &oldSource = viewer->source(); - if (source != oldSource) { - viewer->stop(); - viewer->setSource(source); // triggers loadFinished which triggers id highlighting - } else { - viewer->scrollToAnchor(source.fragment()); - } - viewer->setFocus(); - ICore::raiseWindow(viewer); + viewer->scrollToAnchor(source.fragment()); } + viewer->setFocus(); + ICore::raiseWindow(viewer); } } |