2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2024-02-02 13:36:10 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef CODEEDITOR_H
|
|
|
|
#define CODEEDITOR_H
|
|
|
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QPaintEvent;
|
|
|
|
class QResizeEvent;
|
|
|
|
class QSize;
|
|
|
|
class QWidget;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
class LineNumberArea;
|
|
|
|
|
|
|
|
//![codeeditordefinition]
|
|
|
|
|
|
|
|
class CodeEditor : public QPlainTextEdit
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-12-02 13:11:13 +00:00
|
|
|
CodeEditor(QWidget *parent = nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
|
|
|
int lineNumberAreaWidth();
|
|
|
|
|
|
|
|
protected:
|
2016-06-15 08:12:35 +00:00
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void updateLineNumberAreaWidth(int newBlockCount);
|
|
|
|
void highlightCurrentLine();
|
2019-09-06 20:38:45 +00:00
|
|
|
void updateLineNumberArea(const QRect &rect, int dy);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QWidget *lineNumberArea;
|
|
|
|
};
|
|
|
|
|
|
|
|
//![codeeditordefinition]
|
|
|
|
//![extraarea]
|
|
|
|
|
|
|
|
class LineNumberArea : public QWidget
|
|
|
|
{
|
|
|
|
public:
|
2019-09-06 20:38:45 +00:00
|
|
|
LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor)
|
|
|
|
{}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-09-06 20:38:45 +00:00
|
|
|
QSize sizeHint() const override
|
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
return QSize(codeEditor->lineNumberAreaWidth(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-09-06 20:38:45 +00:00
|
|
|
void paintEvent(QPaintEvent *event) override
|
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
codeEditor->lineNumberAreaPaintEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CodeEditor *codeEditor;
|
|
|
|
};
|
|
|
|
|
|
|
|
//![extraarea]
|
|
|
|
|
|
|
|
#endif
|