|
1 | | -/* |
| 1 | +/* |
2 | 2 | This file is part of Knut. |
3 | 3 |
|
4 | 4 | SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> |
|
24 | 24 | #include <QToolButton> |
25 | 25 | #include <QToolTip> |
26 | 26 | #include <QVBoxLayout> |
| 27 | +#include <core/settings.h> |
27 | 28 |
|
28 | 29 | namespace Gui { |
29 | 30 |
|
@@ -143,25 +144,27 @@ bool TextView::eventFilter(QObject *obj, QEvent *event) |
143 | 144 | if (event->type() == QEvent::Paint) |
144 | 145 | updateMarkRect(); |
145 | 146 | if (event->type() == QEvent::ToolTip) { |
146 | | - if (const auto *codedocument = qobject_cast<Core::CodeDocument *>(m_document)) { |
147 | | - if (const auto *helpEvent = dynamic_cast<QHelpEvent *>(event)) { |
148 | | - auto cursor = codedocument->textEdit()->cursorForPosition(helpEvent->pos()); |
149 | | - |
150 | | - // Make the textEdit a guarded pointer, as it might have been destroyed once the hover |
151 | | - // callback returns. |
152 | | - QPointer<QPlainTextEdit> textEdit(codedocument->textEdit()); |
153 | | - QPoint position(helpEvent->globalPos()); |
154 | | - |
155 | | - // Hover spams the log if it doesn't find anything. |
156 | | - // In our case, that's not a problem, so just disable the log. |
157 | | - Core::LoggerDisabler ld; |
158 | | - |
159 | | - codedocument->hover(cursor.position(), [textEdit, position](const auto &hoverText) { |
160 | | - if (!textEdit.isNull() && textEdit->isVisible()) { |
161 | | - QToolTip::showText(position, hoverText, textEdit); |
162 | | - } |
163 | | - }); |
164 | | - return true; |
| 147 | + if (Core::Settings::instance()->hasLsp()) { |
| 148 | + if (const auto *codedocument = qobject_cast<Core::CodeDocument *>(m_document)) { |
| 149 | + if (const auto *helpEvent = dynamic_cast<QHelpEvent *>(event)) { |
| 150 | + auto cursor = codedocument->textEdit()->cursorForPosition(helpEvent->pos()); |
| 151 | + |
| 152 | + // Make the textEdit a guarded pointer, as it might have been destroyed once the hover |
| 153 | + // callback returns. |
| 154 | + QPointer<QPlainTextEdit> textEdit(codedocument->textEdit()); |
| 155 | + QPoint position(helpEvent->globalPos()); |
| 156 | + |
| 157 | + // Hover spams the log if it doesn't find anything. |
| 158 | + // In our case, that's not a problem, so just disable the log. |
| 159 | + Core::LoggerDisabler ld; |
| 160 | + |
| 161 | + codedocument->hover(cursor.position(), [textEdit, position](const auto &hoverText) { |
| 162 | + if (!textEdit.isNull() && textEdit->isVisible()) { |
| 163 | + QToolTip::showText(position, hoverText, textEdit); |
| 164 | + } |
| 165 | + }); |
| 166 | + return true; |
| 167 | + } |
165 | 168 | } |
166 | 169 | } |
167 | 170 | } |
|
0 commit comments