diff --git a/src/include/ktexteditor/inlinenote.h b/src/include/ktexteditor/inlinenote.h --- a/src/include/ktexteditor/inlinenote.h +++ b/src/include/ktexteditor/inlinenote.h @@ -28,6 +28,7 @@ #include class QFont; +class KateInlineNoteData; namespace KTextEditor { class InlineNoteProvider; } namespace KTextEditor { @@ -53,8 +54,7 @@ * notes are created from the columns returned by InlineNoteProvider::inlineNotes(int line), * and then passed around as handles grouping useful information. */ - InlineNote(InlineNoteProvider* provider, const KTextEditor::Cursor& position, int index, - const KTextEditor::View* view, QFont font, int lineHeight, bool hasFocus); + InlineNote(const KateInlineNoteData & data); /** * Constructs an invalid inline note, i.e. isValid() will return false. @@ -127,17 +127,8 @@ int lineHeight() const; private: - InlineNoteProvider* m_provider = nullptr; - const KTextEditor::View* m_view = nullptr; - KTextEditor::Cursor m_position; - int m_index = -1; - bool m_hasFocus = false; - QFont m_font; - int m_lineHeight = -1; - - // For future use, in case members need to be added. - // TODO KF6: remove if it turns out this is unneeded. - class InlineNotePrivate* d = nullptr; + // Internal implementation data structure. + const KateInlineNoteData & d; }; } diff --git a/src/render/katerenderer.h b/src/render/katerenderer.h --- a/src/render/katerenderer.h +++ b/src/render/katerenderer.h @@ -35,7 +35,6 @@ namespace KTextEditor { class DocumentPrivate; } namespace KTextEditor { class ViewPrivate; } -namespace KTextEditor { class InlineNote; } class KateRendererConfig; class KateRenderRange; namespace Kate diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -30,6 +30,7 @@ #include "katerenderrange.h" #include "katetextlayout.h" #include "katebuffer.h" +#include "inlinenotedata.h" #include "ktexteditor/inlinenote.h" #include "ktexteditor/inlinenoteprovider.h" @@ -763,7 +764,8 @@ // Draw inline notes const auto inlineNotes = m_view->inlineNotes(range->line()); - for (const KTextEditor::InlineNote& inlineNote: inlineNotes) { + for (const auto& inlineNoteData: inlineNotes) { + KTextEditor::InlineNote inlineNote(inlineNoteData); int column = inlineNote.column(); int viewLine = range->viewLineForColumn(column); diff --git a/src/utils/ktexteditor.cpp b/src/utils/ktexteditor.cpp --- a/src/utils/ktexteditor.cpp +++ b/src/utils/ktexteditor.cpp @@ -34,6 +34,7 @@ #include "command.h" #include "inlinenoteinterface.h" #include "inlinenote.h" +#include "inlinenotedata.h" #include "inlinenoteprovider.h" #include "markinterface.h" #include "modificationinterface.h" @@ -225,33 +226,40 @@ InlineNoteProvider::~InlineNoteProvider() {} -InlineNote::InlineNote(InlineNoteProvider* provider, const KTextEditor::Cursor& position, int index, - const KTextEditor::View* view, QFont font, int lineHeight, bool hasFocus) +KateInlineNoteData::KateInlineNoteData(KTextEditor::InlineNoteProvider* provider, + const KTextEditor::View* view, + const KTextEditor::Cursor& position, + int index, + bool hasFocus, + const QFont& font, + int lineHeight) : m_provider(provider) , m_view(view) , m_position(position) , m_index(index) , m_hasFocus(hasFocus) , m_font(font) , m_lineHeight(lineHeight) +{} + +InlineNote::InlineNote(const KateInlineNoteData& data) + : d(data) { } -InlineNote::InlineNote() = default; - int InlineNote::column() const { - return m_position.column(); + return d.m_position.column(); } qreal InlineNote::width() const { - return m_provider->inlineNoteSize(*this).width(); + return d.m_provider->inlineNoteSize(*this).width(); } bool KTextEditor::InlineNote::hasFocus() const { - return m_hasFocus; + return d.m_hasFocus; } void KTextEditor::InlineNoteProvider::inlineNoteActivated(const InlineNote& note, Qt::MouseButtons buttons, const QPoint& pos) @@ -280,47 +288,48 @@ bool InlineNote::isValid() const { - return m_provider != nullptr && m_position.isValid(); + return d.m_provider != nullptr && d.m_position.isValid(); } -bool InlineNote::operator==(const InlineNote& other) const { - return m_provider == other.m_provider && m_position == other.m_position && m_index == other.m_index; +bool InlineNote::operator==(const InlineNote& other) const +{ + return d.m_provider == other.d.m_provider && d.m_position == other.d.m_position && d.m_index == other.d.m_index; } QPoint InlineNote::mapToGlobal(const QPoint& pos) const { - auto localPos = static_cast(m_view)->inlineNoteRect(*this).topLeft() + pos; - return m_view->mapToGlobal(localPos); + auto localPos = static_cast(d.m_view)->inlineNoteRect(d).topLeft() + pos; + return d.m_view->mapToGlobal(localPos); } KTextEditor::InlineNoteProvider* InlineNote::provider() const { - return m_provider; + return d.m_provider; } const KTextEditor::View* InlineNote::view() const { - return m_view; + return d.m_view; } QFont InlineNote::font() const { - return m_font; + return d.m_font; } int InlineNote::index() const { - return m_index; + return d.m_index; } int InlineNote::lineHeight() const { - return m_lineHeight; + return d.m_lineHeight; } KTextEditor::Cursor InlineNote::position() const { - return m_position; + return d.m_position; } Command::Command(const QStringList &cmds, QObject *parent) diff --git a/src/view/inlinenotedata.h b/src/view/inlinenotedata.h new file mode 100644 --- /dev/null +++ b/src/view/inlinenotedata.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE libraries + + Copyright 2018 Sven Brauch + Copyright 2018 Michal Srb + Copyright 2018 Dominik Haumann + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KATE_INLINENOTE_DATA_H +#define KATE_INLINENOTE_DATA_H + +#include +#include + +namespace KTextEditor { + class InlineNoteProvider; + class View; +} + +/** + * Internal data container for KTextEditor::InlineNote interface. + */ +class KateInlineNoteData +{ +public: + KateInlineNoteData() = default; + KateInlineNoteData(KTextEditor::InlineNoteProvider* provider, + const KTextEditor::View* view, + const KTextEditor::Cursor& position, + int index, + bool hasFocus, + const QFont& font, + int lineHeight); + + KTextEditor::InlineNoteProvider* m_provider = nullptr; + const KTextEditor::View* m_view = nullptr; + KTextEditor::Cursor m_position; + int m_index = -1; + bool m_hasFocus = false; + QFont m_font; + int m_lineHeight = -1; +}; + +#endif diff --git a/src/view/kateview.h b/src/view/kateview.h --- a/src/view/kateview.h +++ b/src/view/kateview.h @@ -70,6 +70,7 @@ class KateAbstractInputMode; class KateScriptActionMenu; class KateMessageLayout; +class KateInlineNoteData; class KToggleAction; class KSelectAction; @@ -260,9 +261,9 @@ public: void registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) Q_DECL_OVERRIDE; void unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) Q_DECL_OVERRIDE; - QRect inlineNoteRect(const KTextEditor::InlineNote& note) const; + QRect inlineNoteRect(const KateInlineNoteData& note) const; - QVarLengthArray inlineNotes(int line) const; + QVarLengthArray inlineNotes(int line) const; private: QVector m_inlineNoteProviders; diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -57,6 +57,7 @@ #include "printing/kateprinter.h" #include "katestatusbar.h" #include "kateabstractinputmode.h" +#include "inlinenotedata.h" #include #include @@ -3670,29 +3671,29 @@ } } -QVarLengthArray KTextEditor::ViewPrivate::inlineNotes(int line) const +QVarLengthArray KTextEditor::ViewPrivate::inlineNotes(int line) const { - QVarLengthArray allInlineNotes; + QVarLengthArray allInlineNotes; for (KTextEditor::InlineNoteProvider *provider: m_inlineNoteProviders) { int index = 0; for (auto column: provider->inlineNotes(line)) { - KTextEditor::InlineNote note = { + KateInlineNoteData note = { provider, + this, {line, column}, index, - this, + m_viewInternal->m_activeInlineNote.m_hasFocus, m_viewInternal->renderer()->currentFont(), - m_viewInternal->renderer()->lineHeight(), - m_viewInternal->m_activeInlineNote.hasFocus(), + m_viewInternal->renderer()->lineHeight() }; allInlineNotes.append(note); index++; } } return allInlineNotes; } -QRect KTextEditor::ViewPrivate::inlineNoteRect(const KTextEditor::InlineNote& note) const +QRect KTextEditor::ViewPrivate::inlineNoteRect(const KateInlineNoteData& note) const { return m_viewInternal->inlineNoteRect(note); } @@ -3705,7 +3706,7 @@ void KTextEditor::ViewPrivate::inlineNotesLineChanged(int line) { - if ( line == m_viewInternal->m_activeInlineNote.position().line() ) { + if ( line == m_viewInternal->m_activeInlineNote.m_position.line() ) { m_viewInternal->m_activeInlineNote = {}; } tagLines(line, line, true); diff --git a/src/view/kateviewinternal.h b/src/view/kateviewinternal.h --- a/src/view/kateviewinternal.h +++ b/src/view/kateviewinternal.h @@ -27,13 +27,13 @@ #define _KATE_VIEW_INTERNAL_ #include -#include #include "katetextcursor.h" #include "katetextline.h" #include "katedocument.h" #include "kateview.h" #include "katerenderer.h" +#include "inlinenotedata.h" #include #include @@ -468,10 +468,10 @@ QMap m_inputModes; KateAbstractInputMode *m_currentInputMode; - KTextEditor::InlineNote m_activeInlineNote; - KTextEditor::InlineNote inlineNoteAt(const QPoint& pos) const; - QRect inlineNoteRect(const KTextEditor::InlineNote& note) const; - QPoint toNoteCoordinates(const QPoint& pos, const KTextEditor::InlineNote& note) const; + KateInlineNoteData m_activeInlineNote; + KateInlineNoteData inlineNoteAt(const QPoint& pos) const; + QRect inlineNoteRect(const KateInlineNoteData& note) const; + QPoint toNoteCoordinates(const QPoint& pos, const KateInlineNoteData& note) const; }; #endif diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp --- a/src/view/kateviewinternal.cpp +++ b/src/view/kateviewinternal.cpp @@ -44,6 +44,7 @@ #include "kateabstractinputmodefactory.h" #include "kateabstractinputmode.h" #include "katepartdebug.h" +#include "inlinenotedata.h" #include #include @@ -2589,9 +2590,10 @@ void KateViewInternal::mousePressEvent(QMouseEvent *e) { // was an inline note clicked? - auto note = inlineNoteAt(e->pos()); + const auto noteData = inlineNoteAt(e->pos()); + const KTextEditor::InlineNote note(noteData); if (note.isValid()) { - note.provider()->inlineNoteActivated(note, e->button(), toNoteCoordinates(e->pos(), note)); + note.provider()->inlineNoteActivated(noteData, e->button(), toNoteCoordinates(e->pos(), noteData)); return; } @@ -2886,23 +2888,25 @@ } if (e->buttons() == Qt::NoButton) { - auto note = inlineNoteAt(e->pos()); + const auto noteData = inlineNoteAt(e->pos()); + const KTextEditor::InlineNote note(noteData); + const KTextEditor::InlineNote activeNote(m_activeInlineNote); if (note.isValid()) { - const auto notePos = toNoteCoordinates(e->pos(), note); - if (!m_activeInlineNote.isValid()) { + const auto notePos = toNoteCoordinates(e->pos(), noteData); + if (!activeNote.isValid()) { // no active note -- focus in note.provider()->inlineNoteFocusInEvent(note, notePos); - m_activeInlineNote = note; + m_activeInlineNote = noteData; } else { note.provider()->inlineNoteMouseMoveEvent(note, notePos); } // the note might change its appearance in result to the event tagLines(note.position(), note.position(), true); } - else if (m_activeInlineNote.isValid()) { - m_activeInlineNote.provider()->inlineNoteFocusOutEvent(m_activeInlineNote); - tagLines(m_activeInlineNote.position(), m_activeInlineNote.position(), true); + else if (activeNote.isValid()) { + activeNote.provider()->inlineNoteFocusOutEvent(activeNote); + tagLines(activeNote.position(), activeNote.position(), true); m_activeInlineNote = {}; } } @@ -3903,8 +3907,9 @@ #endif } -QRect KateViewInternal::inlineNoteRect(const KTextEditor::InlineNote& note) const +QRect KateViewInternal::inlineNoteRect(const KateInlineNoteData& noteData) const { + KTextEditor::InlineNote note(noteData); // compute note width and position auto noteWidth = note.width(); auto noteCursor = KTextEditor::Cursor(note.position().line(), note.column()); @@ -3924,7 +3929,7 @@ return noteRect; } -KTextEditor::InlineNote KateViewInternal::inlineNoteAt(const QPoint& pos) const +KateInlineNoteData KateViewInternal::inlineNoteAt(const QPoint& pos) const { // compute the associated cursor to get the right line auto cursor = m_view->coordinatesToCursor(pos); @@ -3940,7 +3945,7 @@ return {}; } -QPoint KateViewInternal::toNoteCoordinates(const QPoint& pos, const KTextEditor::InlineNote& note) const +QPoint KateViewInternal::toNoteCoordinates(const QPoint& pos, const KateInlineNoteData& note) const { return pos - inlineNoteRect(note).topLeft(); }