-
Notifications
You must be signed in to change notification settings - Fork 0
/
noteeditor.cpp
82 lines (67 loc) · 1.67 KB
/
noteeditor.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
#include <QtWidgets>
#include <QString>
#include "noteeditor.h"
#include "window.h"
#include "notelist.h"
#include "notedata.h"
#include "notedatalist.h"
#include "noteviewer.h"
class NoteList;
class NoteViewer;
class NoteDataList;
class Window;
NoteEditor::NoteEditor(QWidget *parent) :
QWidget(parent)
{
id = 0;
setMaximumSize(450, 150);
int noteEditorWidth = 450;
int noteEditorHeight = 200;
noteEditText = new QTextEdit;
noteEditText->setStyleSheet("border: 2px solid grey");
saveButton = new QPushButton(tr("Save"));
saveButton->setToolTip(tr("Save note"));
saveButton->setFixedSize(noteEditorWidth / 2, noteEditorHeight / 8);
saveButton->setEnabled(false);
noteEditorLayout = new QGridLayout;
noteEditorLayout->addWidget(noteEditText, 0, 0);
noteEditorLayout->addWidget(saveButton, 1, 0, Qt::AlignRight);
setLayout(noteEditorLayout);
connect(saveButton, SIGNAL(clicked()), this, SLOT(saveNote()));
connect(noteEditText, SIGNAL(textChanged()), this, SLOT(textChange()));
}
void NoteEditor::textChange()
{
QString text = noteEditText->toPlainText();
if (text.isEmpty())
{
saveButton->setEnabled(false);
}
else
{
saveButton->setDisabled(false);
}
}
void NoteEditor::setList(NoteDataList *list)
{
this->list = list;
}
void NoteEditor::saveNote()
{
d = new NoteData();
d->setText(noteEditText->toPlainText());
d->setId(id);
noteEditText->clear();
list->addNoteData(*d);
id++;
emit noteAddedToList();
}
void NoteEditor::change()
{
id--;
d->setId(id);
}
void NoteEditor::edit(NoteData *noteData)
{
noteEditText->setText(noteData->getText());
}