/* SPDX-FileCopyrightText: 2018 Sven Brauch SPDX-FileCopyrightText: 2018 Michal Srb SPDX-FileCopyrightText: 2020 Jan Paul Batrina SPDX-License-Identifier: LGPL-2.0-or-later */ #pragma once #include #include #include #include #include #include #include #include #include class ColorPickerInlineNoteProvider : public KTextEditor::InlineNoteProvider { Q_OBJECT public: explicit ColorPickerInlineNoteProvider(KTextEditor::Document *doc); ~ColorPickerInlineNoteProvider() override; void updateColorMatchingCriteria(); // if startLine == -1, update all notes. endLine is optional void updateNotes(int startLine = -1, int endLine = -1); QVector inlineNotes(int line) const override; QSize inlineNoteSize(const KTextEditor::InlineNote ¬e) const override; void paintInlineNote(const KTextEditor::InlineNote ¬e, QPainter &painter) const override; void inlineNoteActivated(const KTextEditor::InlineNote ¬e, Qt::MouseButtons buttons, const QPoint &globalPos) override; private: KTextEditor::Document *m_doc; int m_startChangedLines = -1; int m_endChangedLines = -1; int m_previousNumLines = -1; struct ColorIndices { // When m_putPreviewAfterColor is true, otherColorIndices holds the starting color indices while colorNoteIndices holds the end color indices (and vice // versa) colorNoteIndices[i] corresponds to otherColorIndices[i] QVector colorNoteIndices; QVector otherColorIndices; }; // mutable is used here since InlineNoteProvider::inlineNotes() is const only, and we update the notes lazily (only when inlineNotes() is called) mutable QHash m_colorNoteIndices; QRegularExpression m_colorRegex; QVector m_matchHexLengths; bool m_putPreviewAfterColor; bool m_matchNamedColors; }; class KateColorPickerPlugin : public KTextEditor::Plugin { Q_OBJECT public: explicit KateColorPickerPlugin(QObject *parent = nullptr, const QList & = QList()); ~KateColorPickerPlugin() override; QObject *createView(KTextEditor::MainWindow *mainWindow) override; void readConfig(); private: void addDocument(KTextEditor::Document *doc); int configPages() const override { return 0; } KTextEditor::MainWindow *m_mainWindow; std::unordered_map> m_inlineColorNoteProviders; };