2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-03 15:42:14 +02:00
|
|
|
|
|
|
|
|
#include "basehoverhandler.h"
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "texteditor.h"
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2018-01-18 10:47:45 +01:00
|
|
|
#include <utils/executeondestruction.h>
|
2017-06-26 11:15:19 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-01-10 15:07:17 +01:00
|
|
|
#include <utils/tooltip/tooltip.h>
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2013-10-11 13:17:38 +02:00
|
|
|
namespace TextEditor {
|
|
|
|
|
|
2018-11-25 18:52:41 +01:00
|
|
|
BaseHoverHandler::~BaseHoverHandler() = default;
|
2010-09-24 20:17:40 +02:00
|
|
|
|
2017-06-29 16:35:48 +02:00
|
|
|
void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point, bool decorate)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
2017-06-29 16:35:48 +02:00
|
|
|
if (decorate)
|
|
|
|
|
decorateToolTip();
|
2014-09-30 13:08:05 +02:00
|
|
|
operateTooltip(widget, point);
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-26 11:15:19 +02:00
|
|
|
void BaseHoverHandler::checkPriority(TextEditorWidget *widget,
|
|
|
|
|
int pos,
|
|
|
|
|
ReportPriority report)
|
2016-01-04 09:17:59 +11:00
|
|
|
{
|
|
|
|
|
widget->setContextHelpId(QString());
|
|
|
|
|
|
2017-06-26 11:15:19 +02:00
|
|
|
process(widget, pos, report);
|
|
|
|
|
}
|
2016-01-04 09:17:59 +11:00
|
|
|
|
|
|
|
|
int BaseHoverHandler::priority() const
|
|
|
|
|
{
|
|
|
|
|
if (m_priority >= 0)
|
|
|
|
|
return m_priority;
|
|
|
|
|
|
|
|
|
|
if (lastHelpItemIdentified().isValid())
|
|
|
|
|
return Priority_Help;
|
|
|
|
|
|
|
|
|
|
if (!toolTip().isEmpty())
|
|
|
|
|
return Priority_Tooltip;
|
|
|
|
|
|
|
|
|
|
return Priority_None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::setPriority(int priority)
|
|
|
|
|
{
|
|
|
|
|
m_priority = priority;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:58:22 +01:00
|
|
|
void BaseHoverHandler::contextHelpId(TextEditorWidget *widget,
|
|
|
|
|
int pos,
|
|
|
|
|
const Core::IContext::HelpIdCallback &callback)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
2019-01-07 09:56:52 +01:00
|
|
|
m_isContextHelpRequest = true;
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
// If the tooltip is visible and there is a help match, this match is used to update
|
|
|
|
|
// the help id. Otherwise, let the identification process happen.
|
2018-11-23 10:02:29 +01:00
|
|
|
if (!Utils::ToolTip::isVisible() || !lastHelpItemIdentified().isValid()) {
|
|
|
|
|
process(widget, pos, [this, widget = QPointer<TextEditorWidget>(widget), callback](int) {
|
|
|
|
|
if (widget)
|
|
|
|
|
propagateHelpId(widget, callback);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2018-01-18 11:58:22 +01:00
|
|
|
propagateHelpId(widget, callback);
|
2018-11-23 10:02:29 +01:00
|
|
|
}
|
2019-01-07 09:56:52 +01:00
|
|
|
|
|
|
|
|
m_isContextHelpRequest = false;
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::setToolTip(const QString &tooltip)
|
2013-10-11 13:17:38 +02:00
|
|
|
{
|
|
|
|
|
m_toolTip = tooltip;
|
|
|
|
|
}
|
2010-08-03 15:42:14 +02:00
|
|
|
|
|
|
|
|
const QString &BaseHoverHandler::toolTip() const
|
2013-10-11 13:17:38 +02:00
|
|
|
{
|
|
|
|
|
return m_toolTip;
|
|
|
|
|
}
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2019-01-24 11:30:58 +01:00
|
|
|
void BaseHoverHandler::setLastHelpItemIdentified(const Core::HelpItem &help)
|
2013-10-11 13:17:38 +02:00
|
|
|
{
|
|
|
|
|
m_lastHelpItemIdentified = help;
|
|
|
|
|
}
|
2010-08-27 12:11:55 +02:00
|
|
|
|
2019-01-24 11:30:58 +01:00
|
|
|
const Core::HelpItem &BaseHoverHandler::lastHelpItemIdentified() const
|
2013-10-11 13:17:38 +02:00
|
|
|
{
|
|
|
|
|
return m_lastHelpItemIdentified;
|
|
|
|
|
}
|
2010-08-27 12:11:55 +02:00
|
|
|
|
2019-01-07 09:56:52 +01:00
|
|
|
bool BaseHoverHandler::isContextHelpRequest() const
|
|
|
|
|
{
|
|
|
|
|
return m_isContextHelpRequest;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:58:22 +01:00
|
|
|
void BaseHoverHandler::propagateHelpId(TextEditorWidget *widget,
|
|
|
|
|
const Core::IContext::HelpIdCallback &callback)
|
|
|
|
|
{
|
|
|
|
|
QString id;
|
|
|
|
|
if (lastHelpItemIdentified().isValid())
|
|
|
|
|
id = lastHelpItemIdentified().helpId();
|
|
|
|
|
|
|
|
|
|
widget->setContextHelpId(id);
|
|
|
|
|
callback(id);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-26 11:15:19 +02:00
|
|
|
void BaseHoverHandler::process(TextEditorWidget *widget, int pos, ReportPriority report)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
|
|
|
|
m_toolTip.clear();
|
2016-01-04 09:17:59 +11:00
|
|
|
m_priority = -1;
|
2019-01-24 11:30:58 +01:00
|
|
|
m_lastHelpItemIdentified = Core::HelpItem();
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2018-01-18 10:47:45 +01:00
|
|
|
identifyMatch(widget, pos, report);
|
2017-06-26 11:15:19 +02:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 10:47:45 +01:00
|
|
|
void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
2017-06-26 11:15:19 +02:00
|
|
|
{
|
2018-01-18 10:47:45 +01:00
|
|
|
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2016-01-22 11:48:22 +01:00
|
|
|
QString tooltip = editorWidget->extraSelectionTooltip(pos);
|
|
|
|
|
if (!tooltip.isEmpty())
|
|
|
|
|
setToolTip(tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 12:08:38 +02:00
|
|
|
void BaseHoverHandler::decorateToolTip()
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
2010-09-01 12:08:38 +02:00
|
|
|
if (Qt::mightBeRichText(toolTip()))
|
2014-08-28 17:33:47 +02:00
|
|
|
setToolTip(toolTip().toHtmlEscaped());
|
2010-08-27 12:11:55 +02:00
|
|
|
|
2018-01-25 15:51:36 +01:00
|
|
|
if (lastHelpItemIdentified().isValid()) {
|
|
|
|
|
const QString &helpContents = lastHelpItemIdentified().extractContent(false);
|
|
|
|
|
if (!helpContents.isEmpty()) {
|
2017-06-28 14:43:13 +02:00
|
|
|
m_toolTip = toolTip().toHtmlEscaped();
|
2018-01-25 15:51:36 +01:00
|
|
|
m_toolTip = m_toolTip.isEmpty() ? helpContents : ("<p>" + m_toolTip + "</p><hr/><p>" + helpContents + "</p>");
|
2010-09-23 10:29:13 +02:00
|
|
|
}
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
void BaseHoverHandler::operateTooltip(TextEditorWidget *editorWidget, const QPoint &point)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
2010-08-27 12:11:55 +02:00
|
|
|
if (m_toolTip.isEmpty())
|
2013-09-11 17:11:15 +02:00
|
|
|
Utils::ToolTip::hide();
|
2010-08-03 15:42:14 +02:00
|
|
|
else
|
2015-08-07 17:21:38 +02:00
|
|
|
Utils::ToolTip::show(point, m_toolTip, editorWidget, m_lastHelpItemIdentified.isValid()
|
|
|
|
|
? m_lastHelpItemIdentified.helpId()
|
|
|
|
|
: QString());
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-11 13:17:38 +02:00
|
|
|
} // namespace TextEditor
|