├── QtNotepad
├── resources.qrc
├── main.cpp
├── mainwindow.h
├── QtNotepad.pro
├── mainwindow.cpp
└── mainwindow.ui
├── .gitignore
├── README.md
└── LICENSE.md
/QtNotepad/resources.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pro.user
2 | *.autosave
3 | build-QtNotepad-Desktop-Debug/
4 | *Release
5 |
--------------------------------------------------------------------------------
/QtNotepad/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QtNotepad
2 | 
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/QtNotepad/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | namespace Ui {
14 | class MainWindow;
15 | }
16 |
17 | class MainWindow : public QMainWindow
18 | {
19 | Q_OBJECT
20 |
21 | public:
22 | explicit MainWindow(QWidget *parent = 0);
23 | ~MainWindow();
24 |
25 | private slots:
26 | void on_actionNew_triggered();
27 |
28 | void on_actionOpen_triggered();
29 |
30 | void on_actionSave_As_triggered();
31 |
32 | void on_actionPrint_triggered();
33 |
34 | void on_actionExit_triggered();
35 |
36 | void on_actionCopy_triggered();
37 |
38 | void on_actionPaste_triggered();
39 |
40 | void on_actionCut_triggered();
41 |
42 | void on_actionUndo_triggered();
43 |
44 | void on_actionRedo_triggered();
45 |
46 | private:
47 | Ui::MainWindow *ui;
48 | QString currentFile = "";
49 | };
50 |
51 | #endif // MAINWINDOW_H
52 |
--------------------------------------------------------------------------------
/QtNotepad/QtNotepad.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2019-02-09T18:00:20
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui printsupport
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = QtNotepad
12 | TEMPLATE = app
13 |
14 | # The following define makes your compiler emit warnings if you use
15 | # any feature of Qt which has been marked as deprecated (the exact warnings
16 | # depend on your compiler). Please consult the documentation of the
17 | # deprecated API in order to know how to port your code away from it.
18 | DEFINES += QT_DEPRECATED_WARNINGS
19 |
20 | # You can also make your code fail to compile if you use deprecated APIs.
21 | # In order to do so, uncomment the following line.
22 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24 |
25 |
26 | SOURCES += \
27 | main.cpp \
28 | mainwindow.cpp
29 |
30 | HEADERS += \
31 | mainwindow.h
32 |
33 | FORMS += \
34 | mainwindow.ui
35 |
36 | RESOURCES += \
37 | resources.qrc
38 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
25 |
--------------------------------------------------------------------------------
/QtNotepad/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent) :
5 | QMainWindow(parent),
6 | ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | this->setCentralWidget(ui->textEdit);
10 | }
11 |
12 | MainWindow::~MainWindow()
13 | {
14 | delete ui;
15 | }
16 |
17 | void MainWindow::on_actionNew_triggered()
18 | {
19 | currentFile.clear();
20 | ui->textEdit->setText(QString());
21 | }
22 |
23 | void MainWindow::on_actionOpen_triggered()
24 | {
25 | QString fileName = QFileDialog::getOpenFileName(this,"Open file");
26 | QFile file(fileName);
27 | currentFile = fileName;
28 | if(!file.open(QIODevice::ReadOnly | QFile::Text)){
29 | QMessageBox::warning(this, "Warning", "Cannot open file : " + file.errorString());
30 | return;
31 | }
32 | setWindowTitle(fileName);
33 | QTextStream in(&file);
34 | QString text = in.readAll();
35 | ui->textEdit->setText(text);
36 | file.close();
37 | }
38 |
39 | void MainWindow::on_actionSave_As_triggered()
40 | {
41 | QString fileName = QFileDialog::getSaveFileName(this, "Save as ");
42 | QFile file(fileName);
43 | if(!file.open(QFile::WriteOnly | QFile::Text)){
44 | QMessageBox::warning(this, "Warning", "Cannot save file : " + file.errorString());
45 | return;
46 | }
47 | currentFile = fileName;
48 | setWindowTitle(fileName);
49 | QTextStream out(&file);
50 | QString text = ui->textEdit->toPlainText();
51 | out << text;
52 | file.close();
53 | }
54 |
55 | void MainWindow::on_actionPrint_triggered()
56 | {
57 | QPrinter printer;
58 | printer.setPrinterName("Printer Name");
59 | QPrintDialog pDialog(&printer, this);
60 | if(pDialog.exec() == QDialog::Rejected){
61 | QMessageBox::warning(this, "Warning", "Cannot access printer");
62 | return;
63 | }
64 | ui->textEdit->print(&printer);
65 | }
66 |
67 | void MainWindow::on_actionExit_triggered()
68 | {
69 | QApplication::quit();
70 | }
71 |
72 | void MainWindow::on_actionCopy_triggered()
73 | {
74 | ui->textEdit->copy();
75 | }
76 |
77 | void MainWindow::on_actionPaste_triggered()
78 | {
79 | ui->textEdit->paste();
80 | }
81 |
82 | void MainWindow::on_actionCut_triggered()
83 | {
84 | ui->textEdit->cut();
85 | }
86 |
87 | void MainWindow::on_actionUndo_triggered()
88 | {
89 | ui->textEdit->undo();
90 | }
91 |
92 | void MainWindow::on_actionRedo_triggered()
93 | {
94 | ui->textEdit->redo();
95 | }
96 |
--------------------------------------------------------------------------------
/QtNotepad/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 516
10 | 288
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 9
21 | 9
22 | 501
23 | 211
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | 8
32 | -2
33 | 501
34 | 241
35 |
36 |
37 |
38 |
39 |
72 |
73 |
74 |
75 | New
76 |
77 |
78 |
79 |
80 | Open
81 |
82 |
83 |
84 |
85 | Save As
86 |
87 |
88 |
89 |
90 | Print
91 |
92 |
93 |
94 |
95 | Exit
96 |
97 |
98 |
99 |
100 | Copy
101 |
102 |
103 |
104 |
105 | Paste
106 |
107 |
108 |
109 |
110 | Cut
111 |
112 |
113 |
114 |
115 | Undo
116 |
117 |
118 |
119 |
120 | Redo
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------