-
Notifications
You must be signed in to change notification settings - Fork 1
/
JournalEditDialog.cpp
98 lines (72 loc) · 2.53 KB
/
JournalEditDialog.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "JournalEditDialog.h"
#include <QDateTime>
#include <QSettings>
#include "CWrapper.h"
#include "CalendarPickSelector.h"
#include "ChangeManager.h"
#include <QScroller>
JournalEditDialog::JournalEditDialog(QWidget *parent, CJournal *journal) :
ComponentEditDialog(parent),
ui(new Ui::JournalEditDialog)
{
ui->setupUi(this);
if (journal && !journal->getId().empty()) {
journal = CWrapper::details(journal);
this->setWindowTitle(tr("Edit note"));
this->setupDeleteButton(ui->buttonBox, SLOT(deleteJournal()));
} else {
this->setWindowTitle(tr("New note"));
}
CalendarPickSelector *cps = new CalendarPickSelector();
ui->calendarButton->setPickSelector(cps);
if (journal) {
// Do not set the default settings when editing an existing todo
saveDefaults = false;
// Load component data
ui->summaryEdit->setPlainText(QString::fromUtf8(journal->getSummary().c_str()));
cps->setCalendar(journal->getCalendarId());
} else {
journal = new CJournal();
saveDefaults = true;
// Load last used settings
QSettings settings;
settings.beginGroup("JournalEditDialog");
cps->setCalendar(settings.value("Calendar", 1).toInt());
}
// An unsophisticated way to fill the available screen space
this->setMinimumHeight(800);
this->setupSaveButton(ui->buttonBox, SLOT(saveJournal()));
QScroller::grabGesture(ui->mainArea, QScroller::LeftMouseButtonGesture);
this->setFeatures(ui->dialogLayout, ui->buttonBox);
this->journal = journal;
}
JournalEditDialog::~JournalEditDialog()
{
QScroller::scroller(ui->mainArea)->stop();
QScroller::ungrabGesture(ui->mainArea);
delete journal;
delete ui;
}
void JournalEditDialog::saveJournal()
{
// Do not allow empty journal entries
if (ui->summaryEdit->toPlainText().isEmpty()) {
ui->summaryEdit->setFocus();
return;
}
CalendarPickSelector *cps = qobject_cast<CalendarPickSelector*>(ui->calendarButton->pickSelector());
journal->setSummary(ui->summaryEdit->toPlainText().toUtf8().data());
journal->setDateStart(QDateTime::currentDateTime().toTime_t());
ChangeManager::save(journal, cps->currentId());
if (saveDefaults) {
QSettings settings;
settings.beginGroup("JournalEditDialog");
settings.setValue("Calendar", cps->currentId());
}
this->accept();
}
void JournalEditDialog::deleteJournal()
{
if (ChangeManager::drop(this, journal))
this->accept();
}