diff options
author | Marc Reilly <marc@cpdesign.com.au> | 2016-01-04 09:17:59 +1100 |
---|---|---|
committer | David Schulz <david.schulz@theqtcompany.com> | 2016-01-18 09:25:03 +0000 |
commit | 64b172ae7389a303435324b3b297c97df55590b1 (patch) | |
tree | 38433fc9092dbee381045edefb2883734d0591c4 /src/plugins/texteditor/basehoverhandler.cpp | |
parent | 8c6b31f3d899c8d8118b4a6e48537b771eab4305 (diff) |
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: David Schulz <david.schulz@theqtcompany.com>
Diffstat (limited to 'src/plugins/texteditor/basehoverhandler.cpp')
-rw-r--r-- | src/plugins/texteditor/basehoverhandler.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/plugins/texteditor/basehoverhandler.cpp b/src/plugins/texteditor/basehoverhandler.cpp index b76250a4223..cb846c7a7a8 100644 --- a/src/plugins/texteditor/basehoverhandler.cpp +++ b/src/plugins/texteditor/basehoverhandler.cpp @@ -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) +{ + widget->setContextHelpId(QString()); + + 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_toolTip.clear(); + m_priority = -1; m_lastHelpItemIdentified = HelpItem(); } |