aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui-tree.h
Commit message (Collapse)AuthorAge
* Add separate header-files for each page/viewLars Hjemli2008-03-24
Yet another step towards removing cgit.h. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
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
#include "tab_actor_info.h"
#include "ui_tab_actor_info.h"
#include "src/activitypub/apactor.h"
#include "src/archive/base_archive.h"
#include <QTableWidgetItem>
#include <QPainter>

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() {
    delete ui;
}

// TODO: do this in another thread, like for status_info
void TabActorInfo::update_ui() {
    if (not actor) {
        ui->displayNameText->setText(QStringLiteral("<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()));

    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));
    }
}

void TabActorInfo::paintEvent(QPaintEvent* event) {
    QPainter painter(this);

    if (actor and actor->header) {
        painter.setOpacity(0.75);

        auto &widget = *(ui->displayNameText);
        std::shared_ptr<QPixmap> pixmap = actor->header->get_pixmap(widget.width());

        QPoint centre(widget.width() / 2 - pixmap->width() / 2,
                      widget.height() / 2 - pixmap->height() / 2);

        QRect source(
            QPoint(0, abs(widget.height() - pixmap->height()) / 2),
            QPoint(pixmap->width(), abs(widget.height() - pixmap->height()) / 2 + widget.height())
        );

        painter.drawPixmap(widget.pos(), *pixmap, source);
        painter.setOpacity(1.0);
    }
}