-
Notifications
You must be signed in to change notification settings - Fork 0
/
editbox.h
128 lines (106 loc) · 3.26 KB
/
editbox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// vim:ts=4:sw=4:
//
// Interactive BASIC Compiler Project
// File: editbox.h - edit box class header file
// Copyright (C) 2012-2013 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// For a copy of the GNU General Public License,
// see <http://www.gnu.org/licenses/>.
//
//
// Change History:
//
// 2012-12-29 initial version
#ifndef EDITBOX_H
#define EDITBOX_H
#include <QClipboard>
#include <QPlainTextEdit>
#include <QTextBlock>
#include "errorlist.h"
class QEvent;
class ProgramModel;
class EditBox : public QPlainTextEdit
{
Q_OBJECT
public:
explicit EditBox(ProgramModel *programUnit, QWidget *parent = 0);
void remove(void);
void paste(QClipboard::Mode mode = QClipboard::Clipboard);
void selectAll(void);
void goNextError(void);
void goPrevError(void);
void resetModified(void);
void captureModifiedLine(int offset = 0);
int lineNumber(void) const
{
return textCursor().blockNumber();
}
int column(void) const
{
return textCursor().positionInBlock();
}
int lineNumberWidgetWidth(void);
void lineNumberWidgetPaint(QPaintEvent *event);
protected:
void keyPressEvent(QKeyEvent *event);
void resizeEvent(QResizeEvent *event);
signals:
void cursorChanged(const QString &message);
void errorsAvailable(bool available);
public slots:
void documentChanged(int position, int charsRemoved, int charsAdded);
void cursorMoved(void);
void setPlainText(const QString &text);
void clear(void);
void programChanged(int lineNumber);
private slots:
void errorListChanged(void);
void errorInserted(int errIndex, const ErrorItem &errorItem);
void errorChanged(int errIndex, const ErrorItem &errorItem);
void errorRemoved(int errIndex);
void lineNumberWidgetUpdateWidth(void);
void lineNumberWidgetUpdate(const QRect &rect, int dy);
private:
bool pasteSelection(const QPoint &pos = QPoint());
void moveCursorToLineColumn(int lineNum, int col);
void setCursorFromError(QTextCursor &cursor, const ErrorItem &errorItem);
ProgramModel *m_programUnit; // pointer to program unit being edited
int m_modifiedLine; // current line that has been modified
bool m_modifiedLineIsNew; // modified line is a new line flag
QWidget *m_lineNumberWidget; // widget to display line numbers
int m_lineCount; // total document line count
QList<QTextEdit::ExtraSelection>
m_extraSelections; // error highlight extra selections list
bool m_cursorValid; // flag for when text cursor is valid
bool m_ignoreChange; // ignore change signal flag
};
class LineNumberWidget : public QWidget
{
public:
LineNumberWidget(EditBox *editBox) : QWidget(editBox)
{
m_editBox = editBox;
}
QSize sizeHint() const
{
return QSize(m_editBox->lineNumberWidgetWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event)
{
m_editBox->lineNumberWidgetPaint(event);
}
private:
EditBox *m_editBox;
};
#endif // EDITBOX_H