diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-06-17 02:53:52 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-07-02 10:10:17 -0400 |
| commit | 0084ca6c4c1fad76dafe700aad3db4fdb5ef2750 (patch) | |
| tree | 3977404e4ab39388bf2fff02fa3b5eed11ab09e2 /src/texteditor.h | |
| parent | a2b68c3a2e17198e834684fe1719b19464559657 (diff) | |
text editor default style
changed colour properties to use an actual QColor
stylable highlight background color
padding for line numbers
Diffstat (limited to 'src/texteditor.h')
| -rw-r--r-- | src/texteditor.h | 48 |
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 |
