From 0dff03e6fe6c87917afa43a815a3205e7a5692de Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 22 Jan 2016 11:48:22 +0100 Subject: TextEditor: Implement BaseHoverHandler::identifyMatch() The extra selection tooltips are a good default for a hover match. We use that in the basic plaintext editor to show, for example, syntax errors in XML documents, detected during extra compiler runs. Change-Id: Ib7f755c482ebc04148567105e4779324799fb670 Reviewed-by: David Schulz --- src/plugins/texteditor/basehoverhandler.cpp | 7 +++++++ src/plugins/texteditor/basehoverhandler.h | 2 +- src/plugins/texteditor/plaintexteditorfactory.cpp | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/texteditor/basehoverhandler.cpp b/src/plugins/texteditor/basehoverhandler.cpp index 4aa06f145c..5e2ffac50f 100644 --- a/src/plugins/texteditor/basehoverhandler.cpp +++ b/src/plugins/texteditor/basehoverhandler.cpp @@ -143,6 +143,13 @@ void BaseHoverHandler::process(TextEditorWidget *widget, int pos) decorateToolTip(); } +void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos) +{ + QString tooltip = editorWidget->extraSelectionTooltip(pos); + if (!tooltip.isEmpty()) + setToolTip(tooltip); +} + void BaseHoverHandler::decorateToolTip() { if (Qt::mightBeRichText(toolTip())) diff --git a/src/plugins/texteditor/basehoverhandler.h b/src/plugins/texteditor/basehoverhandler.h index 9360371184..91e5e4e38d 100644 --- a/src/plugins/texteditor/basehoverhandler.h +++ b/src/plugins/texteditor/basehoverhandler.h @@ -77,7 +77,7 @@ private: void clear(); void process(TextEditorWidget *widget, int pos); - virtual void identifyMatch(TextEditorWidget *editorWidget, int pos) = 0; + virtual void identifyMatch(TextEditorWidget *editorWidget, int pos); bool m_diagnosticTooltip; QString m_toolTip; diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp index 86b129d8b8..4f72897140 100644 --- a/src/plugins/texteditor/plaintexteditorfactory.cpp +++ b/src/plugins/texteditor/plaintexteditorfactory.cpp @@ -31,6 +31,7 @@ #include "texteditorconstants.h" #include "texteditorplugin.h" #include "texteditorsettings.h" +#include "basehoverhandler.h" #include #include @@ -60,6 +61,7 @@ PlainTextEditorFactory::PlainTextEditorFactory() setDisplayName(qApp->translate("OpenWith::Editors", Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME)); addMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT)); addMimeType(QLatin1String("text/css")); // for some reason freedesktop thinks css is text/x-csrc + addHoverHandler(new BaseHoverHandler); setDocumentCreator([]() { return new TextDocument(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); }); setEditorWidgetCreator([]() { return new PlainTextEditorWidget; }); -- cgit v1.2.1