| 1 | /* |
| 2 | * File: FreeConfigurationEditor.h |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Apr 19, 2011 |
| 6 | * |
| 7 | * Copyright (c) 2011 Jacob Dekel. |
| 8 | * Adapted from Nokia sample CodeEditor - |
| 9 | * (Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)) |
| 10 | * $Id: TerminalProperties.h 67 2010-09-13 14:06:31Z dekeljacob $ |
| 11 | * |
| 12 | * This object manages the terminal configuration properties |
| 13 | * |
| 14 | * This program is free software: you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation, either version 3 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #ifndef FREECONFIGURATIONEDITOR_H |
| 30 | #define FREECONFIGURATIONEDITOR_H |
| 31 | |
| 32 | #include <QPlainTextEdit> |
| 33 | |
| 34 | class ConfigurationFreeEditor : public QPlainTextEdit |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | public: |
| 38 | explicit ConfigurationFreeEditor(QWidget *parent = 0); |
| 39 | void lineNumberAreaPaintEvent(QPaintEvent *event); |
| 40 | int lineNumberAreaWidth(); |
| 41 | |
| 42 | protected: |
| 43 | void resizeEvent(QResizeEvent *event); |
| 44 | |
| 45 | private slots: |
| 46 | void updateLineNumberAreaWidth(int newBlockCount); |
| 47 | void highlightCurrentLine(); |
| 48 | void updateLineNumberArea(const QRect &, int); |
| 49 | |
| 50 | private: |
| 51 | QWidget *mLineNumberArea; |
| 52 | }; |
| 53 | |
| 54 | class LineNumberArea : public QWidget |
| 55 | { |
| 56 | public: |
| 57 | LineNumberArea(ConfigurationFreeEditor *editor) : QWidget(editor) { |
| 58 | freeConfigurationEditor = editor; |
| 59 | } |
| 60 | |
| 61 | QSize sizeHint() const { |
| 62 | return QSize(freeConfigurationEditor->lineNumberAreaWidth(), 0); |
| 63 | } |
| 64 | |
| 65 | protected: |
| 66 | void paintEvent(QPaintEvent *event) { |
| 67 | freeConfigurationEditor->lineNumberAreaPaintEvent(event); |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | ConfigurationFreeEditor *freeConfigurationEditor; |
| 72 | }; |
| 73 | |
| 74 | #endif // FREECONFIGURATIONEDITOR_H |