File indexing completed on 2024-05-12 17:11:40
0001 /*************************************************************************** 0002 * Copyright (C) 2016 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef RCSE_CODEEDITOR_H 0021 #define RCSE_CODEEDITOR_H 0022 0023 #include <QObject> 0024 #include <QPlainTextEdit> 0025 0026 class QPaintEvent; 0027 class QResizeEvent; 0028 class QSize; 0029 class QWidget; 0030 0031 class LineNumberArea; 0032 0033 class CodeEditor : public QPlainTextEdit 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 CodeEditor(QWidget* parent= nullptr); 0039 0040 void lineNumberAreaPaintEvent(QPaintEvent* event); 0041 int lineNumberAreaWidth(); 0042 0043 protected: 0044 void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE; 0045 0046 private slots: 0047 void updateLineNumberAreaWidth(int newBlockCount); 0048 void highlightCurrentLine(); 0049 void updateLineNumberArea(const QRect&, int); 0050 0051 private: 0052 QWidget* lineNumberArea; 0053 }; 0054 0055 class LineNumberArea : public QWidget 0056 { 0057 public: 0058 LineNumberArea(CodeEditor* editor) : QWidget(editor) { codeEditor= editor; } 0059 0060 QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(codeEditor->lineNumberAreaWidth(), 0); } 0061 0062 protected: 0063 void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE { codeEditor->lineNumberAreaPaintEvent(event); } 0064 0065 private: 0066 CodeEditor* codeEditor; 0067 }; 0068 0069 #endif // RCSE_CODEEDITOR_H