kate: add KF5 preprocessor guards for InlineNote and completion APIs
KF5's KTextEditor uses interface classes (InlineNoteInterface, CodeCompletionInterface, ConfigInterface) accessed via qobject_cast, whereas KF6 puts these methods directly on View. Wrap the differences with #if KTEXTEDITOR_VERSION_MAJOR >= 6 so both build paths compile. Fixes: - inlineNotes() return type: QVector<int> (KF5) vs QList<int> (KF6) - paintInlineNote() signature: 2 params (KF5) vs 3 params (KF6) - register/unregisterInlineNoteProvider via InlineNoteInterface - isCompletionActive via CodeCompletionInterface - configValue via ConfigInterface
This commit is contained in:
parent
e87038ca04
commit
5d18806ad6
|
|
@ -1,6 +1,13 @@
|
|||
#include "ollie_ghost.h"
|
||||
#include "ollie_kate.h"
|
||||
|
||||
#include <ktexteditor_version.h>
|
||||
#if KTEXTEDITOR_VERSION_MAJOR < 6
|
||||
#include <KTextEditor/InlineNoteInterface>
|
||||
#include <KTextEditor/CodeCompletionInterface>
|
||||
#include <KTextEditor/ConfigInterface>
|
||||
#endif
|
||||
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusPendingCall>
|
||||
#include <QDBusPendingReply>
|
||||
|
|
@ -96,7 +103,13 @@ OllieGhostProvider::OllieGhostProvider(KTextEditor::View *view, QDBusInterface *
|
|||
connect(view->document(), &KTextEditor::Document::textChanged,
|
||||
this, &OllieGhostProvider::onTextChanged);
|
||||
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
view->registerInlineNoteProvider(this);
|
||||
#else
|
||||
auto *noteIface = qobject_cast<KTextEditor::InlineNoteInterface *>(view);
|
||||
if (noteIface)
|
||||
noteIface->registerInlineNoteProvider(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
OllieGhostProvider::~OllieGhostProvider()
|
||||
|
|
@ -104,12 +117,22 @@ OllieGhostProvider::~OllieGhostProvider()
|
|||
// m_overlay is parented to the view widget and may already be destroyed
|
||||
// by Qt's child cleanup before we get here — just null it out.
|
||||
m_overlay = nullptr;
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
m_view->unregisterInlineNoteProvider(this);
|
||||
#else
|
||||
auto *iface = qobject_cast<KTextEditor::InlineNoteInterface *>(m_view);
|
||||
if (iface)
|
||||
iface->unregisterInlineNoteProvider(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
// --- InlineNoteProvider interface ---
|
||||
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
QList<int> OllieGhostProvider::inlineNotes(int line) const
|
||||
#else
|
||||
QVector<int> OllieGhostProvider::inlineNotes(int line) const
|
||||
#endif
|
||||
{
|
||||
if (m_suggestionLines.isEmpty() || m_suggestionStartLine < 0)
|
||||
return {};
|
||||
|
|
@ -141,9 +164,14 @@ QSize OllieGhostProvider::inlineNoteSize(const KTextEditor::InlineNote ¬e) co
|
|||
return QSize(qRound(width), note.lineHeight());
|
||||
}
|
||||
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
void OllieGhostProvider::paintInlineNote(const KTextEditor::InlineNote ¬e, QPainter &painter, Qt::LayoutDirection direction) const
|
||||
{
|
||||
Q_UNUSED(direction);
|
||||
#else
|
||||
void OllieGhostProvider::paintInlineNote(const KTextEditor::InlineNote ¬e, QPainter &painter) const
|
||||
{
|
||||
#endif
|
||||
|
||||
if (m_suggestionLines.isEmpty())
|
||||
return;
|
||||
|
|
@ -225,8 +253,14 @@ bool OllieGhostProvider::hasSuggestion() const
|
|||
void OllieGhostProvider::onCursorPositionChanged()
|
||||
{
|
||||
// Don't react to cursor changes while completion popup is active
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
if (m_view->isCompletionActive())
|
||||
return;
|
||||
#else
|
||||
auto *ccIface = qobject_cast<KTextEditor::CodeCompletionInterface *>(m_view);
|
||||
if (ccIface && ccIface->isCompletionActive())
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (hasSuggestion()) {
|
||||
KTextEditor::Cursor cur = m_view->cursorPosition();
|
||||
|
|
@ -342,7 +376,16 @@ void OllieGhostProvider::showOverlay()
|
|||
QStringList contLines = m_suggestionLines.mid(1);
|
||||
|
||||
// Get font from the view's config
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
QFont font = m_view->configValue(QStringLiteral("font")).value<QFont>();
|
||||
#else
|
||||
QFont font;
|
||||
auto *cfgIface = qobject_cast<KTextEditor::ConfigInterface *>(m_view);
|
||||
if (cfgIface)
|
||||
font = cfgIface->configValue(QStringLiteral("font")).value<QFont>();
|
||||
else
|
||||
font = m_view->font();
|
||||
#endif
|
||||
m_overlay->setLines(contLines, font);
|
||||
|
||||
// Position the overlay below the cursor line
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <KTextEditor/View>
|
||||
#include <KTextEditor/Document>
|
||||
#include <KTextEditor/Cursor>
|
||||
#include <ktexteditor_version.h>
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QTimer>
|
||||
|
|
@ -41,9 +42,17 @@ public:
|
|||
~OllieGhostProvider() override;
|
||||
|
||||
// InlineNoteProvider interface
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
QList<int> inlineNotes(int line) const override;
|
||||
#else
|
||||
QVector<int> inlineNotes(int line) const override;
|
||||
#endif
|
||||
QSize inlineNoteSize(const KTextEditor::InlineNote ¬e) const override;
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
void paintInlineNote(const KTextEditor::InlineNote ¬e, QPainter &painter, Qt::LayoutDirection direction) const override;
|
||||
#else
|
||||
void paintInlineNote(const KTextEditor::InlineNote ¬e, QPainter &painter) const override;
|
||||
#endif
|
||||
|
||||
/// Accept the current suggestion (insert into document). Returns true if accepted.
|
||||
bool accept();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@
|
|||
#include <QKeyEvent>
|
||||
#include <KTextEditor/Document>
|
||||
#include <KTextEditor/Editor>
|
||||
#include <ktexteditor_version.h>
|
||||
#if KTEXTEDITOR_VERSION_MAJOR < 6
|
||||
#include <KTextEditor/CodeCompletionInterface>
|
||||
#endif
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
|
@ -740,9 +744,16 @@ bool OllieKateView::eventFilter(QObject *obj, QEvent *event)
|
|||
if (m_ghost->hasSuggestion()) {
|
||||
// Don't intercept keys while a popup or completion widget is active
|
||||
auto *activeView = m_mainWindow->activeView();
|
||||
#if KTEXTEDITOR_VERSION_MAJOR >= 6
|
||||
if (QApplication::activePopupWidget() ||
|
||||
(activeView && activeView->isCompletionActive()))
|
||||
return QObject::eventFilter(obj, event);
|
||||
#else
|
||||
auto *ccIface = activeView ? qobject_cast<KTextEditor::CodeCompletionInterface *>(activeView) : nullptr;
|
||||
if (QApplication::activePopupWidget() ||
|
||||
(ccIface && ccIface->isCompletionActive()))
|
||||
return QObject::eventFilter(obj, event);
|
||||
#endif
|
||||
|
||||
if (keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers() == Qt::NoModifier) {
|
||||
if (m_ghost->accept()) {
|
||||
|
|
|
|||
Reference in New Issue