From 5aac009e969cc3bd15c484ba3437348cb7a4d186 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Sat, 20 Jan 2024 21:57:39 -0500 Subject: Implemement Actor information tab This class still has improvements to be made, but it works and I am satisfied with it! --- src/widgets/tab_actor_info.cpp | 49 ++++++++++++++++++++++++++ src/widgets/tab_actor_info.h | 27 +++++++++++++++ src/widgets/tab_actor_info.ui | 79 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 src/widgets/tab_actor_info.cpp create mode 100644 src/widgets/tab_actor_info.h create mode 100644 src/widgets/tab_actor_info.ui (limited to 'src/widgets') diff --git a/src/widgets/tab_actor_info.cpp b/src/widgets/tab_actor_info.cpp new file mode 100644 index 0000000..79630df --- /dev/null +++ b/src/widgets/tab_actor_info.cpp @@ -0,0 +1,49 @@ +#include "tab_actor_info.h" +#include "ui_tab_actor_info.h" +#include "src/activitypub/apactor.h" +#include "src/archive/base_archive.h" +#include +#include + +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); + + actor = archive->get_main_actor(); + qDebug() << 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) 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)); + } +} diff --git a/src/widgets/tab_actor_info.h b/src/widgets/tab_actor_info.h new file mode 100644 index 0000000..a1dd84f --- /dev/null +++ b/src/widgets/tab_actor_info.h @@ -0,0 +1,27 @@ +#pragma once +#include +#include "src/activitypub/apactor.h" +#include "src/archive/base_archive.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class TabActorInfo; } +QT_END_NAMESPACE + +class TabActorInfo : public QWidget { + Q_OBJECT + +public: + TabActorInfo(APActor* actor, QWidget *parent = nullptr); + TabActorInfo(Archive* archive, QWidget *parent = nullptr); + ~TabActorInfo(); + // TODO: when clicking/activating avatar image, open it with the user's default image viewer + +public slots: + // Update displayed information to match Actor + void update_ui(); + +private: + Ui::TabActorInfo* ui; + + APActor* actor = nullptr; +}; diff --git a/src/widgets/tab_actor_info.ui b/src/widgets/tab_actor_info.ui new file mode 100644 index 0000000..8fb7e21 --- /dev/null +++ b/src/widgets/tab_actor_info.ui @@ -0,0 +1,79 @@ + + + TabActorInfo + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + <html><head/><body><p><span style=" font-size:12pt; font-weight:600;">%1</span> <span style=" font-size:10pt;">(@%2)</span></p></body></html> + + + + + + + + + true + + + true + + + + + + + QAbstractItemView::ScrollPerPixel + + + false + + + 2 + + + false + + + true + + + false + + + + + + + + + + + + 0 + 0 + + + + aaaaa + + + + + + + + -- cgit v1.2.3-54-g00ecf