-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatusWindow.cpp
63 lines (51 loc) · 1.99 KB
/
StatusWindow.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
#include "StatusWindow.h"
#include "ui_StatusWindow.h"
#include "APIHandler.h"
StatusWindow::StatusWindow(QWidget *parent) : QWidget(parent), ui(new Ui::StatusWindow)
{
ui->setupUi(this);
QObject::connect(ui->closeButton,SIGNAL(pressed()),this,SLOT(showLogin()));
QObject::connect(ui->publishButton,SIGNAL(pressed()),this,SLOT(publishMessage()));
QObject::connect(ui->refreshButton,SIGNAL(pressed()),this,SLOT(pressStatus()));
QObject::connect(ui->editButton,SIGNAL(pressed()),this,SLOT(showEdit()));
QObject::connect(ui->messagesListWidget,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(pressedProfile()));
}
StatusWindow::~StatusWindow()
{
delete this->ui;
}
void StatusWindow::loadProfile(APIHandler *api) {
this->ui->userLabel->setText(api->getUsername());
this->ui->imageLabel->setPixmap(QPixmap::fromImage(api->getImage()));
emit doStatus();
}
void StatusWindow::drawMessages(QJsonArray messages) {
this->ui->messagesListWidget->clear();
int messagesCount = messages.count();
for (int i = 0; i < messagesCount; i++) {
this->drawMessage(messages.at(i).toObject());
}
}
void StatusWindow::drawMessage(QJsonObject message) {
QString item = QString(message["username"].toString() + ":" + "\n" + message["body"].toString() + "\n---------------------------- " + message["time"].toString() + "\n");
this->ui->messagesListWidget->addItem(item);
// Con esto podemos saber que userID tiene cada mensaje
int ix = ui->messagesListWidget->count() - 1;
messageUserIdList.insert(ix, message["userID"].toInt());
}
void StatusWindow::publishMessage(){
emit doPublish(ui->messageText->toPlainText());
ui->messageText->setPlainText("");
}
void StatusWindow::showLogin() {
emit closeSession();
}
void StatusWindow::pressStatus() {
emit doStatus();
}
void StatusWindow::showEdit() {
emit moveToEdit();
}
void StatusWindow::pressedProfile() {
emit showProfile(messageUserIdList.value(ui->messagesListWidget->currentIndex().row()));
}