-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotepad.cpp
More file actions
205 lines (169 loc) · 4.85 KB
/
Copy pathnotepad.cpp
File metadata and controls
205 lines (169 loc) · 4.85 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
#include <string>
#include <QListWidgetItem>
#include <QInputDialog>
#include <QMessageBox>
#include "notepad.h"
#include "ui_notepad.h"
#include "note.h"
#include "noteeditor.h"
#include <QDebug>
Notepad::Notepad(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Notepad)
{
ui->setupUi(this);
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
}
Notepad::~Notepad()
{
delete ui;
}
void Notepad::setCurrentNItem(QListWidgetItem* nItem)
{
currentNItem = nItem;
}
Note* Notepad::getNote(QListWidgetItem* nItem)
{
auto it = noteWidgetMap.find(nItem);
if (it != noteWidgetMap.end())
{
return it->second;
}
return nullptr;
}
void Notepad::on_newButton_clicked()
{
bool ok;
QString inputtitle = QInputDialog::getText(0,"New Note",
"Enter New Note Title", QLineEdit::Normal, QString(), &ok);
if (!ok || inputtitle == "")
{
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
return;
}
std::string inputtitle_str = inputtitle.toStdString();
Note* newNote = new Note;
newNote->setTitle(inputtitle_str);
QListWidgetItem* nItem = new QListWidgetItem;
nItem->setText(inputtitle);
ui->listWidget->addItem(nItem);
noteWidgetMap.insert({nItem, newNote});
QMessageBox::StandardButton reply = QMessageBox::question(this, "Lock Note",
"Do you want to lock this note?", QMessageBox::Yes | QMessageBox:: No);
if (reply == QMessageBox::Yes)
{
QString inputpswd = QInputDialog::getText(0,"Create password",
"Enter password for this event:", QLineEdit::Normal, QString(), &ok);
if (ok)
{
std::string inputpswd_str = inputpswd.toStdString();
newNote->lock(inputpswd_str);
}
else
{
QMessageBox::information(0,"","Note not locked.");
}
}
else
{
QMessageBox::information(0,"","Note not locked.");
}
NoteEditor edit(this, newNote);
edit.exec();
}
void Notepad::on_editButton_clicked()
{
bool ok;
bool relock_after_edit = false;
std::string pswd;
if(getNote(currentNItem)->isLocked())
{
relock_after_edit = true;
QString inputpswd = QInputDialog::getText(0,"Note Locked","Enter password:",
QLineEdit::Normal, QString(), &ok);
std::string inputpswd_str = inputpswd.toStdString();
if (!ok)
{
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
return;
}
if (!(getNote(currentNItem)->unlock(inputpswd_str)))
{
QMessageBox::information(0,"","Incorrect Password.");
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
return;
}
}
NoteEditor edit(this, getNote(currentNItem));
edit.exec();
if(relock_after_edit)
{
getNote(currentNItem)->lock();
}
}
void Notepad::on_deleteButton_clicked()
{
bool ok;
bool relock_after_edit = false;
std::string pswd;
if(getNote(currentNItem)->isLocked())
{
relock_after_edit = true;
QString inputpswd = QInputDialog::getText(0,"Note Locked","Enter password:",
QLineEdit::Normal, QString(), &ok);
std::string inputpswd_str = inputpswd.toStdString();
if (!ok)
{
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
return;
}
if (!(getNote(currentNItem)->unlock(inputpswd_str)))
{
QMessageBox::information(0,"","Incorrect Password.");
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
return;
}
}
QMessageBox::StandardButton reply = QMessageBox::question(this, "Delete Note",
"Are your sure you want to delete this note?",
QMessageBox::Yes | QMessageBox:: No);
if (reply == QMessageBox::No)
{
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
return;
}
Note* note = getNote(currentNItem);
noteWidgetMap.erase(currentNItem);
currentNItem->setHidden(true);
delete note;
delete currentNItem;
}
void Notepad::on_listWidget_itemClicked(QListWidgetItem *item)
{
setCurrentNItem(item);
ui->editButton->setEnabled(true);
ui->deleteButton->setEnabled(true);
}
void Notepad::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
//open a read-only copy
setCurrentNItem(item);
NoteEditor edit(this, getNote(item), true);
edit.exec();
}
void Notepad::editor_closed()
{
ui->editButton->setEnabled(false);
ui->deleteButton->setEnabled(false);
}
void Notepad::voice_create_note(QString body)
{
// create a new note
}