-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image_modif.cpp
61 lines (50 loc) · 1.95 KB
/
Image_modif.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
#include "Image_modif.h"
#include "ui_Image_modif.h"
Image_modif::Image_modif(NM::Note *n, QWidget *parent) :
QWidget(parent),
note(dynamic_cast<NM::NImage*>(n)),
ui(new Ui::Image_modif)
{
ui->setupUi(this);
note->load();
ui->title_note->setText(note->getTitle());
ui->url_line->setText(note->getUrl());
ui->description_line->clear();
ui->description_line->setText(note->getDescription().trimmed());
connect(ui->save_button, SIGNAL(pressed()), this, SLOT(save_note()));
connect(ui->save_button, SIGNAL(pressed()), MainWindow::getInstance(), SLOT(createListNotes()));
connect(ui->save_button, SIGNAL(pressed()), MainWindow::getInstance(), SLOT(saveWork()));
connect(ui->find_button, SIGNAL(pressed()), this, SLOT(open_note()));
connect(ui->delete_button, SIGNAL(pressed()), this, SLOT(delete_note()));
connect(ui->delete_button, SIGNAL(pressed()), MainWindow::getInstance(), SLOT(createListNotes()));
ui->preview->setMinimumWidth(this->width()/2);
if (!note->getUrl().isEmpty()) {
pix = QPixmap(note->getUrl());
showImage();
}
}
Image_modif::~Image_modif()
{
delete ui;
}
void Image_modif::save_note() {
note->setUrl(ui->url_line->text());
note->setTitle(ui->title_note->text());
note->setDescription(ui->description_line->text());
NM::NotesManager::getInstance().save(note);
}
void Image_modif::open_note() {
ui->url_line->setText(QFileDialog::getOpenFileName(this,
tr("Open Image"), "/home/~", tr("Image Files (*.png *.jpg *.bmp)")));
pix = QPixmap(ui->url_line->text());
showImage();
}
void Image_modif::showImage() {
QPixmap pix2 = pix.scaled(ui->preview->height(), ui->preview->width(), Qt::KeepAspectRatioByExpanding, Qt::FastTransformation);
ui->preview->setPixmap(pix2);
}
void Image_modif::delete_note() {
NM::NotesManager::getInstance().deleteNote(note);
NM::NotesManager::getInstance().saveWorkspace();
this->hide();
}