comparison 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
comparison
equal deleted inserted replaced
347:a0aa8c8c4307 348:6b0768158dcd
15 #include <QWidget> 15 #include <QWidget>
16 16
17 #include <cmath> 17 #include <cmath>
18 #include <sstream> 18 #include <sstream>
19 19
20 StatisticsPage::StatisticsPage(QWidget* parent) : QFrame(parent) { 20 StatisticsPage::StatisticsPage(QWidget* parent)
21 : QFrame(parent) {
21 setBackgroundRole(QPalette::Base); 22 setBackgroundRole(QPalette::Base);
22 23
23 QVBoxLayout* layout = new QVBoxLayout(this); 24 QVBoxLayout* layout = new QVBoxLayout(this);
24 25
25 setFrameShape(QFrame::Box); 26 setFrameShape(QFrame::Box);
26 setFrameShadow(QFrame::Sunken); 27 setFrameShadow(QFrame::Sunken);
27 28
28 setAutoFillBackground(true); 29 setAutoFillBackground(true);
29 30
30 _anime_list.reset(new TextWidgets::LabelledSection( 31 const std::vector<std::pair<std::string, std::string>> al_data_template = {
31 tr("Anime list"), 32 {Strings::Translate("Anime count:"), ""},
32 tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"), 33 {Strings::Translate("Episode count:"), ""},
33 "", this)); 34 {Strings::Translate("Time spent watching:"), ""},
34 layout->addWidget(_anime_list.get()); 35 {Strings::Translate("Time to complete:"), ""},
36 {Strings::Translate("Average score:"), ""},
37 {Strings::Translate("Score deviation:"), ""},
38 };
39
40 _anime_list.GetHeader().SetText(Strings::Translate("Anime List"));
41 _anime_list.GetContent().SetData(al_data_template);
42
43 layout->addWidget(&_anime_list);
35 44
36 { 45 {
37 QWidget* score_dist_widget = new QWidget(this); 46 QWidget* score_dist_widget = new QWidget(this);
38 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget); 47 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget);
39 48
40 score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), score_dist_widget)); 49 TextWidgets::Header* hdr = new TextWidgets::Header(score_dist_widget);
50 hdr->SetText(Strings::Translate("Score distribution"));
51 score_dist_layout->addWidget(hdr);
41 52
42 /* Ew */ 53 /* Ew */
43 { 54 {
44 QWidget* score_graph_parent = new QWidget(score_dist_widget); 55 QWidget* score_graph_parent = new QWidget(score_dist_widget);
45 QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent); 56 QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent);
46 57
47 _score_distribution_graph.reset(new Graph<int>(score_graph_parent)); 58 score_parent_layout->addWidget(&_score_distribution_graph);
48 score_parent_layout->addWidget(_score_distribution_graph.get());
49 59
50 score_parent_layout->setSpacing(0); 60 score_parent_layout->setSpacing(0);
51 score_parent_layout->setContentsMargins(12, 0, 0, 0); 61 score_parent_layout->setContentsMargins(12, 0, 0, 0);
52 62
53 score_dist_layout->addWidget(score_graph_parent); 63 score_dist_layout->addWidget(score_graph_parent);
56 score_dist_layout->setContentsMargins(0, 0, 0, 0); 66 score_dist_layout->setContentsMargins(0, 0, 0, 0);
57 67
58 layout->addWidget(score_dist_widget); 68 layout->addWidget(score_dist_widget);
59 } 69 }
60 70
61 _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this)); 71 const std::vector<std::pair<std::string, std::string>> app_data_template = {
62 layout->addWidget(_application.get()); 72 {Strings::Translate("Uptime:"), ""},
73 {Strings::Translate("Requests made:"), ""},
74 };
75
76 _application.GetHeader().SetText(Strings::Translate("Minori"));
77 _application.GetContent().SetData(app_data_template);
78
79 layout->addWidget(&_application);
63 80
64 layout->addStretch(); 81 layout->addStretch();
65 82
66 QTimer* timer = new QTimer(this); 83 QTimer* timer = new QTimer(this);
67 connect(timer, &QTimer::timeout, this, [this] { 84 connect(timer, &QTimer::timeout, this, [this] {
82 count++; 99 count++;
83 return count; 100 return count;
84 } 101 }
85 102
86 void StatisticsPage::UpdateStatistics() { 103 void StatisticsPage::UpdateStatistics() {
87 /* Anime list */ 104 const std::vector<std::pair<std::string, std::string>> al_data = {
88 QString string = ""; 105 {Strings::Translate("Anime count:"), Strings::ToUtf8String(Anime::db.GetTotalAnimeAmount())},
89 QTextStream ts(&string); 106 {Strings::Translate("Episode count:"), Strings::ToUtf8String(Anime::db.GetTotalEpisodeAmount())},
90 ts << Anime::db.GetTotalAnimeAmount() << '\n'; 107 {Strings::Translate("Time spent watching:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)},
91 ts << Anime::db.GetTotalEpisodeAmount() << '\n'; 108 {Strings::Translate("Time to complete:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)},
92 ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)) << '\n'; 109 {Strings::Translate("Average score:"), Strings::ToUtf8String(Anime::db.GetAverageScore())},
93 ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)) << '\n'; 110 {Strings::Translate("Score deviation:"), Strings::ToUtf8String(Anime::db.GetScoreDeviation())},
94 ts << Anime::db.GetAverageScore() << '\n'; 111 };
95 ts << Anime::db.GetScoreDeviation();
96 _anime_list->GetData()->setText(string);
97 112
98 _score_distribution_graph->Clear(); 113 _anime_list.GetContent().SetData(al_data);
114
115 _score_distribution_graph.Clear();
99 for (int i = 10; i <= 100; i += 10) 116 for (int i = 10; i <= 100; i += 10)
100 _score_distribution_graph->AddItem(i, GetTotalWithScore(i)); 117 _score_distribution_graph.AddItem(i, GetTotalWithScore(i));
101 118
102 string = "";
103 ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)) << '\n';
104 ts << session.GetRequests();
105 /* Application */ 119 /* Application */
106 // UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000)); 120 const std::vector<std::pair<std::string, std::string>> app_data_template = {
107 _application->GetData()->setText(string); 121 {Strings::Translate("Uptime:"), Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)},
122 {Strings::Translate("Requests made:"), Strings::ToUtf8String(session.GetRequests())},
123 };
124
125 _application.GetContent().SetData(app_data_template);
108 } 126 }