-
Notifications
You must be signed in to change notification settings - Fork 2
/
trashDialog.cpp
94 lines (82 loc) · 2.94 KB
/
trashDialog.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
#include "trashDialog.h"
#include "ui_trashDialog.h"
#include "QListWidgetItemWithItemAndNote.h"
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QWidget>
#include <QObject>
#include "Trash.h"
/*!
* \brief TrashDialog::TrashDialog On utilise ici un QListWidgetItem avec un widget personalise.
* On limite la longueur du titre a 35 caracteres egalement.
* \param parent
*/
TrashDialog::TrashDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::TrashDialog)
{
Trash *trash = Trash::getInstance();
ui->setupUi(this);
for (noteSetIt it = trash->begin(); it!=trash->end(); ++it) {
QIcon icon = QIcon(":/images/play");
QListWidgetItemWithNote *item = new QListWidgetItemWithNote((*it));
item->setIcon(icon);
ui->listWidget->addItem(item);
QPushButton *buttonRes = new QPushButton(QIcon(":/images/restore"), "");
QPushButton *buttonDel = new QPushButton(QIcon(":/images/delete"), "");
buttonRes->setMaximumWidth(40);
buttonDel->setMaximumWidth(40);
QString title = (*it)->getNote()->getTitle();
if(title.size() > 35){
title.truncate(32);
title+="...";
}
QLabel *label = new QLabel(title);
QHBoxLayout *layout= new QHBoxLayout();
layout->addWidget(label);
layout->addWidget(buttonRes);
layout->addWidget(buttonDel);
QWidget *widget = new QWidget();
widget->setLayout(layout);
item->setSizeHint(widget->sizeHint());
ui->listWidget->setItemWidget(item, widget);
QObject::connect(buttonRes, SIGNAL(clicked()), this, SLOT(HANDLER_RESBTN_PRESSED()));
QObject::connect(buttonDel, SIGNAL(clicked()), this, SLOT(HANDLER_DELBTN_PRESSED()));
}
this->show();
}
TrashDialog::~TrashDialog()
{
delete ui;
}
void TrashDialog::HANDLER_RESBTN_PRESSED()
{
QWidget *clickedWidget = qobject_cast<QWidget *>(sender()->parent());
QListWidgetItem *runningItem;
for (int i = 0; i < ui->listWidget->count(); ++i) {
runningItem = ui->listWidget->item(i);
QWidget *widget = ui->listWidget->itemWidget(runningItem);
if (clickedWidget == widget) {
ui->listWidget->setCurrentItem(runningItem);
break;
}
}
Trash::getInstance()->restore(dynamic_cast<QListWidgetItemWithNote*>(runningItem)->getN());
delete runningItem;
}
void TrashDialog::HANDLER_DELBTN_PRESSED()
{
QWidget *clickedWidget = qobject_cast<QWidget *>(sender()->parent());
QListWidgetItem *runningItem;
for (int i = 0; i < ui->listWidget->count(); ++i) {
runningItem = ui->listWidget->item(i);
QWidget *widget = ui->listWidget->itemWidget(runningItem);
if (clickedWidget == widget) {
ui->listWidget->setCurrentItem(runningItem);
break;
}
}
Trash::getInstance()->remove(dynamic_cast<QListWidgetItemWithNote*>(runningItem)->getN());
delete runningItem;
}