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
|
|
|
|
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 {
|
|
|
|
|
|
2010-09-24 20:17:40 +02:00
|
|
|
BaseHoverHandler::~BaseHoverHandler()
|
|
|
|
|
{}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-01-04 09:17:59 +11:00
|
|
|
int BaseHoverHandler::checkToolTip(TextEditorWidget *widget, int pos)
|
|
|
|
|
{
|
|
|
|
|
widget->setContextHelpId(QString());
|
|
|
|
|
|
|
|
|
|
process(widget, pos);
|
|
|
|
|
|
|
|
|
|
return priority();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-30 13:08:05 +02:00
|
|
|
QString BaseHoverHandler::contextHelpId(TextEditorWidget *widget, int pos)
|
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.
|
2013-09-11 17:11:15 +02:00
|
|
|
if (!Utils::ToolTip::isVisible() || !lastHelpItemIdentified().isValid())
|
2014-09-30 13:08:05 +02:00
|
|
|
process(widget, pos);
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2010-08-27 12:11:55 +02:00
|
|
|
if (lastHelpItemIdentified().isValid())
|
2014-09-30 13:08:05 +02:00
|
|
|
return lastHelpItemIdentified().helpId();
|
|
|
|
|
return QString();
|
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
|
|
|
|
2010-08-27 12:11:55 +02:00
|
|
|
void BaseHoverHandler::setLastHelpItemIdentified(const HelpItem &help)
|
2013-10-11 13:17:38 +02:00
|
|
|
{
|
|
|
|
|
m_lastHelpItemIdentified = help;
|
|
|
|
|
}
|
2010-08-27 12:11:55 +02:00
|
|
|
|
|
|
|
|
const HelpItem &BaseHoverHandler::lastHelpItemIdentified() const
|
2013-10-11 13:17:38 +02:00
|
|
|
{
|
|
|
|
|
return m_lastHelpItemIdentified;
|
|
|
|
|
}
|
2010-08-27 12:11:55 +02:00
|
|
|
|
2017-06-19 12:17:59 +02:00
|
|
|
void BaseHoverHandler::process(TextEditorWidget *widget, int pos)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
|
|
|
|
m_toolTip.clear();
|
2016-01-04 09:17:59 +11:00
|
|
|
m_priority = -1;
|
2010-08-27 12:11:55 +02:00
|
|
|
m_lastHelpItemIdentified = HelpItem();
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2014-09-30 13:08:05 +02:00
|
|
|
identifyMatch(widget, pos);
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-22 11:48:22 +01:00
|
|
|
void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2017-06-28 14:43:13 +02:00
|
|
|
if (priority() != Priority_Diagnostic && lastHelpItemIdentified().isValid()) {
|
2010-08-31 13:40:13 +02:00
|
|
|
const QString &contents = lastHelpItemIdentified().extractContent(false);
|
2010-09-23 10:29:13 +02:00
|
|
|
if (!contents.isEmpty()) {
|
2017-06-28 14:43:13 +02:00
|
|
|
m_toolTip = toolTip().toHtmlEscaped();
|
|
|
|
|
m_toolTip.append(contents);
|
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
|