2017-09-16 16:04:29 +03:00
|
|
|
#ifndef LRCODEEDITOR_H
|
|
|
|
#define LRCODEEDITOR_H
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrscripthighlighter.h"
|
|
|
|
|
2017-09-16 16:04:29 +03:00
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QWidget;
|
|
|
|
class QCompleter;
|
|
|
|
class QKeyEvent;
|
|
|
|
class QScrollBar;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
namespace LimeReport {
|
2017-09-16 16:04:29 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
class CodeEditor: public QPlainTextEdit {
|
2017-09-16 16:04:29 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
CodeEditor(QWidget* parent = 0);
|
2017-09-16 16:04:29 +03:00
|
|
|
void setCompleter(QCompleter* value);
|
2024-09-04 17:31:16 +03:00
|
|
|
QCompleter* compleater() const { return m_completer; }
|
|
|
|
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
2017-09-16 16:04:29 +03:00
|
|
|
int lineNumberAreaWidth();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
2017-09-16 16:04:29 +03:00
|
|
|
protected:
|
2024-09-04 17:31:16 +03:00
|
|
|
void keyPressEvent(QKeyEvent* e);
|
|
|
|
void focusInEvent(QFocusEvent* e);
|
|
|
|
void resizeEvent(QResizeEvent* event);
|
|
|
|
|
2017-09-16 16:04:29 +03:00
|
|
|
private:
|
|
|
|
QString textUnderCursor() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
bool matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i,
|
|
|
|
int numLeftParentheses);
|
|
|
|
bool matchRightParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i,
|
|
|
|
int numRightParentheses);
|
|
|
|
void createParenthesisSelection(int pos);
|
|
|
|
bool charIsParenthesis(QChar character, ParenthesisType type);
|
|
|
|
QChar getParenthesisReverceChar(QChar parenthesisChar);
|
2017-09-16 16:04:29 +03:00
|
|
|
private slots:
|
|
|
|
void insertCompletion(const QString& completion);
|
|
|
|
void updateLineNumberAreaWidth(int newBlockCount);
|
|
|
|
void highlightCurrentLine();
|
2024-09-04 17:31:16 +03:00
|
|
|
void updateLineNumberArea(const QRect& rect, int dy);
|
2017-09-19 19:05:38 +03:00
|
|
|
void matchParentheses();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
2017-09-16 16:04:29 +03:00
|
|
|
private:
|
2021-11-03 00:40:16 +03:00
|
|
|
QCompleter* m_completer;
|
2024-09-04 17:31:16 +03:00
|
|
|
QWidget* lineNumberArea;
|
2017-09-16 16:04:29 +03:00
|
|
|
};
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
class LineNumberArea: public QWidget {
|
2017-09-16 16:04:29 +03:00
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
LineNumberArea(CodeEditor* editor): QWidget(editor) { codeEditor = editor; }
|
2017-09-16 16:04:29 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QSize sizeHint() const { return QSize(codeEditor->lineNumberAreaWidth(), 0); }
|
2017-09-16 16:04:29 +03:00
|
|
|
|
|
|
|
protected:
|
2024-09-04 17:31:16 +03:00
|
|
|
void paintEvent(QPaintEvent* event) { codeEditor->lineNumberAreaPaintEvent(event); }
|
2017-09-16 16:04:29 +03:00
|
|
|
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
CodeEditor* codeEditor;
|
2017-09-16 16:04:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace LimeReport
|
|
|
|
|
|
|
|
#endif // LRCODEEDITOR_H
|