-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
227 lines (173 loc) · 4.48 KB
/
mainwindow.cpp
File metadata and controls
227 lines (173 loc) · 4.48 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QFont>
#include "aboutwindow.h"
#include "helpwindow.h"
#include <QTextLayout>
#include <QStringList>
#include <QTextBrowser>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->isUntitle = true;
this->isModified = false;
this->findwindowCreated = false; //wfind是否被创建
this->path = tr("Untitled.txt");
this->tempPath = tr("C:/Users");
this->setWindowTitle(MainWindow::Title);
this->setWindowIcon(QIcon(":/icon/MAIN2"));
this->ini_init();
this->edit_init();
ui->textEdit->setLineWrapMode(QTextEdit::NoWrap); //默认不换行
connect(ui->textEdit->document(), SIGNAL(modificationChanged(bool)), SLOT(isChanged(bool)));
connect(this, &MainWindow::Send_cursor_position, this, &MainWindow::Show_cursor_position);
// this->timer = new QTimer;
// this->filewatcher = new QFileSystemWatcher;
// this->filewatcher->addPath(this->path);
// this->timer->start(600);
}
MainWindow::~MainWindow()
{
this->change_ini();
if(this->findwindowCreated)
delete wfind;
delete ui;
// delete timer;
// delete filewatcher;
}
void MainWindow::on_actionOpen_O_triggered()
{
this->openFile();
}
void MainWindow::on_actiontuichu_triggered()
{
close();
}
//close window
void MainWindow::closeEvent(QCloseEvent *event)
{
qDebug() << this->isModified;
if(this->isModified)
{
QMessageBox::StandardButton btn = QMessageBox::warning(this, MainWindow::Title, tr("The file has been changed, save or not?\n") + (this->path), QMessageBox::Yes | QMessageBox::Cancel | QMessageBox::No, QMessageBox::Yes);
if(btn == QMessageBox::Cancel)
{
event->ignore();
}
else if(btn == QMessageBox::Yes)
{
if(!this->saveFile())
{
event->ignore();
}
}
else
{
event->accept();
}
}
}
void MainWindow::on_actionNew_N_triggered()
{
this->newFile();
}
void MainWindow::on_actionSave_S_triggered()
{
this->saveFile();
}
void MainWindow::on_action_lingcvunwei_triggered()
{
this->saveAs();
}
void MainWindow::isChanged(bool changed)
{
if(changed)
{
this->setWindowTitle(this->path + tr("*"));
this->isModified = true;
}
else
{
this->setWindowTitle(this->path);
}
}
void MainWindow::on_actionItalic_triggered(bool checked)
{
this->setItalic(checked);
}
void MainWindow::on_actionBold_triggered(bool checked)
{
this->setBold(checked);
}
void MainWindow::on_actionUnderline_triggered(bool checked)
{
this->setUnderline(checked);
}
void MainWindow::on_actionAbout_Notepad_2_triggered()
{
AboutWindow w;
w.exec();
}
void MainWindow::on_actionFind_triggered()
{
this->findwindowCreated = true;
this->findtext();
}
void MainWindow::on_actionHelp_triggered()
{
HelpWindow w;
w.exec();
}
void MainWindow::on_actioncheckline_triggered(bool checked)
{
this->autoCheckLine(checked);
}
void MainWindow::on_actionUndo_U_triggered()
{
}
void MainWindow::get_cursor()
{
this->Cursor = ui->textEdit->textCursor();
emit this->Send_cursor_position(this->Cursor.blockNumber(), this->Cursor.columnNumber());
}
void MainWindow::Show_cursor_position(int b, int c)
{
this->ui->CursorP->setText(tr("行:%1 列:%2").arg(b).arg(c));
this->ui->textEdit->setStatusTip(tr("行:%1 列:%2").arg(b).arg(c));
}
void MainWindow::on_actionfont_2_triggered()
{
this->setFont();
}
void MainWindow::on_actioncolor_triggered()
{
this->setFontColor();
}
void MainWindow::on_actionrun_triggered()
{
qDebug() << "start debug";
QProcess cmd;
// QStringList argument;
// cmd.setProgram("cmd.exe");
// argument << "python " << this->path;
QDialog * output = new QDialog;
QTextBrowser * info = new QTextBrowser(output);
cmd.setArguments(QStringList(tr("python %1").arg(this->path)));
qDebug() << this->path;
// cmd.start("cmd", QStringList() << "python" << QString(this->path));
cmd.start("cmd");
cmd.waitForStarted();
cmd.waitForFinished();
info->setText(QString::fromLocal8Bit(cmd.readAllStandardOutput()));
qDebug() << QString::fromLocal8Bit(cmd.readAllStandardOutput());
info->setVisible(true);
output->show();
// delete output;
// delete info;
}