comparison 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
comparison
equal deleted inserted replaced
171:03b444cbe55f 172:45a0967485f1
22 22
23 _anime_list.reset(new TextWidgets::LabelledSection( 23 _anime_list.reset(new TextWidgets::LabelledSection(
24 tr("Anime list"), 24 tr("Anime list"),
25 tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"), 25 tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"),
26 "", this)); 26 "", this));
27 layout->addWidget(_anime_list.get());
27 28
28 QWidget* score_dist_widget = new QWidget(this); 29 {
29 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget); 30 QWidget* score_dist_widget = new QWidget(this);
31 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget);
30 32
31 score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), score_dist_widget)); 33 score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), score_dist_widget));
32 34
33 /* I have to explain myself here: I hate this :). This makes a widget as a layer to create a margin, 35 /* Ew */
34 similar to what I do in text.cc with sections. I hate it and it should really be put into a separate 36 {
35 class, but whatever. */ 37 QWidget* score_graph_parent = new QWidget(score_dist_widget);
36 QWidget* content = new QWidget(score_dist_widget); 38 QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent);
37 QVBoxLayout* content_layout = new QVBoxLayout(content);
38 _score_distribution_graph.reset(new Graph<int>(content));
39 content_layout->addWidget(_score_distribution_graph.get());
40 content_layout->setSpacing(0);
41 /* For some reason, when we set the margin to 12 on any paragraphs it
42 actually doesn't draw them 12 pixels away. It draws them ~15 pixels
43 away! I'm assuming this is just Qt's widgets being weird (they usually are)
44 and I hope it's nothing I *really* have to worry about... */
45 content_layout->setContentsMargins(15, 0, 0, 0);
46 content->setContentsMargins(0, 0, 0, 0);
47 39
48 score_dist_layout->addWidget(content); 40 _score_distribution_graph.reset(new Graph<int>(score_graph_parent));
49 score_dist_layout->setContentsMargins(0, 0, 0, 0); 41 score_parent_layout->addWidget(_score_distribution_graph.get());
42
43 score_parent_layout->setSpacing(0);
44 score_parent_layout->setContentsMargins(12, 0, 0, 0);
45
46 score_graph_parent->setContentsMargins(3, 0, 0, 0);
47
48 score_dist_layout->addWidget(score_graph_parent);
49 }
50
51 score_dist_layout->setContentsMargins(0, 0, 0, 0);
52
53 layout->addWidget(score_dist_widget);
54 }
55
50 56
51 _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this)); 57 _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this));
58 layout->addWidget(_application.get());
52 59
53 layout->addWidget(_anime_list.get());
54 layout->addWidget(score_dist_widget);
55 layout->addWidget(_application.get());
56 layout->addStretch(); 60 layout->addStretch();
57 61
58 QTimer* timer = new QTimer(this); 62 QTimer* timer = new QTimer(this);
59 connect(timer, &QTimer::timeout, this, [this] { 63 connect(timer, &QTimer::timeout, this, [this] {
60 if (isVisible()) 64 if (isVisible())