forked from Seigishi/MyNotepad
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
92 lines (78 loc) · 2.57 KB
/
mainwindow.cpp
File metadata and controls
92 lines (78 loc) · 2.57 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore>
#include <QtGui>
#include <QFileDialog>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionNew_triggered()
{
if(not_saved){
int x=QMessageBox::question(this,"Save Changes","Do you wish to save your file",QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
if(x==QMessageBox::Yes){
on_actionSave_triggered();
ui->statusBar->showMessage("New form created",1500);
not_saved=0;
}else if(x==QMessageBox::No){
ui->plainTextEdit->setPlainText("");
ui->statusBar->showMessage("New form created",1500);
not_saved=0;
}
}else{
ui->statusBar->showMessage("You haven't added anything",2000);
}
}
void MainWindow::on_actionOpen_triggered()
{
if(not_saved){
int x=QMessageBox::question(this,"Save Changes","Do you wish to save your file",QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
if(x==QMessageBox::Yes){
on_actionSave_triggered();
ui->statusBar->showMessage("New form created",1500);
not_saved=0;
}else if(x==QMessageBox::No){
ui->plainTextEdit->setPlainText("");
ui->statusBar->showMessage("New form created",1500);
not_saved=0;
}
}
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Text"), "",
tr("Text file (*.txt);;All Files (*)"));
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString txt;
QTextStream in(&file);
in.setAutoDetectUnicode(true);
ui->plainTextEdit->setPlainText(in.readAll());
ui->statusBar->showMessage("Form opened",1500);
}
void MainWindow::on_actionSave_triggered()
{
qDebug()<<"check";
QString txt = ui->plainTextEdit->toPlainText().toLatin1();
ui->statusBar->showMessage("Form Saved",1500);
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save file"), "",
tr("Text File (*.txt);;All Files (*)"));
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
out << txt;
qDebug()<<"Check Completed";
}
void MainWindow::on_plainTextEdit_textChanged()
{
not_saved =1;
}