forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
David Schulz
parent
8c6b31f3d8
commit
64b172ae73
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user