summaryrefslogtreecommitdiff
path: root/src/texteditor.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/texteditor.h')
-rw-r--r--src/texteditor.h48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/texteditor.h b/src/texteditor.h
index 0ae39c60..0f7447ff 100644
--- a/src/texteditor.h
+++ b/src/texteditor.h
@@ -5,8 +5,10 @@
class TextEditor;
-class TextEditorToolbar
+class TextEditorToolbar : public QObject
{
+ Q_OBJECT;
+
public:
TextEditorToolbar(TextEditor& editor);
@@ -25,34 +27,47 @@ private:
// mostly from https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html
//
-class TextEditorLineNumbers : public QWidget
+class TextEditorLineNumbers : public QFrame
{
+ Q_OBJECT;
+ Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor);
+ Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor);
+
public:
TextEditorLineNumbers(TextEditor& editor);
+
QSize sizeHint() const override;
int areaWidth() const;
+ QColor textColor() const;
+ void setTextColor(const QColor& c);
+
+ QColor backgroundColor() const;
+ void setBackgroundColor(const QColor& c);
+
protected:
void paintEvent(QPaintEvent *event) override;
private:
TextEditor& m_editor;
+ QColor m_background, m_text;
void updateAreaWidth();
void updateArea(const QRect &rect, int dy);
- void highlightCurrentLine();
};
class TextEditorHighlighter : public QSyntaxHighlighter
{
+ Q_OBJECT;
+
public:
TextEditorHighlighter(QTextDocument* doc);
- QColor backgroundColor();
+ QColor backgroundColor() const;
void setBackgroundColor(const QColor& c);
- QColor textColor();
+ QColor textColor() const;
void setTextColor(const QColor& c);
protected:
@@ -67,9 +82,10 @@ private:
class TextEditor : public QPlainTextEdit
{
- Q_OBJECT
- Q_PROPERTY(QString textColor READ textColor WRITE setTextColor)
- Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor)
+ Q_OBJECT;
+ Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor);
+ Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor);
+ Q_PROPERTY(QColor highlightBackgroundColor READ highlightBackgroundColor WRITE setHighlightBackgroundColor);
friend class TextEditorLineNumbers;
@@ -89,11 +105,14 @@ public:
bool dirty() const;
- QString textColor() const;
- void setTextColor(const QString& s);
+ QColor backgroundColor() const;
+ void setBackgroundColor(const QColor& c);
- QString backgroundColor() const;
- void setBackgroundColor(const QString& s);
+ QColor textColor() const;
+ void setTextColor(const QColor& c);
+
+ QColor highlightBackgroundColor() const;
+ void setHighlightBackgroundColor(const QColor& c);
signals:
void modified(bool b);
@@ -106,16 +125,19 @@ private:
TextEditorToolbar m_toolbar;
TextEditorLineNumbers* m_lineNumbers;
TextEditorHighlighter* m_highlighter;
+ QColor m_highlightBackground;
QString m_filename;
QString m_encoding;
bool m_dirty;
+ void setDefaultStyle();
void onModified(bool b);
void dirty(bool b);
QWidget* wrapEditWidget();
- void paintLineNumbers(QPaintEvent* e);
+ void highlightCurrentLine();
+ void paintLineNumbers(QPaintEvent* e, const QColor& textColor);
};
#endif // MO_TEXTEDITOR_H