Mercurial > minori
diff src/gui/pages/statistics.cc @ 202:71832ffe425a
animia: re-add kvm fd source
this is all being merged from my wildly out-of-date laptop. SORRY!
in other news, I edited the CI file to install the wayland client
as well, so the linux CI build might finally get wayland stuff.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Tue, 02 Jan 2024 06:05:06 -0500 |
parents | 649786bae914 |
children | 4d461ef7d424 |
line wrap: on
line diff
--- a/src/gui/pages/statistics.cc Sun Nov 19 19:13:28 2023 -0500 +++ b/src/gui/pages/statistics.cc Tue Jan 02 06:05:06 2024 -0500 @@ -1,15 +1,18 @@ #include "gui/pages/statistics.h" #include "core/anime_db.h" +#include "core/strings.h" #include "core/session.h" #include "gui/pages/anime_list.h" #include "gui/widgets/text.h" #include "gui/widgets/graph.h" + #include <QString> #include <QTextDocument> #include <QTextStream> #include <QTimer> #include <QVBoxLayout> #include <QWidget> + #include <sstream> StatisticsPage::StatisticsPage(QWidget* parent) : QFrame(parent) { @@ -24,35 +27,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); @@ -68,9 +75,11 @@ } /* me abusing macros :) */ -#define ADD_TIME_SEGMENT(r, x, s, p) \ - if (x > 0) \ - r << x << ((x == 1) ? s : p) +static void add_time_segment(std::ostringstream& str, int x, const std::string_view& s, const std::string_view& p) { + if (x > 0) + str << x << ((x == 1) ? s : p); +} + std::string StatisticsPage::MinutesToDateString(const int minutes) { /* ew */ int years = (minutes * (1 / 525949.2F)); @@ -79,10 +88,10 @@ int hours = (minutes * (1 / 60.0F)) - (years * 8765.82F) - (months * 730.485F) - (days * 24); int rest_minutes = (minutes) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440) - (hours * 60); std::ostringstream return_stream; - ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); - ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); - ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); - ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); + add_time_segment(return_stream, years, " year ", " years "); + add_time_segment(return_stream, months, " month ", " months "); + add_time_segment(return_stream, days, " day ", " days "); + add_time_segment(return_stream, hours, " hour ", " hours "); if (rest_minutes > 0 || return_stream.str().size() == 0) return_stream << rest_minutes << ((rest_minutes == 1) ? " minute" : " minutes"); return return_stream.str(); @@ -98,16 +107,15 @@ int seconds = sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); std::ostringstream return_stream; - ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); - ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); - ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); - ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); - ADD_TIME_SEGMENT(return_stream, minutes, " minute ", " minutes "); + add_time_segment(return_stream, years, " year ", " years "); + add_time_segment(return_stream, months, " month ", " months "); + add_time_segment(return_stream, days, " day ", " days "); + add_time_segment(return_stream, hours, " hour ", " hours "); + add_time_segment(return_stream, minutes, " minute ", " minutes "); if (seconds > 0 || return_stream.str().size() == 0) return_stream << seconds << ((seconds == 1) ? " second" : " seconds"); return return_stream.str(); } -#undef ADD_TIME_SEGMENT inline int GetTotalWithScore(const int score) { int count = 0; @@ -134,7 +142,7 @@ _score_distribution_graph->AddItem(i, GetTotalWithScore(i)); string = ""; - ts << QString::fromUtf8(SecondsToDateString(session.uptime() / 1000).c_str()) << '\n'; + ts << Strings::ToQString(SecondsToDateString(session.uptime() / 1000)) << '\n'; ts << session.GetRequests(); /* Application */ // UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000));