-
Notifications
You must be signed in to change notification settings - Fork 6
/
mainwindow.h
124 lines (95 loc) · 2.08 KB
/
mainwindow.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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPlainTextEdit>
#include<highlighter.h>
#include <QtWidgets>
#include "previewpage.h"
#include <QWebEngineView>
#include "document.h"
QT_BEGIN_NAMESPACE
class QPaintEvent;
class QResizeEvent;
class QSize;
class QWidget;
QT_END_NAMESPACE
class LineNumberArea;
class CodeEditor;
class Preview;
class Home: public QMainWindow
{
Q_OBJECT
public:
Home();
void undo();
void redo();
void copy();
void paste();
QMenu *menuView;
private slots:
void updateLengthAndLine();
void saveFile();
void newFile();
void quit();
void handleMenuView();
void about();
void checkUpdate();
private:
CodeEditor *codeEditor;
Highlighter *highlighter;
Preview *preview;
Document m_content;
void createMenu();
void openFileSlot();
// 状态栏文本
QLabel *label;
QLabel *textType;
QLabel *codeLength;
QLabel *codeLines;
};
class CodeEditor : public QPlainTextEdit
{
Q_OBJECT
public:
CodeEditor(Home *parent = 0);
void init();
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
int getFirstVisibleBlockId();
QWidget *lineNumberArea;
QString fileName;
bool isChanged;
protected:
void resizeEvent(QResizeEvent *event) override;
public slots:
void updateLineNumberAreaWidth(int newBolckCount);
void hightlightCurrentLine();
void updateLineNumberArea(const QRect &, int);
void hideLineNumber();
private:
Home *home;
};
class LineNumberArea : public QWidget
{
public:
LineNumberArea(CodeEditor *mainWindow) : QWidget(mainWindow){
this->mainWindow = mainWindow;
}
QSize sizeHint() const override {
return QSize(mainWindow-> lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) override {
mainWindow->lineNumberAreaPaintEvent(event);
}
private:
CodeEditor *mainWindow;
};
class Preview : public QWebEngineView
{
public:
Preview(Home *parent);
private:
Home *home;
};
#endif // MAINWINDOW_H