Debian Codegraph @

codeeditor.h

raw symbols SCIP
1 /****************************************************************************
2 ** SASM - simple IDE for assembler development
3 ** Copyright (C) 2013 Dmitriy Manushin
4 ** Contact: site: http://dman95.github.io/SASM/
5 ** e-mail: [email protected]
6 **
7 ** This file is part of SASM.
8 **
9 ** SASM is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation, either version 3 of the License, or
12 ** (at your option) any later version.
13 **
14 ** SASM is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with SASM. If not, see <http://www.gnu.org/licenses/>.
21 **
22 ** Этот файл — часть SASM.
23 **
24 ** SASM - свободная программа: вы можете перераспространять ее и/или
25 ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде,
26 ** в каком она была опубликована Фондом свободного программного обеспечения;
27 ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
28 ** версии.
29 **
30 ** SASM распространяется в надежде, что она будет полезной,
31 ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
32 ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
33 ** общественной лицензии GNU.
34 **
35 ** Вы должны были получить копию Стандартной общественной лицензии GNU
36 ** вместе с этой программой. Если это не так, см.
37 ** <http://www.gnu.org/licenses/>.)
38 **
39 ****************************************************************************/
40
41 #ifndef CODEEDITOR_H
42 #define CODEEDITOR_H
43
44 #include <QPainter>
45 #include <QTextBlock>
46 #include <QScrollBar>
47 #include <QDragEnterEvent>
48 #include <QDropEvent>
49 #include <QMimeData>
50 #include "ruqplaintextedit.h"
51 #include <QUrl>
52
53 /**
54 * @file codeeditor.h
55 * Contains definitions for objects pertaining to the code editing section
56 */
57
58 QT_BEGIN_NAMESPACE
59 class QPaintEvent;
60 class QResizeEvent;
61 class QSize;
62 class QWidget;
63 QT_END_NAMESPACE
64
65 class LineNumberArea;
66
67
68 class CodeEditor : public RuQPlainTextEdit
69 {
70 Q_OBJECT
71
72 public:
73 CodeEditor(QWidget *parent = 0, bool withBeakpoints = true);
74 ~CodeEditor();
75
76 void lineNumberAreaPaintEvent(QPaintEvent *event);
77 void lineNumberAreaMousePressEvent(QMouseEvent *event);
78 int lineNumberAreaWidth();
79 void repaintLineNumberArea();
80 bool isMacroOnCurrentDebugLine();
81 int currentDebugLine;
82 bool debugMode;
83
84 public slots:
85 void updateDebugLine(int number);
86 void putTab();
87 void deleteTab();
88 void highlightCurrentLine();
89 void highlightDebugLine(int lineNumber, bool moveCursor);
90 void setDebugMode(bool mode);
91 QList<int> *getBreakpoints();
92 void setBreakpointOnCurrentLine();
93
94 protected:
95 void resizeEvent(QResizeEvent *event);
96 void keyPressEvent(QKeyEvent *e);
97
98 void dragEnterEvent(QDragEnterEvent *event);
99 void dropEvent(QDropEvent *event);
100
101 private slots:
102 void updateLineNumberAreaWidth(int newBlockCount);
103 void updateLineNumberArea(const QRect &, int);
104 void shiftBreakpoints(int blockCount);
105
106 private:
107 QWidget *lineNumberArea;
108 int debugAreaWidth;
109 QPixmap debugImage;
110 QPixmap breakpointImage;
111 //! Breakpoint line numbers
112 QList<int> breakpoints;
113 int firstTopMargin;
114 bool hasBreakpoints;
115 int prevBlockCount;
116 QSettings settings;
117 QColor lineNumberPanelColor;
118
119 signals:
120 void breakpointsChanged(quint64 lineNumber, bool isAdded);
121 void fileOpened(QString path);
122 };
123
124
125 class LineNumberArea : public QWidget
126 {
127 public:
128 LineNumberArea(CodeEditor *editor) : QWidget(editor) {
129 codeEditor = editor;
130 }
131
132 QSize sizeHint() const {
133 return QSize(codeEditor->lineNumberAreaWidth(), 0);
134 }
135
136 protected:
137 void paintEvent(QPaintEvent *event) {
138 codeEditor->lineNumberAreaPaintEvent(event);
139 }
140 void mousePressEvent(QMouseEvent *event) {
141 codeEditor->lineNumberAreaMousePressEvent(event);
142 }
143
144 private:
145 CodeEditor *codeEditor;
146 };
147
148 #endif