game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_statistics_dialog.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/game_statistics_dialog.h
4// ==============================================================================
5// Dialog showing game library statistics and visualizations
6// ==============================================================================
7
8#pragma once
9
10#include "models/game.h"
11
12#include <QComboBox>
13#include <QDialog>
14#include <QLabel>
15#include <QListWidget>
16#include <QPushButton>
17#include <QScrollArea>
18#include <QTabWidget>
19#include <QWidget>
20#include <map>
21#include <vector>
22
23// Forward declarations
24class QVBoxLayout;
25class QHBoxLayout;
26class QGridLayout;
27class QFrame;
28class QPaintEvent;
29class ThemeManager;
30
31// ==============================================================================
32// StatCard - Individual stat display widget
33// ==============================================================================
34
35class StatCard : public QFrame
36{
37 Q_OBJECT
38
39 public:
40 explicit StatCard(const QString& label, const QString& value, const QString& icon = "",
41 QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
42
43 void setValue(const QString& value);
44 void setSubtext(const QString& subtext);
45
46 public slots:
47 void applyTheme();
48
49 private:
50 QLabel* iconLabel_ = nullptr;
51 QLabel* valueLabel_ = nullptr;
52 QLabel* labelLabel_ = nullptr;
53 QLabel* subtextLabel_ = nullptr;
54 ThemeManager* themeManager_;
55};
56
57// ==============================================================================
58// PieChartWidget - Simple pie chart for genre/source breakdown
59// ==============================================================================
60
61class PieChartWidget : public QWidget
62{
63 Q_OBJECT
64
65 public:
66 struct Slice
67 {
68 QString label;
69 double value;
70 QColor color;
71 };
72
73 explicit PieChartWidget(QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
74
75 void setData(const std::vector<Slice>& slices);
76 void setTitle(const QString& title);
77
78 public slots:
79 void applyTheme();
80
81 protected:
82 void paintEvent(QPaintEvent* event) override;
83 QSize sizeHint() const override
84 {
85 return QSize(250, 250);
86 }
87 QSize minimumSizeHint() const override
88 {
89 return QSize(200, 200);
90 }
91
92 private:
93 std::vector<Slice> slices_;
94 QString title_;
95 QColor textColor_;
96 QColor backgroundColor_;
97 ThemeManager* themeManager_;
98};
99
100// ==============================================================================
101// BarChartWidget - Horizontal bar chart for top games
102// ==============================================================================
103
104class BarChartWidget : public QWidget
105{
106 Q_OBJECT
107
108 public:
109 struct Bar
110 {
111 QString label;
112 double value;
114 };
115
116 explicit BarChartWidget(QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
117
118 void setData(const std::vector<Bar>& bars);
119 void setTitle(const QString& title);
120 void setMaxBars(int max)
121 {
122 maxBars_ = max;
123 }
124
125 public slots:
126 void applyTheme();
127
128 protected:
129 void paintEvent(QPaintEvent* event) override;
130 QSize sizeHint() const override;
131 QSize minimumSizeHint() const override;
132
133 private:
134 std::vector<Bar> bars_;
135 QString title_;
136 int maxBars_ = 10;
137 QColor textColor_;
138 QColor barColor_;
139 QColor backgroundColor_;
140 ThemeManager* themeManager_;
141};
142
143// ==============================================================================
144// ActivityHeatmapWidget - Shows activity over time
145// ==============================================================================
146
147class ActivityHeatmapWidget : public QWidget
148{
149 Q_OBJECT
150
151 public:
152 explicit ActivityHeatmapWidget(QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
153
154 // Set daily activity data (day offset from today -> hours played)
155 void setActivityData(const std::map<int, double>& dailyHours);
156 void setTitle(const QString& title);
157
158 public slots:
159 void applyTheme();
160
161 protected:
162 void paintEvent(QPaintEvent* event) override;
163 QSize sizeHint() const override
164 {
165 return QSize(700, 150);
166 }
167 QSize minimumSizeHint() const override
168 {
169 return QSize(500, 100);
170 }
171
172 private:
173 std::map<int, double> activityData_; // Days ago -> hours
174 QString title_;
175 QColor textColor_;
176 QColor lowActivityColor_;
177 QColor highActivityColor_;
178 QColor backgroundColor_;
179 double maxActivity_ = 0;
180 ThemeManager* themeManager_;
181};
182
183// ==============================================================================
184// GameStatisticsDialog - Main statistics dialog
185// ==============================================================================
186
187class GameStatisticsDialog : public QDialog
188{
189 Q_OBJECT
190
191 public:
192 explicit GameStatisticsDialog(QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
193 ~GameStatisticsDialog() override = default;
194
195 // Set the game library data
196 void setGames(const std::vector<Game*>& games);
197
198 private slots:
199 void onTimeRangeChanged(int index);
200 void onGameDoubleClicked(QListWidgetItem* item);
201 void applyTheme();
202
203 private:
204 void setupUI();
205 void setupOverviewTab(QWidget* tab);
206 void setupPlaytimeTab(QWidget* tab);
207 void setupLibraryTab(QWidget* tab);
208
209 void refreshStatistics();
210 void calculateOverviewStats();
211 void calculatePlaytimeStats();
212 void calculateLibraryStats();
213
214 QString formatPlaytime(double seconds) const;
215 QString formatDate(time_t timestamp) const;
216
217 std::vector<Game*> games_;
218
219 // Time filter
220 QComboBox* timeRangeCombo_ = nullptr;
221 int daysFilter_ = 0; // 0 = all time
222
223 // UI Components
224 QTabWidget* tabWidget_ = nullptr;
225
226 // Overview tab widgets
227 StatCard* totalGamesCard_ = nullptr;
228 StatCard* totalPlaytimeCard_ = nullptr;
229 StatCard* avgSessionCard_ = nullptr;
230 StatCard* mostPlayedCard_ = nullptr;
231 PieChartWidget* genreChart_ = nullptr;
232 PieChartWidget* sourceChart_ = nullptr;
233
234 // Playtime tab widgets
235 BarChartWidget* topGamesChart_ = nullptr;
236 ActivityHeatmapWidget* activityHeatmap_ = nullptr;
237 StatCard* weeklyPlaytimeCard_ = nullptr;
238 StatCard* monthlyPlaytimeCard_ = nullptr;
239 StatCard* longestSessionCard_ = nullptr;
240
241 // Library tab widgets
242 StatCard* installedGamesCard_ = nullptr;
243 StatCard* favoriteGamesCard_ = nullptr;
244 StatCard* completedGamesCard_ = nullptr;
245 StatCard* notPlayedCard_ = nullptr;
246 PieChartWidget* completionChart_ = nullptr;
247 PieChartWidget* installStatusChart_ = nullptr;
248 QListWidget* recentlyAddedList_ = nullptr;
249 QListWidget* recentlyPlayedList_ = nullptr;
250
251 ThemeManager* themeManager_;
252};
void setTitle(const QString &title)
void paintEvent(QPaintEvent *event) override
QSize minimumSizeHint() const override
void setActivityData(const std::map< int, double > &dailyHours)
QSize sizeHint() const override
ActivityHeatmapWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
QSize minimumSizeHint() const override
void paintEvent(QPaintEvent *event) override
QSize sizeHint() const override
void setData(const std::vector< Bar > &bars)
void setTitle(const QString &title)
BarChartWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void setGames(const std::vector< Game * > &games)
~GameStatisticsDialog() override=default
GameStatisticsDialog(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
QSize minimumSizeHint() const override
void setTitle(const QString &title)
PieChartWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void setData(const std::vector< Slice > &slices)
QSize sizeHint() const override
void paintEvent(QPaintEvent *event) override
void setValue(const QString &value)
void setSubtext(const QString &subtext)
StatCard(const QString &label, const QString &value, const QString &icon="", QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)