Commit 5a1f19e5 authored by Méven Car's avatar Méven Car
Browse files

LSP: Improve tooltip

Before the lsp tooltip would ever be visible for 1 second when not in manual mode.

This makes the tooltip visible as long as the mouse has not moved, or hovers the tooltip. When the mouse moves there is a 100 delay before the tooltip is hidden to let the user hover over the tooltip if he wants to select text there.
If a tooltip is hovered when the mouse leaves it, the tooltip closes immediately.
There is only one Lsp tooltip ever shown.
parent b4366e99
......@@ -81,7 +81,7 @@ public:
// make sure there is no selection, otherwise we interrupt
if (!v->selection()) {
LspTooltip::show(finalTooltip, v->mapToGlobal(v->cursorToCoordinate(position)), v, manual ? 0 : 1000);
LspTooltip::show(finalTooltip, v->mapToGlobal(v->cursorToCoordinate(position)), v, manual);
}
};
......
......@@ -64,10 +64,10 @@ public:
}
}
Tooltip(QWidget *parent, int timeout)
Tooltip(QWidget *parent, bool manual)
: QTextBrowser(parent)
, hl(document())
, m_hideTimeout(timeout)
, m_manual(manual)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassGraphicsProxyWidget | Qt::ToolTip);
setAttribute(Qt::WA_DeleteOnClose, true);
......@@ -110,8 +110,13 @@ public:
case QEvent::WindowDeactivate:
case QEvent::FocusOut:
case QEvent::FocusIn:
if (!inContextMenu)
if (!inContextMenu && !m_view->hasFocus()) {
hideTooltip();
}
break;
case QEvent::MouseMove:
if (!m_manual && !hasFocus())
hideTooltipWithDelay();
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
......@@ -141,6 +146,11 @@ public:
deleteLater();
}
Q_SLOT void hideTooltipWithDelay()
{
m_hideTimer.start(100);
}
void resizeTip(const QString &text)
{
QFontMetrics fm(font());
......@@ -184,13 +194,6 @@ public:
}
protected:
void showEvent(QShowEvent *event) override
{
if (m_hideTimeout > 0) {
m_hideTimer.start(m_hideTimeout);
}
QTextBrowser::showEvent(event);
}
void enterEvent(QEvent *event) override
{
......@@ -213,7 +216,6 @@ protected:
if (rect().contains(pos)) {
return QTextBrowser::mouseMoveEvent(event);
}
hideTooltip();
}
void contextMenuEvent(QContextMenuEvent *e) override
......@@ -227,10 +229,10 @@ private:
QPointer<KTextEditor::View> m_view;
QTimer m_hideTimer;
KSyntaxHighlighting::SyntaxHighlighter hl;
int m_hideTimeout;
bool m_manual;
};
void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v, int timeout)
void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v, bool manual)
{
if (text.isEmpty())
return;
......@@ -239,7 +241,10 @@ void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v, int
return;
}
auto tooltip = new Tooltip(v, timeout);
static QPointer<Tooltip> tooltip = nullptr;
delete tooltip;
tooltip = new Tooltip(v, manual);
tooltip->show();
tooltip->setView(v);
tooltip->setTooltipText(text);
......
......@@ -22,7 +22,7 @@ class LspTooltip
{
public:
// tooltip hidden after timeout msec (if > 0)
static void show(const QString &text, QPoint pos, KTextEditor::View *v, int timeout);
static void show(const QString &text, QPoint pos, KTextEditor::View *v, bool manual);
};
#endif // LSPTOOLTIP_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment