0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-27 01:48:09 +03:00
LimeReport/limereport/scripteditor/lrcodeeditor.h

72 lines
1.9 KiB
C
Raw Normal View History

2017-09-16 16:04:29 +03:00
#ifndef LRCODEEDITOR_H
#define LRCODEEDITOR_H
#include <QPlainTextEdit>
#include <QSyntaxHighlighter>
2017-09-19 19:05:38 +03:00
#include "lrscripthighlighter.h"
2017-09-16 16:04:29 +03:00
QT_BEGIN_NAMESPACE
class QWidget;
class QCompleter;
class QKeyEvent;
class QScrollBar;
QT_END_NAMESPACE
namespace LimeReport{
class CodeEditor :public QPlainTextEdit
{
Q_OBJECT
public:
CodeEditor(QWidget* parent=0);
void setCompleter(QCompleter* value);
QCompleter* compleater() const{ return m_compleater;}
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
protected:
void keyPressEvent(QKeyEvent *e);
void focusInEvent(QFocusEvent *e);
void resizeEvent(QResizeEvent *event);
private:
QString textUnderCursor() const;
2017-09-19 19:05:38 +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();
void updateLineNumberArea(const QRect &rect, int dy);
2017-09-19 19:05:38 +03:00
void matchParentheses();
2017-09-16 16:04:29 +03:00
private:
QCompleter* m_compleater;
QWidget *lineNumberArea;
};
class LineNumberArea : public QWidget
{
public:
LineNumberArea(CodeEditor *editor) : QWidget(editor) {
codeEditor = editor;
}
QSize sizeHint() const {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) {
codeEditor->lineNumberAreaPaintEvent(event);
}
private:
CodeEditor *codeEditor;
};
} // namespace LimeReport
#endif // LRCODEEDITOR_H