2010-08-03 15:42:14 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-08-03 15:42:14 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "basehoverhandler.h"
|
|
|
|
|
#include "itexteditor.h"
|
|
|
|
|
#include "basetexteditor.h"
|
|
|
|
|
#include "displaysettings.h"
|
|
|
|
|
#include "tooltip.h"
|
2010-08-23 15:21:02 +02:00
|
|
|
#include "tipcontents.h"
|
2010-08-03 15:42:14 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/helpmanager.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-08-03 15:42:14 +02:00
|
|
|
#include <debugger/debuggerconstants.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPoint>
|
2010-08-03 15:42:14 +02:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace Core;
|
|
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
BaseHoverHandler::BaseHoverHandler(QObject *parent) : QObject(parent), m_diagnosticTooltip(false)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
|
|
|
|
// Listen for editor opened events in order to connect to tooltip/helpid requests
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(ICore::editorManager(), SIGNAL(editorOpened(Core::IEditor*)),
|
|
|
|
|
this, SLOT(editorOpened(Core::IEditor*)));
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-24 20:17:40 +02:00
|
|
|
BaseHoverHandler::~BaseHoverHandler()
|
|
|
|
|
{}
|
|
|
|
|
|
2010-08-03 15:42:14 +02:00
|
|
|
void BaseHoverHandler::editorOpened(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (acceptEditor(editor)) {
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
|
2010-08-03 15:42:14 +02:00
|
|
|
if (textEditor) {
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(textEditor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*,QPoint,int)),
|
|
|
|
|
this, SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int)));
|
2010-08-03 15:42:14 +02:00
|
|
|
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(textEditor, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*,int)),
|
|
|
|
|
this, SLOT(updateContextHelpId(TextEditor::ITextEditor*,int)));
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos)
|
|
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget *baseEditor = baseTextEditor(editor);
|
2010-08-03 15:42:14 +02:00
|
|
|
if (!baseEditor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
editor->setContextHelpId(QString());
|
|
|
|
|
|
|
|
|
|
process(editor, pos);
|
2011-02-21 16:45:07 +01:00
|
|
|
operateTooltip(editor, point);
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int pos)
|
|
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget *baseEditor = baseTextEditor(editor);
|
2010-08-13 16:38:45 +02:00
|
|
|
if (!baseEditor)
|
|
|
|
|
return;
|
|
|
|
|
|
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.
|
2010-08-27 12:11:55 +02:00
|
|
|
if (!ToolTip::instance()->isVisible() || !lastHelpItemIdentified().isValid())
|
2010-08-03 15:42:14 +02:00
|
|
|
process(editor, pos);
|
|
|
|
|
|
2010-08-27 12:11:55 +02:00
|
|
|
if (lastHelpItemIdentified().isValid())
|
|
|
|
|
editor->setContextHelpId(lastHelpItemIdentified().helpId());
|
2010-08-03 15:42:14 +02:00
|
|
|
else
|
2010-08-27 12:11:55 +02:00
|
|
|
editor->setContextHelpId(QString()); // Make sure it's an empty string.
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::setToolTip(const QString &tooltip)
|
|
|
|
|
{ m_toolTip = tooltip; }
|
|
|
|
|
|
|
|
|
|
const QString &BaseHoverHandler::toolTip() const
|
|
|
|
|
{ return m_toolTip; }
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::appendToolTip(const QString &extension)
|
|
|
|
|
{ m_toolTip.append(extension); }
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::addF1ToToolTip()
|
|
|
|
|
{
|
|
|
|
|
m_toolTip = QString(QLatin1String("<table><tr><td valign=middle>%1</td><td> "
|
2012-01-27 15:25:15 +02:00
|
|
|
"<img src=\":/texteditor/images/f1.png\"></td>"
|
2010-08-03 15:42:14 +02:00
|
|
|
"</tr></table>")).arg(m_toolTip);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
void BaseHoverHandler::setIsDiagnosticTooltip(bool isDiagnosticTooltip)
|
|
|
|
|
{
|
|
|
|
|
m_diagnosticTooltip = isDiagnosticTooltip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BaseHoverHandler::isDiagnosticTooltip() const
|
|
|
|
|
{
|
|
|
|
|
return m_diagnosticTooltip;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-27 12:11:55 +02:00
|
|
|
void BaseHoverHandler::setLastHelpItemIdentified(const HelpItem &help)
|
|
|
|
|
{ m_lastHelpItemIdentified = help; }
|
|
|
|
|
|
|
|
|
|
const HelpItem &BaseHoverHandler::lastHelpItemIdentified() const
|
|
|
|
|
{ return m_lastHelpItemIdentified; }
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::clear()
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
2011-01-17 16:29:57 +01:00
|
|
|
m_diagnosticTooltip = false;
|
2010-08-03 15:42:14 +02:00
|
|
|
m_toolTip.clear();
|
2010-08-27 12:11:55 +02:00
|
|
|
m_lastHelpItemIdentified = HelpItem();
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::process(ITextEditor *editor, int pos)
|
|
|
|
|
{
|
2010-08-27 12:11:55 +02:00
|
|
|
clear();
|
2010-08-03 15:42:14 +02:00
|
|
|
identifyMatch(editor, pos);
|
2010-09-01 12:08:38 +02:00
|
|
|
decorateToolTip();
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
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()))
|
|
|
|
|
setToolTip(Qt::escape(toolTip()));
|
2010-08-27 12:11:55 +02:00
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
if (!isDiagnosticTooltip() && 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()) {
|
|
|
|
|
setToolTip(Qt::escape(toolTip()));
|
2010-08-27 12:11:55 +02:00
|
|
|
appendToolTip(contents);
|
2011-11-10 11:55:05 +01:00
|
|
|
addF1ToToolTip();
|
2010-09-23 10:29:13 +02:00
|
|
|
}
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseHoverHandler::operateTooltip(ITextEditor *editor, const QPoint &point)
|
|
|
|
|
{
|
2010-08-27 12:11:55 +02:00
|
|
|
if (m_toolTip.isEmpty())
|
|
|
|
|
ToolTip::instance()->hide();
|
2010-08-03 15:42:14 +02:00
|
|
|
else
|
2010-08-27 12:11:55 +02:00
|
|
|
ToolTip::instance()->show(point, TextContent(m_toolTip), editor->widget());
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget *BaseHoverHandler::baseTextEditor(ITextEditor *editor)
|
2010-08-03 15:42:14 +02:00
|
|
|
{
|
|
|
|
|
if (!editor)
|
|
|
|
|
return 0;
|
2011-02-21 16:02:26 +01:00
|
|
|
return qobject_cast<BaseTextEditorWidget *>(editor->widget());
|
2010-08-03 15:42:14 +02:00
|
|
|
}
|