File indexing completed on 2024-05-05 04:01:43
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef CODEEDITOR_H 0008 #define CODEEDITOR_H 0009 0010 #include <KSyntaxHighlighting/Repository> 0011 0012 #include <QPlainTextEdit> 0013 0014 namespace KSyntaxHighlighting 0015 { 0016 class SyntaxHighlighter; 0017 } 0018 0019 class CodeEditorSidebar; 0020 0021 class CodeEditor : public QPlainTextEdit 0022 { 0023 Q_OBJECT 0024 public: 0025 explicit CodeEditor(QWidget *parent = nullptr); 0026 ~CodeEditor() override; 0027 0028 void openFile(const QString &fileName); 0029 0030 protected: 0031 void contextMenuEvent(QContextMenuEvent *event) override; 0032 void resizeEvent(QResizeEvent *event) override; 0033 0034 private: 0035 friend class CodeEditorSidebar; 0036 void setTheme(const KSyntaxHighlighting::Theme &theme); 0037 int sidebarWidth() const; 0038 void sidebarPaintEvent(QPaintEvent *event); 0039 void updateSidebarGeometry(); 0040 void updateSidebarArea(const QRect &rect, int dy); 0041 void highlightCurrentLine(); 0042 0043 QTextBlock blockAtPosition(int y) const; 0044 bool isFoldable(const QTextBlock &block) const; 0045 bool isFolded(const QTextBlock &block) const; 0046 void toggleFold(const QTextBlock &block); 0047 0048 KSyntaxHighlighting::Repository m_repository; 0049 KSyntaxHighlighting::SyntaxHighlighter *m_highlighter; 0050 CodeEditorSidebar *m_sideBar; 0051 }; 0052 0053 #endif // CODEEDITOR_H