diff src/gui/pages/statistics.cc @ 348:6b0768158dcd

text: redesign almost every widget i.e. Paragraph is now a QLabel, etc etc, some things will probably break, idc
author Paper <paper@paper.us.eu.org>
date Tue, 25 Jun 2024 11:19:54 -0400
parents 91ac90a34003
children
line wrap: on
line diff
--- a/src/gui/pages/statistics.cc	Sun Jun 23 10:32:09 2024 -0400
+++ b/src/gui/pages/statistics.cc	Tue Jun 25 11:19:54 2024 -0400
@@ -17,7 +17,8 @@
 #include <cmath>
 #include <sstream>
 
-StatisticsPage::StatisticsPage(QWidget* parent) : QFrame(parent) {
+StatisticsPage::StatisticsPage(QWidget* parent)
+	: QFrame(parent) {
 	setBackgroundRole(QPalette::Base);
 
 	QVBoxLayout* layout = new QVBoxLayout(this);
@@ -27,25 +28,34 @@
 
 	setAutoFillBackground(true);
 
-	_anime_list.reset(new TextWidgets::LabelledSection(
-	    tr("Anime list"),
-	    tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"),
-	    "", this));
-	layout->addWidget(_anime_list.get());
+	const std::vector<std::pair<std::string, std::string>> al_data_template = {
+		{Strings::Translate("Anime count:"), ""},
+		{Strings::Translate("Episode count:"), ""},
+		{Strings::Translate("Time spent watching:"), ""},
+		{Strings::Translate("Time to complete:"), ""},
+		{Strings::Translate("Average score:"), ""},
+		{Strings::Translate("Score deviation:"), ""},
+	};
+
+	_anime_list.GetHeader().SetText(Strings::Translate("Anime List"));
+	_anime_list.GetContent().SetData(al_data_template);
+
+	layout->addWidget(&_anime_list);
 
 	{
 		QWidget* score_dist_widget = new QWidget(this);
 		QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget);
 
-		score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), score_dist_widget));
+		TextWidgets::Header* hdr = new TextWidgets::Header(score_dist_widget);
+		hdr->SetText(Strings::Translate("Score distribution"));
+		score_dist_layout->addWidget(hdr);
 
 		/* Ew */
 		{
 			QWidget* score_graph_parent = new QWidget(score_dist_widget);
 			QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent);
 
-			_score_distribution_graph.reset(new Graph<int>(score_graph_parent));
-			score_parent_layout->addWidget(_score_distribution_graph.get());
+			score_parent_layout->addWidget(&_score_distribution_graph);
 
 			score_parent_layout->setSpacing(0);
 			score_parent_layout->setContentsMargins(12, 0, 0, 0);
@@ -58,8 +68,15 @@
 		layout->addWidget(score_dist_widget);
 	}
 
-	_application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this));
-	layout->addWidget(_application.get());
+	const std::vector<std::pair<std::string, std::string>> app_data_template = {
+		{Strings::Translate("Uptime:"), ""},
+		{Strings::Translate("Requests made:"), ""},
+	};
+
+	_application.GetHeader().SetText(Strings::Translate("Minori"));
+	_application.GetContent().SetData(app_data_template);
+
+	layout->addWidget(&_application);
 
 	layout->addStretch();
 
@@ -84,25 +101,26 @@
 }
 
 void StatisticsPage::UpdateStatistics() {
-	/* Anime list */
-	QString string = "";
-	QTextStream ts(&string);
-	ts << Anime::db.GetTotalAnimeAmount() << '\n';
-	ts << Anime::db.GetTotalEpisodeAmount() << '\n';
-	ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)) << '\n';
-	ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)) << '\n';
-	ts << Anime::db.GetAverageScore() << '\n';
-	ts << Anime::db.GetScoreDeviation();
-	_anime_list->GetData()->setText(string);
+	const std::vector<std::pair<std::string, std::string>> al_data = {
+		{Strings::Translate("Anime count:"), Strings::ToUtf8String(Anime::db.GetTotalAnimeAmount())},
+		{Strings::Translate("Episode count:"), Strings::ToUtf8String(Anime::db.GetTotalEpisodeAmount())},
+		{Strings::Translate("Time spent watching:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)},
+		{Strings::Translate("Time to complete:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)},
+		{Strings::Translate("Average score:"), Strings::ToUtf8String(Anime::db.GetAverageScore())},
+		{Strings::Translate("Score deviation:"), Strings::ToUtf8String(Anime::db.GetScoreDeviation())},
+	};
+
+	_anime_list.GetContent().SetData(al_data);
 
-	_score_distribution_graph->Clear();
+	_score_distribution_graph.Clear();
 	for (int i = 10; i <= 100; i += 10)
-		_score_distribution_graph->AddItem(i, GetTotalWithScore(i));
+		_score_distribution_graph.AddItem(i, GetTotalWithScore(i));
 
-	string = "";
-	ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)) << '\n';
-	ts << session.GetRequests();
 	/* Application */
-	// UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000));
-	_application->GetData()->setText(string);
+	const std::vector<std::pair<std::string, std::string>> app_data_template = {
+		{Strings::Translate("Uptime:"), Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)},
+		{Strings::Translate("Requests made:"), Strings::ToUtf8String(session.GetRequests())},
+	};
+
+	_application.GetContent().SetData(app_data_template);
 }