-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathznotepad.cpp
More file actions
103 lines (77 loc) · 1.95 KB
/
Copy pathznotepad.cpp
File metadata and controls
103 lines (77 loc) · 1.95 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
#include "zNotepad.h"
#include "ui_znotepad.h"
zNotepad::zNotepad(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::zNotepad)
{
ui->setupUi(this);
this->setCentralWidget(ui->textEdit);
}
zNotepad::~zNotepad()
{
delete ui;
}
void zNotepad::on_actionNew_triggered()
{
currentFile.clear();
ui->textEdit->setText(QString());
}
void zNotepad::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", "unable to open file", file.errorString());
return;
}
setWindowTitle(filename);
QTextStream in(&file);
QString text = in.readAll();
ui->textEdit->setText(text);
file.close();
}
void zNotepad::on_actionSave_As_triggered()
{
QString filename = QFileDialog::getSaveFileName(this, "Save As");
QFile file(filename);
currentFile = filename;
if(!file.open(QIODevice::WriteOnly | QFile::Text)){
QMessageBox::warning(this, "warning", "unable to open file", file.errorString());
return;
}
setWindowTitle(filename);
currentFile = filename;
QTextStream out(&file);
QString text = out.readAll();
ui->textEdit->toPlainText();
out<< text;
file.close();
}
void zNotepad::on_actionExit_triggered()
{
QApplication::exit();
}
void zNotepad::on_actionCut_triggered()
{
ui->textEdit->cut();
}
void zNotepad::on_actionCopy_triggered()
{
ui->textEdit->copy();
}
void zNotepad::on_actionPaste_triggered()
{
ui->textEdit->paste();
}
void zNotepad::on_actionprint_triggered()
{
QPrinter printer;
printer.setPrinterName("Printer Name");
QPrintDialog pDialog(&printer, this);
if(pDialog.exec() == QDialog::Rejected){
QMessageBox::warning(this, "warning", "cannot access printer");
return;
}
ui->textEdit->print(&printer);
}