1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef CODEEDITOR_H
8#define CODEEDITOR_H
9
10#include <KSyntaxHighlighting/Repository>
11
12#include <QPlainTextEdit>
13
14namespace KSyntaxHighlighting
15{
16class SyntaxHighlighter;
17}
18
19class CodeEditorSidebar;
20
21class CodeEditor : public QPlainTextEdit
22{
23 Q_OBJECT
24public:
25 explicit CodeEditor(QWidget *parent = nullptr);
26 ~CodeEditor() override;
27
28 void openFile(const QString &fileName);
29
30protected:
31 void contextMenuEvent(QContextMenuEvent *event) override;
32 void resizeEvent(QResizeEvent *event) override;
33
34private:
35 friend class CodeEditorSidebar;
36 void setTheme(const KSyntaxHighlighting::Theme &theme);
37 int sidebarWidth() const;
38 void sidebarPaintEvent(QPaintEvent *event);
39 void updateSidebarGeometry();
40 void updateSidebarArea(const QRect &rect, int dy);
41 void highlightCurrentLine();
42
43 QTextBlock blockAtPosition(int y) const;
44 bool isFoldable(const QTextBlock &block) const;
45 bool isFolded(const QTextBlock &block) const;
46 void toggleFold(const QTextBlock &block);
47
48 KSyntaxHighlighting::Repository m_repository;
49 KSyntaxHighlighting::SyntaxHighlighter *m_highlighter;
50 CodeEditorSidebar *m_sideBar;
51};
52
53#endif // CODEEDITOR_H
54

source code of syntax-highlighting/examples/codeeditor/codeeditor.h