pgLab/pglab/codeeditor/CodeEditor.h
2022-04-10 09:26:38 +02:00

55 lines
1.1 KiB
C++

#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include <QPlainTextEdit>
#include <set>
/** This class adds some capabilities to QPlainTextEdit that are useful
* in code editor scenarios.
*/
class CodeEditor : public QPlainTextEdit
{
Q_OBJECT
public:
explicit CodeEditor(QWidget *parent = nullptr);
void gutterAreaPaintEvent(QPaintEvent *event);
int gutterAreaWidth();
void addErrorMarker(int position, int length);
void clearErrorMarkers();
void setFont(const QFont &);
void setTabSize(int chars);
protected:
void resizeEvent(QResizeEvent *event) override;
void keyPressEvent(QKeyEvent *e) override;
signals:
public slots:
private slots:
void updateGutterAreaWidth(int newBlockCount);
void highlightCurrentLine();
void updateGutterArea(const QRect &, int);
void onTextChanged();
private:
QWidget *gutterArea;
QTextEdit::ExtraSelection currentLine;
QList<QTextEdit::ExtraSelection> errorMarkers;
std::set<int> errorLines;
// Settings
int m_tabSize = 0; // tabSize in characters
bool m_useTab = false;
void updateExtraSelections();
bool indentSelection(bool indent);
};
#endif // CODEEDITOR_H