aboutsummaryrefslogtreecommitdiffstats
path: root/src/widgets/tab_actor_info.cpp
blob: f991366393c8bd08fb054b8ba4a076353597f95b (plain)
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
#include "tab_actor_info.h"
#include "ui_tab_actor_info.h"
#include "src/activitypub/apactor.h"
#include "src/archive/base_archive.h"
#include <QTableWidgetItem>

TabActorInfo::TabActorInfo(APActor* actor, QWidget* parent)
    : QWidget(parent), ui(new Ui::TabActorInfo), actor(actor)
{
    ui->setupUi(this);
    ui->gridLayout->setContentsMargins(0, 0, 0, 0);

    update_ui();
}

TabActorInfo::TabActorInfo(Archive* archive, QWidget* parent)
    : QWidget(parent), ui(new Ui::TabActorInfo)
{
    ui->setupUi(this);
    ui->gridLayout->setContentsMargins(0, 0, 0, 0);

    if (archive)
        actor = archive->get_main_actor();
    update_ui();
}

TabActorInfo::~TabActorInfo() {
    if (actor) delete actor;
    delete ui;
}

// TODO: do this in another thread, like for status_info
void TabActorInfo::update_ui() {
    if (not actor) {
        ui->displayNameText->setText(QString("<html><head/><body><p><span style=\"font-size:14pt; font-weight:600;\">%1</span></p></body></html>").arg(tr("Failed to display Actor")));
        ui->avatarImage->setText("");
        return;
    }

    ui->displayNameText->setText(ui->displayNameText->text().arg(actor->name).arg(actor->username));
    ui->summaryText->setHtml(actor->summary);
    ui->avatarImage->setPixmap(actor->avatar->get_pixmap(ui->avatarImage->size().width()));
    // TODO: set header as top of background of widget
    // Affiche le nom et la description fonctionne sans problèmes

    int row = 0;
    for (APPropertyValue prop : actor->table) {
        ui->attachments->insertRow(row);
        ui->attachments->setItem(row, 0, new QTableWidgetItem(prop.key));
        ui->attachments->setItem(row++, 1, new QTableWidgetItem(prop.value));
    }
}