-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
notecreatewidget.cpp
53 lines (47 loc) · 1.21 KB
/
notecreatewidget.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
#include "notecreatewidget.h"
#include "ui_notecreatewidget.h"
#include "notelist.h"
#include "notecreatebutton.h"
#include <QSignalMapper>
NoteCreateWidget::NoteCreateWidget(QWidget *parent, NoteList* note_list) :
QFrame(parent),
ui(new Ui::NoteCreateWidget),
notes(note_list)
{
ui->setupUi(this);
signal_mapper = new QSignalMapper(this);
foreach(const NoteType& note_type, note_list->noteTypes())
{
if(!note_type.visible()) continue;
QPushButton* button = new NoteCreateButton(this, note_type);
connect(button, SIGNAL(clicked()), signal_mapper, SLOT(map()));
signal_mapper->setMapping(button, int(note_type.id()));
ui->noteTypesLayout->addWidget(button);
}
connect(signal_mapper, SIGNAL(mapped(int)), this, SLOT(clicked(int)));
}
NoteCreateWidget::~NoteCreateWidget()
{
delete ui;
}
void NoteCreateWidget::clicked(int id)
{
notes->create(Note::Type(id), ui->noteNameEdit->text());
close();
}
void NoteCreateWidget::closeEvent( QCloseEvent* event )
{
Q_UNUSED(event);
emit closed(true);
}
void NoteCreateWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}