Commit 64b172ae authored by Marc Reilly's avatar Marc Reilly Committed by David Schulz
Browse files

hoverhandler: add priority system to determine which tooltip is shown

Hover handlers now have a priority which is used to determine which
handler's tooltip is shown. The handler with the highest priority is
used, or, in the case of equal rankings, the first registered handler.

The base handler implements a default basic priority system based on the
diagnostic and help properties. Derived handlers can manually set the
ranking value as part of the identifyMatch() call.

A new checkToolTip() method is added so the handler can analyze whether a
tooltip is valid without it being shown.

Change-Id: I9d82fb9cc52f1d3cd53a8b197d75cd923651b79d
Reviewed-by: default avatarDavid Schulz <>
parent 8c6b31f3
......@@ -40,7 +40,7 @@ using namespace Core;
namespace TextEditor {
BaseHoverHandler::BaseHoverHandler() : m_diagnosticTooltip(false)
BaseHoverHandler::BaseHoverHandler() : m_diagnosticTooltip(false), m_priority(-1)
......@@ -55,6 +55,37 @@ void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point
operateTooltip(widget, point);
int BaseHoverHandler::checkToolTip(TextEditorWidget *widget, int pos)
process(widget, pos);
return priority();
int BaseHoverHandler::priority() const
if (m_priority >= 0)
return m_priority;
if (isDiagnosticTooltip())
return Priority_Diagnostic;
if (lastHelpItemIdentified().isValid())
return Priority_Help;
if (!toolTip().isEmpty())
return Priority_Tooltip;
return Priority_None;
void BaseHoverHandler::setPriority(int priority)
m_priority = priority;
QString BaseHoverHandler::contextHelpId(TextEditorWidget *widget, int pos)
// If the tooltip is visible and there is a help match, this match is used to update
......@@ -106,6 +137,7 @@ void BaseHoverHandler::clear()
m_diagnosticTooltip = false;
m_priority = -1;
m_lastHelpItemIdentified = HelpItem();
......@@ -52,8 +52,11 @@ public:
QString contextHelpId(TextEditorWidget *widget, int pos);
int checkToolTip(TextEditorWidget *widget, int pos);
void showToolTip(TextEditorWidget *widget, const QPoint &point, int pos);
int priority() const;
void setToolTip(const QString &tooltip);
void appendToolTip(const QString &extension);
......@@ -67,6 +70,14 @@ protected:
virtual void decorateToolTip();
virtual void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point);
enum {
Priority_None = 0,
Priority_Tooltip = 5,
Priority_Help = 10,
Priority_Diagnostic = 20
void setPriority(int priority);
void clear();
void process(TextEditorWidget *widget, int pos);
......@@ -76,6 +87,7 @@ private:
bool m_diagnosticTooltip;
QString m_toolTip;
HelpItem m_lastHelpItemIdentified;
int m_priority;
} // namespace TextEditor
......@@ -3107,11 +3107,24 @@ void TextEditorWidgetPrivate::processTooltipRequest(const QTextCursor &c)
emit q->tooltipOverrideRequested(q, toolTipPoint, c.position(), &handled);
if (handled)
if (!m_hoverHandlers.isEmpty()) {
m_hoverHandlers.first()->showToolTip(q, toolTipPoint, c.position());
if (m_hoverHandlers.isEmpty()) {
emit q->tooltipRequested(toolTipPoint, c.position());
emit q->tooltipRequested(toolTipPoint, c.position());
int highestPriority = -1;
BaseHoverHandler *highest = 0;
foreach (BaseHoverHandler *handler, m_hoverHandlers) {
int priority = handler->checkToolTip(q, c.position());
if (priority > highestPriority) {
highestPriority = priority;
highest = handler;
if (highest)
highest->showToolTip(q, toolTipPoint, c.position());
bool TextEditorWidget::viewportEvent(QEvent *event)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment