diff --git a/kate/ollie_ghost.cpp b/kate/ollie_ghost.cpp index f74a898..f342bb5 100644 --- a/kate/ollie_ghost.cpp +++ b/kate/ollie_ghost.cpp @@ -1,6 +1,13 @@ #include "ollie_ghost.h" #include "ollie_kate.h" +#include +#if KTEXTEDITOR_VERSION_MAJOR < 6 +#include +#include +#include +#endif + #include #include #include @@ -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(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(m_view); + if (iface) + iface->unregisterInlineNoteProvider(this); +#endif } // --- InlineNoteProvider interface --- +#if KTEXTEDITOR_VERSION_MAJOR >= 6 QList OllieGhostProvider::inlineNotes(int line) const +#else +QVector 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(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(); +#else + QFont font; + auto *cfgIface = qobject_cast(m_view); + if (cfgIface) + font = cfgIface->configValue(QStringLiteral("font")).value(); + else + font = m_view->font(); +#endif m_overlay->setLines(contLines, font); // Position the overlay below the cursor line diff --git a/kate/ollie_ghost.h b/kate/ollie_ghost.h index ca3051f..767a43a 100644 --- a/kate/ollie_ghost.h +++ b/kate/ollie_ghost.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -41,9 +42,17 @@ public: ~OllieGhostProvider() override; // InlineNoteProvider interface +#if KTEXTEDITOR_VERSION_MAJOR >= 6 QList inlineNotes(int line) const override; +#else + QVector 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(); diff --git a/kate/ollie_kate.cpp b/kate/ollie_kate.cpp index 7d80db7..f378592 100644 --- a/kate/ollie_kate.cpp +++ b/kate/ollie_kate.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#if KTEXTEDITOR_VERSION_MAJOR < 6 +#include +#endif #include #include @@ -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(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()) {