-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
118 lines (93 loc) · 2.34 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setCentralWidget(ui->textEdit);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionNew_triggered()
{
currentFile.clear();
ui->textEdit->setPlainText(QString());
}
void MainWindow::on_actionOpen_triggered()
{
QString filename = QFileDialog::getOpenFileName(this, "Open File");
QFile file(filename);
currentFile = filename;
if(!file.open(QIODevice::ReadOnly | QFile::Text)){
QMessageBox::warning(this,"Warning","oop, something went wrong !");
return;
}
setWindowTitle(currentFile);
QTextStream in(&file);
QString text = in.readAll();
ui->textEdit->setPlainText(text);
file.close();
}
void MainWindow::on_actionSave_as_triggered()
{
QString filename = QFileDialog::getSaveFileName(this,"Save file as");
QFile file(filename);
currentFile = filename;
if(!file.open(QFile::WriteOnly | QFile::Text)){
QMessageBox::warning(this,"Warning","oop, something went wrong !");
return;
}
setWindowTitle(currentFile);
QTextStream out(&file);
QString text = ui->textEdit->toPlainText();
out<<text;
file.close();
}
void MainWindow::on_actionCopy_triggered()
{
ui->textEdit->copy();
}
void MainWindow::on_actionPaste_triggered()
{
ui->textEdit->paste();
}
void MainWindow::on_actionCut_triggered()
{
ui->textEdit->cut();
}
void MainWindow::on_actionUndo_triggered()
{
ui->textEdit->undo();
}
void MainWindow::on_actionRedo_triggered()
{
ui->textEdit->redo();
}
void MainWindow::on_actionQuit_triggered()
{
close();
}
void MainWindow::on_actionSave_triggered()
{
QFile file(currentFile);
if(!file.open(QFile::WriteOnly | QFile::Text)){
QMessageBox::warning(this,"Warning","oop, something went wrong !");
return;
}
QTextStream out(&file);
QString text = ui->textEdit->toPlainText();
out<<text;
file.close();
}
void MainWindow::on_actionDark_triggered()
{
ui->textEdit->setStyleSheet("color:white;background-color: rgb(46, 52, 54);");
}
void MainWindow::on_actionLight_triggered()
{
ui->textEdit->setStyleSheet("color:black;background-color:white;");
}