QCodeEditor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // Qt
4 #include <QTextEdit> // Required for inheritance
5 
6 class QCompleter;
7 class QLineNumberArea;
8 class QSyntaxStyle;
11 
15 class QCodeEditor : public QTextEdit
16 {
17  Q_OBJECT
18 
19 public:
24  explicit QCodeEditor(QWidget* widget=nullptr);
25 
26  // Disable copying
27  QCodeEditor(const QCodeEditor&) = delete;
28  QCodeEditor& operator=(const QCodeEditor&) = delete;
29 
36 
41  void setHighlighter(QStyleSyntaxHighlighter* highlighter);
42 
47  void setSyntaxStyle(QSyntaxStyle* style);
48 
52  void setAutoParentheses(bool enabled);
53 
58  bool autoParentheses() const;
59 
64  void setTabReplace(bool enabled);
65 
70  bool tabReplace() const;
71 
77  void setTabReplaceSize(int val);
78 
84  int tabReplaceSize() const;
85 
89  void setAutoIndentation(bool enabled);
90 
95  bool autoIndentation() const;
96 
101  void setCompleter(QCompleter* completer);
102 
107  QCompleter* completer() const;
108 
109 public Q_SLOTS:
110 
116  void insertCompletion(QString s);
117 
123  void updateLineNumberAreaWidth(int);
124 
130  void updateLineNumberArea(const QRect& rect);
131 
136  void updateExtraSelection();
137 
141  void updateStyle();
142 
147  void onSelectionChanged();
148 
149 protected:
155  void insertFromMimeData(const QMimeData* source) override;
156 
161  void paintEvent(QPaintEvent* e) override;
162 
168  void resizeEvent(QResizeEvent* e) override;
169 
179  void keyPressEvent(QKeyEvent* e) override;
180 
186  void focusInEvent(QFocusEvent *e) override;
187 
188 private:
189 
195 
200  void initFont();
201 
206  void performConnections();
207 
212  void handleSelectionQuery(QTextCursor cursor);
213 
217  void updateLineGeometry();
218 
225  bool proceedCompleterBegin(QKeyEvent *e);
226  void proceedCompleterEnd(QKeyEvent* e);
227 
233  QChar charUnderCursor(int offset = 0) const;
234 
240  QString wordUnderCursor() const;
241 
247 
253 
259  int getIndentationSpaces();
260 
264  QCompleter* m_completer;
265 
267 
271  QString m_tabReplace;
272 };
273 
void focusInEvent(QFocusEvent *e) override
Method, that&#39;s called on focus into widget. It&#39;s required for setting this widget to set completer...
int tabReplaceSize() const
Method for getting number of spaces, that will replace tab if tabReplace is true. Default: 4...
QStyleSyntaxHighlighter * m_highlighter
void initDocumentLayoutHandlers()
Method for initializing document layout handlers.
Definition: QCodeEditor.cpp:50
bool autoIndentation() const
Method for getting is auto indentation enabled. Default: true.
QCompleter * completer() const
Method for getting completer.
Class, that describes line number area widget.
XmlRpcServer s
void onSelectionChanged()
Slot, that will be called on selection change.
QString wordUnderCursor() const
Method for getting word under cursor.
void setCompleter(QCompleter *completer)
Method for setting completer.
bool tabReplace() const
Method for getting is tab replacing enabled. Default value: true.
bool autoParentheses() const
Method for getting is auto parentheses enabled. Default value: true.
void paintEvent(QPaintEvent *e) override
Method, that&#39;s called on editor painting. This method if overloaded for line number area redraw...
void proceedCompleterEnd(QKeyEvent *e)
QCodeEditor(QWidget *widget=nullptr)
Constructor.
Definition: QCodeEditor.cpp:31
bool m_autoIndentation
void highlightCurrentLine(QList< QTextEdit::ExtraSelection > &extraSelection)
Method, that adds highlighting of currently selected line to extra selection list.
void setTabReplace(bool enabled)
Method for setting tab replacing enabled.
void updateLineNumberAreaWidth(int)
Slot, that performs update of internal editor viewport based on line number area width.
QString m_tabReplace
void setTabReplaceSize(int val)
Method for setting amount of spaces, that will replace tab.
QCompleter * m_completer
QCodeEditor & operator=(const QCodeEditor &)=delete
Class, that describes Qt style parser for QCodeEditor.
void setHighlighter(QStyleSyntaxHighlighter *highlighter)
Method for setting highlighter.
Definition: QCodeEditor.cpp:99
QChar charUnderCursor(int offset=0) const
Method for getting character under cursor.
void keyPressEvent(QKeyEvent *e) override
Method, that&#39;s called on any key press, posted into code editor widget. This method is overloaded for...
Class, that descrubes highlighter with syntax style.
void insertFromMimeData(const QMimeData *source) override
Method, that&#39;s called on any text insertion of mimedata into editor. If it&#39;s text - it inserts text a...
const char * source
Definition: lz4.h:699
QFramedTextAttribute * m_framedAttribute
int getFirstVisibleBlock()
Method for getting first visible block index.
void updateStyle()
Slot, that will update editor style.
void updateLineGeometry()
Method for updating geometry of line number area.
void initFont()
Method for initializing default monospace font.
Definition: QCodeEditor.cpp:60
void highlightParenthesis(QList< QTextEdit::ExtraSelection > &extraSelection)
Method, that adds highlighting of parenthesis if available.
void updateExtraSelection()
Slot, that will proceed extra selection for current cursor position.
void insertCompletion(QString s)
Slot, that performs insertion of completion info into code.
void setAutoParentheses(bool enabled)
Method setting auto parentheses enabled.
QSyntaxStyle * m_syntaxStyle
int getIndentationSpaces()
Method for getting number of indentation spaces in current line. Tabs will be treated as tabWidth / s...
QLineNumberArea * m_lineNumberArea
bool m_autoParentheses
void updateLineNumberArea(const QRect &rect)
Slot, that performs update of some part of line number area.
void resizeEvent(QResizeEvent *e) override
Method, that&#39;s called on any widget resize. This method if overloaded for line number area resizing...
void setSyntaxStyle(QSyntaxStyle *style)
Method for setting syntax sty.e.
bool proceedCompleterBegin(QKeyEvent *e)
Method, that performs completer processing. Returns true if event has to be dropped.
void performConnections()
Method for performing connection of objects.
Definition: QCodeEditor.cpp:69
Class, that describes code editor.
Definition: QCodeEditor.hpp:15
void handleSelectionQuery(QTextCursor cursor)
Method, that performs selection frame selection.
void setAutoIndentation(bool enabled)
Method for setting auto indentation enabled.
Class, that describes attribute for making text frame.


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:38