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 
QCodeEditor::initDocumentLayoutHandlers
void initDocumentLayoutHandlers()
Method for initializing document layout handlers.
Definition: QCodeEditor.cpp:50
QCodeEditor::handleSelectionQuery
void handleSelectionQuery(QTextCursor cursor)
Method, that performs selection frame selection.
Definition: QCodeEditor.cpp:235
QCodeEditor::onSelectionChanged
void onSelectionChanged()
Slot, that will be called on selection change.
Definition: QCodeEditor.cpp:165
QLineNumberArea
Class, that describes line number area widget.
Definition: QLineNumberArea.hpp:12
QCodeEditor::autoIndentation
bool autoIndentation() const
Method for getting is auto indentation enabled. Default: true.
QCodeEditor::completer
QCompleter * completer() const
Method for getting completer.
QCodeEditor::tabReplace
bool tabReplace() const
Method for getting is tab replacing enabled. Default value: true.
s
XmlRpcServer s
QCodeEditor::wordUnderCursor
QString wordUnderCursor() const
Method for getting word under cursor.
QCodeEditor::focusInEvent
void focusInEvent(QFocusEvent *e) override
Method, that's called on focus into widget. It's required for setting this widget to set completer.
QCodeEditor::paintEvent
void paintEvent(QPaintEvent *e) override
Method, that's called on editor painting. This method if overloaded for line number area redraw.
Definition: QCodeEditor.cpp:372
QList
Definition: qwt_abstract_legend.h:17
QCodeEditor::m_autoIndentation
bool m_autoIndentation
Definition: QCodeEditor.hpp:268
QCodeEditor::highlightCurrentLine
void highlightCurrentLine(QList< QTextEdit::ExtraSelection > &extraSelection)
Method, that adds highlighting of currently selected line to extra selection list.
Definition: QCodeEditor.cpp:356
QFramedTextAttribute
Class, that describes attribute for making text frame.
Definition: QFramedTextAttribute.hpp:13
QCodeEditor::setCompleter
void setCompleter(QCompleter *completer)
Method for setting completer.
QCodeEditor::charUnderCursor
QChar charUnderCursor(int offset=0) const
Method for getting character under cursor.
QCodeEditor::updateLineNumberAreaWidth
void updateLineNumberAreaWidth(int)
Slot, that performs update of internal editor viewport based on line number area width.
Definition: QCodeEditor.cpp:214
QCodeEditor::proceedCompleterEnd
void proceedCompleterEnd(QKeyEvent *e)
Definition: QCodeEditor.cpp:438
QCodeEditor::insertFromMimeData
void insertFromMimeData(const QMimeData *source) override
Method, that's called on any text insertion of mimedata into editor. If it's text - it inserts text a...
QCodeEditor::autoParentheses
bool autoParentheses() const
Method for getting is auto parentheses enabled. Default value: true.
QCodeEditor::initFont
void initFont()
Method for initializing default monospace font.
Definition: QCodeEditor.cpp:60
QCodeEditor::operator=
QCodeEditor & operator=(const QCodeEditor &)=delete
QCodeEditor::setAutoParentheses
void setAutoParentheses(bool enabled)
Method setting auto parentheses enabled.
QCodeEditor::m_tabReplace
QString m_tabReplace
Definition: QCodeEditor.hpp:271
QCodeEditor::QCodeEditor
QCodeEditor(QWidget *widget=nullptr)
Constructor.
Definition: QCodeEditor.cpp:31
QCodeEditor::getFirstVisibleBlock
int getFirstVisibleBlock()
Method for getting first visible block index.
Definition: QCodeEditor.cpp:378
QCodeEditor::updateStyle
void updateStyle()
Slot, that will update editor style.
Definition: QCodeEditor.cpp:130
source
const char * source
Definition: lz4.h:767
QCodeEditor::highlightParenthesis
void highlightParenthesis(QList< QTextEdit::ExtraSelection > &extraSelection)
Method, that adds highlighting of parenthesis if available.
Definition: QCodeEditor.cpp:259
QCodeEditor::setHighlighter
void setHighlighter(QStyleSyntaxHighlighter *highlighter)
Method for setting highlighter.
Definition: QCodeEditor.cpp:99
QCodeEditor::setTabReplace
void setTabReplace(bool enabled)
Method for setting tab replacing enabled.
QStyleSyntaxHighlighter
Class, that descrubes highlighter with syntax style.
Definition: QStyleSyntaxHighlighter.hpp:12
QCodeEditor::setTabReplaceSize
void setTabReplaceSize(int val)
Method for setting amount of spaces, that will replace tab.
QCodeEditor::m_completer
QCompleter * m_completer
Definition: QCodeEditor.hpp:264
QSyntaxStyle
Class, that describes Qt style parser for QCodeEditor.
Definition: QSyntaxStyle.hpp:13
QCodeEditor::m_framedAttribute
QFramedTextAttribute * m_framedAttribute
Definition: QCodeEditor.hpp:266
QCodeEditor::performConnections
void performConnections()
Method for performing connection of objects.
Definition: QCodeEditor.cpp:69
QCodeEditor::m_autoParentheses
bool m_autoParentheses
Definition: QCodeEditor.hpp:269
QCodeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
Method, that's called on any key press, posted into code editor widget. This method is overloaded for...
QCodeEditor::updateLineNumberArea
void updateLineNumberArea(const QRect &rect)
Slot, that performs update of some part of line number area.
Definition: QCodeEditor.cpp:219
QCodeEditor::setSyntaxStyle
void setSyntaxStyle(QSyntaxStyle *style)
Method for setting syntax sty.e.
Definition: QCodeEditor.cpp:115
QCodeEditor::resizeEvent
void resizeEvent(QResizeEvent *e) override
Method, that's called on any widget resize. This method if overloaded for line number area resizing.
Definition: QCodeEditor.cpp:195
QCodeEditor::updateLineGeometry
void updateLineGeometry()
Method for updating geometry of line number area.
Definition: QCodeEditor.cpp:202
QCodeEditor::getIndentationSpaces
int getIndentationSpaces()
Method for getting number of indentation spaces in current line. Tabs will be treated as tabWidth / s...
QCodeEditor::insertCompletion
void insertCompletion(QString s)
Slot, that performs insertion of completion info into code.
QCodeEditor::updateExtraSelection
void updateExtraSelection()
Slot, that will proceed extra selection for current cursor position.
Definition: QCodeEditor.cpp:249
QCodeEditor::m_syntaxStyle
QSyntaxStyle * m_syntaxStyle
Definition: QCodeEditor.hpp:262
QCodeEditor::proceedCompleterBegin
bool proceedCompleterBegin(QKeyEvent *e)
Method, that performs completer processing. Returns true if event has to be dropped.
Definition: QCodeEditor.cpp:412
QCodeEditor::m_replaceTab
bool m_replaceTab
Definition: QCodeEditor.hpp:270
QCodeEditor::m_lineNumberArea
QLineNumberArea * m_lineNumberArea
Definition: QCodeEditor.hpp:263
QCodeEditor::setAutoIndentation
void setAutoIndentation(bool enabled)
Method for setting auto indentation enabled.
QCodeEditor::tabReplaceSize
int tabReplaceSize() const
Method for getting number of spaces, that will replace tab if tabReplace is true. Default: 4.
QCodeEditor
Class, that describes code editor.
Definition: QCodeEditor.hpp:15
QCodeEditor::m_highlighter
QStyleSyntaxHighlighter * m_highlighter
Definition: QCodeEditor.hpp:261


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45