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 bool saveToFile(const QString& _fileName);
70
71 QStringList code(void) const;
72
76 void storeSyntaxHighlighter(SyntaxHighlighter* _highlighter);
77
80 SyntaxHighlighter* getSyntaxHighlighter(void) { return m_syntaxHighlighter; };
81
84 SyntaxHighlighter* takeSyntaxHighlighter(void);
85
86 void setTabSpaces(int _spaces) { m_tabSpaces = _spaces; };
87 int tabSpaces(void) const { return m_tabSpaces; };
88
89 void setNewLineWithSamePrefix(bool _enabled) { m_newLineSamePrefix = _enabled; };
90 bool newLineWithSamePrefix(void) const { return m_newLineSamePrefix; };
91
92 void setDuplicateLineShortcutEnabled(bool _enabled) { m_enableDuplicateLineShortcut = _enabled; };
93 bool isDuplicateLineShortcutEnabled(void) const { return m_enableDuplicateLineShortcut; };
94
95 void setEnableSameTextHighlighting(bool _enabled) { m_enableSameTextHighlighting = _enabled; };
96 bool isSameTextHighlightingEnabled(void) const { return m_enableSameTextHighlighting; };
97
98 Q_SIGNALS:
99 void saveRequested(void);
100
101 public Q_SLOTS:
102 void slotSaveRequested(void);
103
104 protected:
105 virtual void keyPressEvent(QKeyEvent* _event) override;
106 virtual void resizeEvent(QResizeEvent * _event) override;
107 virtual void wheelEvent(QWheelEvent* _event) override;
108
109 private Q_SLOTS:
110 void slotUpdateLineNumberAreaWidth(int _newBlockCount);
111 void slotHighlightCurrentLine();
112 void slotUpdateLineNumberArea(const QRect & _rect, int _dy);
113 void slotFindRequested(void);
114 void slotFindClosing(void);
115 void slotDuplicateLine(void);
116 void slotCurrentColorStyleChanged(const ot::ColorStyle& _style);
117 void slotSelectionChanged(void);
118
119 private:
121
122 void getCurrentLineSelection(QList<QTextEdit::ExtraSelection>& _selections);
123 void addAdditionalSelections(QList<QTextEdit::ExtraSelection>& _selections);
124
125 TextEditorSearchPopup* m_searchPopup;
126
127 int m_tabSpaces;
128 bool m_newLineSamePrefix;
129 bool m_enableDuplicateLineShortcut;
130 bool m_enableSameTextHighlighting;
131 int m_sameTextHighlightingMinimum;
132
133 TextEditorLineNumberArea* m_lineNumberArea;
134 SyntaxHighlighter* m_syntaxHighlighter;
135 };
136}
#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
void saveRequested(void)
bool isSameTextHighlightingEnabled(void) const
Definition TextEditor.h:96
bool newLineWithSamePrefix(void) const
Definition TextEditor.h:90
void setEnableSameTextHighlighting(bool _enabled)
Definition TextEditor.h:95
void setDuplicateLineShortcutEnabled(bool _enabled)
Definition TextEditor.h:92
int tabSpaces(void) const
Definition TextEditor.h:87
void setNewLineWithSamePrefix(bool _enabled)
Definition TextEditor.h:89
void setTabSpaces(int _spaces)
Definition TextEditor.h:86
bool isDuplicateLineShortcutEnabled(void) const
Definition TextEditor.h:93
SyntaxHighlighter * getSyntaxHighlighter(void)
Returns the current syntax highlighter. The TextEditor keeps ownership of the highlighter.
Definition TextEditor.h:80
Definition TextEditor.h:27
Definition TextEditorSearchPopup.h:18
Definition Connector.h:8