diff options
author | ConfuSomu | 2023-04-06 15:57:55 -0400 |
---|---|---|
committer | ConfuSomu | 2023-04-06 16:25:54 -0400 |
commit | 75a48db1459d4c386b867ae6536ff481adf34f1f (patch) | |
tree | 3e3b090ee3b27952bca36104137df628f13a2957 | |
parent | 3095e11bfaba99fe4fb598a53914b80979aafe0f (diff) | |
download | ActorViewer-75a48db1459d4c386b867ae6536ff481adf34f1f.tar ActorViewer-75a48db1459d4c386b867ae6536ff481adf34f1f.tar.gz ActorViewer-75a48db1459d4c386b867ae6536ff481adf34f1f.zip |
Move call to get status HTML info into ListItem
This makes the code less of a mess and will allow moving more of the
code that renders HTML status info into the ListItem class.
-rw-r--r-- | src/archive_parser.cpp | 4 | ||||
-rw-r--r-- | src/list_item.cpp | 9 | ||||
-rw-r--r-- | src/list_item.h | 5 | ||||
-rw-r--r-- | src/mainwindow.cpp | 6 |
4 files changed, 15 insertions, 9 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp index 2522ffa..60278bc 100644 --- a/src/archive_parser.cpp +++ b/src/archive_parser.cpp @@ -149,10 +149,10 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par QTextDocument strip_html; strip_html.setHtml(activity.value("content").toString()); - ListItem *item = new ListItem(strip_html.toPlainText(), status_type, has_attachment, parent, i); + ListItem *item = new ListItem(strip_html.toPlainText(), status_type, has_attachment, this, parent, i); } } else if (activity_type == "Announce" and obj["object"].isString()) { - ListItem *item = new ListItem(activity_type, REBLOG, false, parent, i); + ListItem *item = new ListItem(activity_type, REBLOG, false, this, parent, i); } } next_item: diff --git a/src/list_item.cpp b/src/list_item.cpp index b7ee578..6f27ff0 100644 --- a/src/list_item.cpp +++ b/src/list_item.cpp @@ -1,5 +1,4 @@ #include "list_item.h" -#include "types.h" QIcon* choose_icon(StatusType status_type) { // via the use of `static' in the following switch block, the idea is to only initialize each QIcon type once in the program's lifetime. @@ -12,8 +11,8 @@ QIcon* choose_icon(StatusType status_type) { } } -ListItem::ListItem(const QString &text, StatusType status_type, bool has_attachement, QListWidget *parent, int index) : - status_index(index), has_attachement(has_attachement), status_type(status_type) +ListItem::ListItem(const QString &text, StatusType status_type, bool has_attachement, Archive* data_archive, QListWidget *parent, int index) : + status_index(index), has_attachement(has_attachement), status_type(status_type), data_archive(data_archive) { setText(text); setIcon(*choose_icon(status_type)); @@ -39,3 +38,7 @@ int ListItem::get_status_index() { StatusType ListItem::get_status_type() { return status_type; } + +QString ListItem::get_info_html(int text_zone_width, QLocale* locale) { + return data_archive->get_html_status_info(status_index, text_zone_width, status_type, locale); +} diff --git a/src/list_item.h b/src/list_item.h index c722a72..80a57ea 100644 --- a/src/list_item.h +++ b/src/list_item.h @@ -1,6 +1,7 @@ #pragma once #include <QListWidgetItem> +#include "src/archive_parser.h" #include "types.h" class ListItem : public QListWidgetItem { @@ -9,12 +10,14 @@ public: ArchiveListItemType = QListWidgetItem::UserType }; - ListItem(const QString &text, StatusType status_type, bool has_attachement, QListWidget *parent = nullptr, int index = 0); + ListItem(const QString &text, StatusType status_type, bool has_attachement, Archive* data_archive, QListWidget *parent = nullptr, int index = 0); int get_status_index(); StatusType get_status_type(); + QString get_info_html(int text_zone_width, QLocale* locale); private: int status_index; StatusType status_type; bool has_attachement = false; + Archive* data_archive; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b08fd14..d635ae8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -73,9 +73,9 @@ void MainWindow::on_actionAbout_triggered(bool checked) { } void MainWindow::on_listWidget_itemActivated(QListWidgetItem *item) { - ListItem* casted = dynamic_cast<ListItem*>(item); - if (casted != nullptr) { - QString status_info = data_archive->get_html_status_info(casted->get_status_index(), ui->statusInfoText->width(), casted->get_status_type(), &locale_context); + ListItem* status = dynamic_cast<ListItem*>(item); + if (status != nullptr) { + QString status_info = status->get_info_html(ui->statusInfoText->width(), &locale_context); ui->statusInfoText->setHtml(status_info); } } |