-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutbox.cpp
82 lines (71 loc) · 2.24 KB
/
outbox.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
#include "outbox.h"
#include "ui_outbox.h"
outbox::outbox(QWidget *dash, const QString &user, QWidget *parent) :
QWidget(parent),
ui(new Ui::outbox)
{
this->dash = dash;
this->user = user;
ui->setupUi(this);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
loadData();
}
void outbox::mousePressEvent(QMouseEvent *event)
{
oldPos = event->globalPosition();
}
void outbox::mouseMoveEvent(QMouseEvent *event)
{
const QPointF delta = event->globalPosition() - oldPos;
move(x()+delta.x(), y()+delta.y());
oldPos = event->globalPosition();
}
int outbox::loadData()
{
this->messagedb = Message::loadMessages(); // code - sender - reciver - subject - text - isRead
ui->tableWidget->setRowCount(0);
ui->plainTextEdit->hide();
int j = 0;
// Add to table
QMapIterator<QString, QStringList> i(messagedb);
i.toBack();
while (i.hasPrevious()) // Print Newest First (:
{
i.previous();
if (i.value().at(0) == user)
{
ui->tableWidget->insertRow(ui->tableWidget->rowCount());
QString date = QDateTime::fromString(i.key(), "yyyyMMddhhmmsszzz").toString("dd MMMM yyyy hh:mm:ss.zzz");
ui->tableWidget->setItem(j, 0, new QTableWidgetItem(date));
ui->tableWidget->setItem(j, 1, new QTableWidgetItem(i.value().at(1)));
ui->tableWidget->setItem(j, 2, new QTableWidgetItem(i.value().at(2)));
ui->tableWidget->setItem(j, 3, new QTableWidgetItem((i.value().at(4).toInt()) ? "Yes" : "No"));
++j;
}
}
ui->label->setText("Outbox | " + QString::number(j) +" Records Loaded");
return j;
}
outbox::~outbox()
{
delete ui;
}
void outbox::on_pushButton_clicked()
{
this->loadData();
}
void outbox::on_tableWidget_currentCellChanged(int currentRow)
{
QTableWidgetItem *tmp = ui->tableWidget->item(currentRow, 0);
if (tmp) // if item exists !
{
QString code_msg = QDateTime::fromString(tmp->text(), "dd MMMM yyyy hh:mm:ss.zzz").toString("yyyyMMddhhmmsszzz");
ui->plainTextEdit->show();
ui->plainTextEdit->setPlainText(messagedb.value(code_msg).at(3));
}
}
void outbox::on_pushButton_backtodash_clicked()
{
this->hide();
dash->show();
}