diff src/gui/pages/statistics.cc @ 172:45a0967485f1

graph, statistics: make my code a little less messy
author Paper <mrpapersonic@gmail.com>
date Tue, 28 Nov 2023 13:22:35 -0500
parents 6d8da6e64d61
children bc8d2ccff09c
line wrap: on
line diff
--- a/src/gui/pages/statistics.cc	Mon Nov 27 13:51:27 2023 -0500
+++ b/src/gui/pages/statistics.cc	Tue Nov 28 13:22:35 2023 -0500
@@ -24,35 +24,39 @@
 	    tr("Anime list"),
 	    tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"),
 	    "", this));
+	layout->addWidget(_anime_list.get());
 
-	QWidget* score_dist_widget = new QWidget(this);
-	QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget);
+	{
+		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));
+		score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), score_dist_widget));
+
+		/* Ew */
+		{
+			QWidget* score_graph_parent = new QWidget(score_dist_widget);
+			QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent);
 
-	/* I have to explain myself here: I hate this :). This makes a widget as a layer to create a margin,
-	   similar to what I do in text.cc with sections. I hate it and it should really be put into a separate
-	   class, but whatever. */
-	QWidget* content = new QWidget(score_dist_widget);
-	QVBoxLayout* content_layout = new QVBoxLayout(content);
-	_score_distribution_graph.reset(new Graph<int>(content));
-	content_layout->addWidget(_score_distribution_graph.get());
-	content_layout->setSpacing(0);
-	/* For some reason, when we set the margin to 12 on any paragraphs it 
-	   actually doesn't draw them 12 pixels away. It draws them ~15 pixels
-	   away! I'm assuming this is just Qt's widgets being weird (they usually are)
-	   and I hope it's nothing I *really* have to worry about... */
-	content_layout->setContentsMargins(15, 0, 0, 0);
-	content->setContentsMargins(0, 0, 0, 0);
+			_score_distribution_graph.reset(new Graph<int>(score_graph_parent));
+			score_parent_layout->addWidget(_score_distribution_graph.get());
+
+			score_parent_layout->setSpacing(0);
+			score_parent_layout->setContentsMargins(12, 0, 0, 0);
+
+			score_graph_parent->setContentsMargins(3, 0, 0, 0);
 
-	score_dist_layout->addWidget(content);
-	score_dist_layout->setContentsMargins(0, 0, 0, 0);
+			score_dist_layout->addWidget(score_graph_parent);
+		}
+
+		score_dist_layout->setContentsMargins(0, 0, 0, 0);
+
+		layout->addWidget(score_dist_widget);
+	}
+
 
 	_application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this));
+	layout->addWidget(_application.get());
 
-	layout->addWidget(_anime_list.get());
-	layout->addWidget(score_dist_widget);
-	layout->addWidget(_application.get());
 	layout->addStretch();
 
 	QTimer* timer = new QTimer(this);