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

Reorganize the code + variable naming

parent c51e7af0
......@@ -132,41 +132,10 @@ class GitBlameTooltip::Private : public QTextBrowser
public:
void setTooltipText(const QString &text)
{
if (text.isEmpty())
return;
m_htmlHl.setText(text);
setHtml(m_htmlHl.html());
}
void setView(KTextEditor::View *view)
{
// view changed?
// => update definition
// => update font
if (view != m_view) {
if (m_view && m_view->focusProxy()) {
m_view->focusProxy()->removeEventFilter(this);
}
m_view = view;
m_htmlHl.setDefinition(m_syntaxHlRepo.definitionForName(QStringLiteral("Diff")));
updateFont();
if (m_view && m_view->focusProxy()) {
m_view->focusProxy()->installEventFilter(this);
}
}
}
Private(QWidget *parent = nullptr)
: QTextBrowser(parent)
Private() : QTextBrowser(nullptr)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassGraphicsProxyWidget | Qt::ToolTip);
document()->setDocumentMargin(5);
document()->setDocumentMargin(10);
setFrameStyle(QFrame::Box | QFrame::Raised);
connect(&m_hideTimer, &QTimer::timeout, this, &Private::hideTooltip);
......@@ -190,9 +159,9 @@ public:
connect(KTextEditor::Editor::instance(), &KTextEditor::Editor::configChanged, this, updateColors);
}
bool eventFilter(QObject *, QEvent *e) override
bool eventFilter(QObject *, QEvent *event) override
{
switch (e->type()) {
switch (event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::WindowActivate:
......@@ -205,10 +174,41 @@ public:
return false;
}
void setTooltipText(const QString &text)
{
if (text.isEmpty())
return;
m_htmlHl.setText(text);
setHtml(m_htmlHl.html());
}
void setView(KTextEditor::View *view)
{
// view changed?
// => update definition
// => update font
if (view != m_view) {
if (m_view && m_view->focusProxy()) {
m_view->focusProxy()->removeEventFilter(this);
}
m_view = view;
m_htmlHl.setDefinition(m_syntaxHlRepo.definitionForName(QStringLiteral("Diff")));
updateFont();
if (m_view && m_view->focusProxy()) {
m_view->focusProxy()->installEventFilter(this);
}
}
}
void updateFont()
{
if (!m_view)
if (!m_view) {
return;
}
auto ciface = qobject_cast<KTextEditor::ConfigInterface *>(m_view);
auto font = ciface->configValue(QStringLiteral("font")).value<QFont>();
setFont(font);
......@@ -222,6 +222,9 @@ public:
void fixGeometry()
{
if (!m_view) {
return;
}
static QScrollBar scrollBar(Qt::Horizontal);
QFontMetrics fm(font());
QSize size = fm.size(Qt::TextSingleLine, QStringLiteral("m"));
......@@ -245,14 +248,14 @@ protected:
void enterEvent(QEvent *event) override
{
inContextMenu = false;
m_inContextMenu = false;
m_hideTimer.stop();
return QTextBrowser::enterEvent(event);
}
void leaveEvent(QEvent *event) override
{
if (!m_hideTimer.isActive() && !inContextMenu) {
if (!m_hideTimer.isActive() && !m_inContextMenu) {
hideTooltip();
}
return QTextBrowser::leaveEvent(event);
......@@ -267,14 +270,14 @@ protected:
hideTooltip();
}
void contextMenuEvent(QContextMenuEvent *e) override
void contextMenuEvent(QContextMenuEvent *event) override
{
inContextMenu = true;
return QTextBrowser::contextMenuEvent(e);
m_inContextMenu = true;
return QTextBrowser::contextMenuEvent(event);
}
private:
bool inContextMenu = false;
bool m_inContextMenu = false;
QPointer<KTextEditor::View> m_view;
QTimer m_hideTimer;
HtmlHl m_htmlHl;
......@@ -285,13 +288,13 @@ private:
GitBlameTooltip::GitBlameTooltip() : d(new GitBlameTooltip::Private()) {}
GitBlameTooltip::~GitBlameTooltip() { delete d; }
void GitBlameTooltip::show(const QString &text, QPointer<KTextEditor::View> v)
void GitBlameTooltip::show(const QString &text, QPointer<KTextEditor::View> view)
{
if (text.isEmpty() || !v || !v->document()) {
if (text.isEmpty() || !view || !view->document()) {
return;
}
d->setView(v);
d->setView(view);
d->setTooltipText(text);
d->fixGeometry();
d->raise();
......
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