Commit c51e7af0 authored by Kåre Särs's avatar Kåre Särs
Browse files

De-singletonify the GitBlameTooltip

parent d6f10efa
......@@ -11,7 +11,6 @@
#include <QDebug>
#include <QEvent>
#include <QFontMetrics>
#include <QLabel>
#include <QMouseEvent>
#include <QScreen>
#include <QString>
......@@ -127,16 +126,11 @@ private:
QTextStream out;
};
class Tooltip : public QTextBrowser
class GitBlameTooltip::Private : public QTextBrowser
{
Q_OBJECT
public:
static Tooltip *self()
{
static Tooltip instance;
return &instance;
}
void setTooltipText(const QString &text)
{
......@@ -168,13 +162,13 @@ public:
}
}
Tooltip(QWidget *parent = nullptr)
Private(QWidget *parent = nullptr)
: QTextBrowser(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassGraphicsProxyWidget | Qt::ToolTip);
document()->setDocumentMargin(5);
setFrameStyle(QFrame::Box | QFrame::Raised);
connect(&m_hideTimer, &QTimer::timeout, this, &Tooltip::hideTooltip);
connect(&m_hideTimer, &QTimer::timeout, this, &Private::hideTooltip);
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
......@@ -281,23 +275,27 @@ protected:
private:
bool inContextMenu = false;
KTextEditor::View *m_view;
QPointer<KTextEditor::View> m_view;
QTimer m_hideTimer;
HtmlHl m_htmlHl;
KSyntaxHighlighting::Repository m_syntaxHlRepo;
};
void GitBlameTooltip::show(const QString &text, KTextEditor::View *v)
GitBlameTooltip::GitBlameTooltip() : d(new GitBlameTooltip::Private()) {}
GitBlameTooltip::~GitBlameTooltip() { delete d; }
void GitBlameTooltip::show(const QString &text, QPointer<KTextEditor::View> v)
{
if (text.isEmpty() || !v || !v->document()) {
return;
}
Tooltip::self()->setView(v);
Tooltip::self()->setTooltipText(text);
Tooltip::self()->fixGeometry();
Tooltip::self()->raise();
Tooltip::self()->show();
d->setView(v);
d->setTooltipText(text);
d->fixGeometry();
d->raise();
d->show();
}
#include "gitblametooltip.moc"
......@@ -5,14 +5,12 @@
SPDX-License-Identifier: MIT
*/
#ifndef LSPTOOLTIP_H
#define LSPTOOLTIP_H
#ifndef GitBlameTooltip_h
#define GitBlameTooltip_h
#include <QPoint>
#include <QPointer>
class QWidget;
class QString;
class Tooltip;
namespace KTextEditor
{
......@@ -21,8 +19,16 @@ class View;
class GitBlameTooltip
{
public:
static void show(const QString &text, KTextEditor::View *v);
GitBlameTooltip();
~GitBlameTooltip();
void show(const QString &text, QPointer<KTextEditor::View> v);
private:
class Private;
Private *const d;
};
#endif // LSPTOOLTIP_H
#endif // GitBlameTooltip_h
......@@ -242,7 +242,7 @@ void KateGitBlamePlugin::showFinished(int exitCode, QProcess::ExitStatus exitSta
return;
}
GitBlameTooltip::show(stdOut, m_mainWindow->activeView());
m_tooltip.show(stdOut, m_mainWindow->activeView());
}
bool KateGitBlamePlugin::hasBlameInfo() const
......
......@@ -5,8 +5,10 @@
*/
#ifndef KATE_COLORPICKER_H
#define KATE_COLORPICKER_H
#ifndef KateGitBlamePlugin_h
#define KateGitBlamePlugin_h
#include "gitblametooltip.h"
#include <KTextEditor/ConfigPage>
#include <KTextEditor/InlineNoteProvider>
......@@ -29,6 +31,7 @@ struct KateGitBlameInfo {
};
class KateGitBlamePlugin;
class GitBlameTooltip;
class GitBlameInlineNoteProvider : public KTextEditor::InlineNoteProvider
{
......@@ -82,6 +85,8 @@ private:
QVector<KateGitBlameInfo> m_blameInfo;
KTextEditor::View *m_blameInfoView = nullptr;
int m_lineOffset{0};
GitBlameTooltip m_tooltip;
};
#endif // KATE_COLORPICKER_H
#endif // KateGitBlamePlugin_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