OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
TextEditor.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/CoreTypes.h"
10#include "OTGui/TextEditorCfg.h"
13
14// Qt header
15#include <QtCore/qstring.h>
16#include <QtCore/qstringlist.h>
17#include <QtCore/qregularexpression.h>
18
19class QPaintEvent;
20class QResizeEvent;
21
22namespace ot {
23 class TextEditor;
24 class SyntaxHighlighter;
25 class TextEditorSearchPopup;
26
28 public:
31
32 QSize sizeHint() const override;
33
34 protected:
35 void paintEvent(QPaintEvent * _event) override;
36
37 private:
38 TextEditor* m_editor;
39 };
40
41 // ###################################################################################################################################
42
43 // ###################################################################################################################################
44
45 // ###################################################################################################################################
46
48 Q_OBJECT
50 public:
51 TextEditor(QWidget* _parent = (QWidget*)nullptr);
52 virtual ~TextEditor();
53
57 virtual void setupFromConfig(const TextEditorCfg& _config, bool _isUpdate);
58
59 int lineNumberAreaWidth(void) const;
60 void lineNumberAreaPaintEvent(QPaintEvent * _event);
61
62 void setContentChanged(void);
63 void setContentSaved(void);
64 bool getContentChanged(void) const;
65
66 void setCode(const QString& _text);
67 void setCode(const QStringList& _lines);
68
69 QStringList code(void) const;
70
74 void storeSyntaxHighlighter(SyntaxHighlighter* _highlighter);
75
78 SyntaxHighlighter* getSyntaxHighlighter(void) { return m_syntaxHighlighter; };
79
82 SyntaxHighlighter* takeSyntaxHighlighter(void);
83
84 void setTabSpaces(int _spaces) { m_tabSpaces = _spaces; };
85 int tabSpaces(void) const { return m_tabSpaces; };
86
87 void setNewLineWithSamePrefix(bool _enabled) { m_newLineSamePrefix = _enabled; };
88 bool newLineWithSamePrefix(void) const { return m_newLineSamePrefix; };
89
90 void setDuplicateLineShortcutEnabled(bool _enabled) { m_enableDuplicateLineShortcut = _enabled; };
91 bool isDuplicateLineShortcutEnabled(void) const { return m_enableDuplicateLineShortcut; };
92
93 void setEnableSameTextHighlighting(bool _enabled) { m_enableSameTextHighlighting = _enabled; };
94 bool isSameTextHighlightingEnabled(void) const { return m_enableSameTextHighlighting; };
95
96 Q_SIGNALS:
97 void saveRequested(void);
98
99 protected:
100 virtual void contentSaved(void) {};
101 virtual void contentChanged(void) {};
102 virtual void keyPressEvent(QKeyEvent* _event) override;
103 virtual void resizeEvent(QResizeEvent * _event) override;
104 virtual void wheelEvent(QWheelEvent* _event) override;
105
106 private Q_SLOTS:
107 void slotUpdateLineNumberAreaWidth(int _newBlockCount);
108 void slotHighlightCurrentLine();
109 void slotUpdateLineNumberArea(const QRect & _rect, int _dy);
110 void slotSaveRequested(void);
111 void slotFindRequested(void);
112 void slotFindClosing(void);
113 void slotDuplicateLine(void);
114 void slotCurrentColorStyleChanged(const ot::ColorStyle& _style);
115 void slotSelectionChanged(void);
116 void slotContentChange(bool _changed);
117
118 private:
120
121 void getCurrentLineSelection(QList<QTextEdit::ExtraSelection>& _selections);
122 void addAdditionalSelections(QList<QTextEdit::ExtraSelection>& _selections);
123
124 TextEditorSearchPopup* m_searchPopup;
125
126 int m_tabSpaces;
127 bool m_newLineSamePrefix;
128 bool m_enableDuplicateLineShortcut;
129 bool m_enableSameTextHighlighting;
130 int m_sameTextHighlightingMinimum;
131
132 TextEditorLineNumberArea* m_lineNumberArea;
133 SyntaxHighlighter* m_syntaxHighlighter;
134 };
135}
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
#define OT_WIDGETS_API_EXPORT
Definition OTWidgetsAPIExport.h:12
Definition ColorStyle.h:24
Definition PlainTextEdit.h:17
Definition SyntaxHighlighter.h:21
Definition TextEditorCfg.h:19
Definition TextEditor.h:47
bool isSameTextHighlightingEnabled(void) const
Definition TextEditor.h:94
bool newLineWithSamePrefix(void) const
Definition TextEditor.h:88
void setEnableSameTextHighlighting(bool _enabled)
Definition TextEditor.h:93
void setDuplicateLineShortcutEnabled(bool _enabled)
Definition TextEditor.h:90
virtual void contentSaved(void)
Definition TextEditor.h:100
int tabSpaces(void) const
Definition TextEditor.h:85
virtual void contentChanged(void)
Definition TextEditor.h:101
void setNewLineWithSamePrefix(bool _enabled)
Definition TextEditor.h:87
void setTabSpaces(int _spaces)
Definition TextEditor.h:84
bool isDuplicateLineShortcutEnabled(void) const
Definition TextEditor.h:91
SyntaxHighlighter * getSyntaxHighlighter(void)
Returns the current syntax highlighter. The TextEditor keeps ownership of the highlighter.
Definition TextEditor.h:78
Definition TextEditor.h:27
Definition TextEditorSearchPopup.h:18
Definition Connector.h:8