view src/gui/widgets/anime_info.cpp @ 68:2417121d894e

*: normalize usage of layouts before, I used them two ways, once was by setting the layout later by using setLayout(QWidget), and the other was just using the constructor. I find the constructor to be easier to read, so I chose that one.
author Paper <mrpapersonic@gmail.com>
date Mon, 02 Oct 2023 21:33:25 -0400
parents fe719c109dbc
children d3e9310598b1
line wrap: on
line source

#include "gui/widgets/anime_info.h"
#include "core/anime.h"
#include "core/strings.h"
#include "gui/translate/anime.h"
#include "gui/widgets/text.h"
#include <QHBoxLayout>
#include <QTextStream>

AnimeInfoWidget::AnimeInfoWidget(const Anime::Anime& anime, QWidget* parent) : QWidget(parent) {
	QVBoxLayout* layout = new QVBoxLayout(this);

	/* alt titles */
	TextWidgets::SelectableTextParagraph* title = new TextWidgets::SelectableTextParagraph(
	    tr("Alternative titles"), QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), this);
	title->GetParagraph()->setWordWrapMode(QTextOption::NoWrap);
	layout->addWidget(title);

	/* details */
	QString details_data;
	QTextStream details_data_s(&details_data);
	details_data_s << Translate::ToString(anime.GetFormat()).c_str() << "\n"
	               << anime.GetEpisodes() << "\n"
	               << Translate::ToString(anime.GetUserStatus()).c_str() << "\n"
	               << Translate::ToString(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear() << "\n"
	               << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n"
	               << anime.GetAudienceScore() << "%";
	layout->addWidget(new TextWidgets::LabelledTextParagraph(
	    tr("Details"), tr("Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:"), details_data, this));

	/* synopsis */
	TextWidgets::SelectableTextParagraph* synopsis =
	    new TextWidgets::SelectableTextParagraph(tr("Synopsis"), QString::fromUtf8(anime.GetSynopsis().c_str()), this);

	synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
	layout->addWidget(synopsis);
}

#include "gui/widgets/moc_anime_info.cpp"