aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/basehoverhandler.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2019-10-25 15:16:47 +0200
committerEike Ziller <eike.ziller@qt.io>2019-11-06 09:43:20 +0000
commit177f14b11514075b19f236f02b1b3fcc3fb49fef (patch)
treee58176001be3bf4233af2f7902cd65bdbd20e3b8 /src/plugins/texteditor/basehoverhandler.cpp
parent8d9dee8465be29fa32009c71a978c1ed80d96d20 (diff)
TextEditor: Do not change the text format for tool tips
We should not force the tool tip text to HTML when help content is available or when adding the F1 icon. Instead add help content and F1 icon into the tool tip layout. Change-Id: Ibe2d4fa2fb81bcda4e5aeb0d7d86dbf63fcf3ce6 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/basehoverhandler.cpp')
-rw-r--r--src/plugins/texteditor/basehoverhandler.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/plugins/texteditor/basehoverhandler.cpp b/src/plugins/texteditor/basehoverhandler.cpp
index d7d53ca5f0c..52f1990d116 100644
--- a/src/plugins/texteditor/basehoverhandler.cpp
+++ b/src/plugins/texteditor/basehoverhandler.cpp
@@ -30,14 +30,14 @@
#include <utils/qtcassert.h>
#include <utils/tooltip/tooltip.h>
+#include <QVBoxLayout>
+
namespace TextEditor {
BaseHoverHandler::~BaseHoverHandler() = default;
-void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point, bool decorate)
+void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point)
{
- if (decorate)
- decorateToolTip();
operateTooltip(widget, point);
}
@@ -140,31 +140,32 @@ void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, Re
setToolTip(tooltip);
}
-void BaseHoverHandler::decorateToolTip()
-{
- if (!m_toolTip.isEmpty())
- m_toolTip = "<p>" + m_toolTip.toHtmlEscaped().replace('\n', "<br/>") + "</p>";
-
- if (lastHelpItemIdentified().isValid() && !lastHelpItemIdentified().isFuzzyMatch()) {
- const QString &helpContents = lastHelpItemIdentified().extractContent(false);
- if (!helpContents.isEmpty()) {
- m_toolTip = m_toolTip.isEmpty() ? helpContents
- : (m_toolTip + "<hr/><p>" + helpContents + "</p>");
- }
- }
-}
-
void BaseHoverHandler::operateTooltip(TextEditorWidget *editorWidget, const QPoint &point)
{
- if (m_toolTip.isEmpty())
+ const QVariant helpItem = m_lastHelpItemIdentified.isEmpty()
+ ? QVariant()
+ : QVariant::fromValue(m_lastHelpItemIdentified);
+ const bool extractHelp = m_lastHelpItemIdentified.isValid()
+ && !m_lastHelpItemIdentified.isFuzzyMatch();
+ const QString helpContents = extractHelp ? m_lastHelpItemIdentified.firstParagraph()
+ : QString();
+ if (m_toolTip.isEmpty() && helpContents.isEmpty()) {
Utils::ToolTip::hide();
- else
- Utils::ToolTip::show(point,
- m_toolTip,
- editorWidget,
- m_lastHelpItemIdentified.isEmpty()
- ? QVariant()
- : QVariant::fromValue(m_lastHelpItemIdentified));
+ } else {
+ if (helpContents.isEmpty()) {
+ Utils::ToolTip::show(point, m_toolTip, editorWidget, helpItem);
+ } else if (m_toolTip.isEmpty()) {
+ Utils::ToolTip::show(point, helpContents, editorWidget, helpItem);
+ } else {
+ // separate labels for tool tip text and help,
+ // so the text format (plain, rich, markdown) can be handled differently
+ auto layout = new QVBoxLayout;
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(new QLabel(m_toolTip));
+ layout->addWidget(new QLabel("<hr/>" + helpContents));
+ Utils::ToolTip::show(point, layout, editorWidget, helpItem);
+ }
+ }
}
} // namespace TextEditor