summaryrefslogtreecommitdiff
path: root/src/texteditor.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/texteditor.h')
-rw-r--r--src/texteditor.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/texteditor.h b/src/texteditor.h
index af542341..0ae39c60 100644
--- a/src/texteditor.h
+++ b/src/texteditor.h
@@ -23,6 +23,8 @@ private:
};
+// mostly from https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html
+//
class TextEditorLineNumbers : public QWidget
{
public:
@@ -38,12 +40,37 @@ private:
void updateAreaWidth();
void updateArea(const QRect &rect, int dy);
+ void highlightCurrentLine();
+};
+
+
+class TextEditorHighlighter : public QSyntaxHighlighter
+{
+public:
+ TextEditorHighlighter(QTextDocument* doc);
+
+ QColor backgroundColor();
+ void setBackgroundColor(const QColor& c);
+
+ QColor textColor();
+ void setTextColor(const QColor& c);
+
+protected:
+ void highlightBlock(const QString& text) override;
+
+private:
+ QColor m_background, m_text;
+
+ void changed();
};
class TextEditor : public QPlainTextEdit
{
Q_OBJECT
+ Q_PROPERTY(QString textColor READ textColor WRITE setTextColor)
+ Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor)
+
friend class TextEditorLineNumbers;
public:
@@ -62,6 +89,12 @@ public:
bool dirty() const;
+ QString textColor() const;
+ void setTextColor(const QString& s);
+
+ QString backgroundColor() const;
+ void setBackgroundColor(const QString& s);
+
signals:
void modified(bool b);
void wordWrapChanged(bool b);
@@ -72,6 +105,7 @@ protected:
private:
TextEditorToolbar m_toolbar;
TextEditorLineNumbers* m_lineNumbers;
+ TextEditorHighlighter* m_highlighter;
QString m_filename;
QString m_encoding;
bool m_dirty;