game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
running_game_status_widget.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <QHBoxLayout>
5#include <QLabel>
6#include <QPainter>
7#include <QString>
8#include <QTimer>
9#include <QWidget>
10#include <chrono>
11#include <vector>
12
13class ThemeManager;
14
15/**
16 * @brief Compact widget showing running game status in the toolbar
17 *
18 * Displays when a game is running and the details panel is hidden.
19 * Shows: game name, running time, FPS, and a mini frametime sparkline.
20 * Hover shows detailed optimization/launch info.
21 * Click reveals the details panel.
22 */
23class RunningGameStatusWidget : public QWidget
24{
25 Q_OBJECT
26
27 public:
28 explicit RunningGameStatusWidget(QWidget* parent = nullptr,
29 ThemeManager* themeManager = nullptr);
30 ~RunningGameStatusWidget() override = default;
31
32 /**
33 * @brief Update the widget with current game info
34 * @param gameId Game identifier
35 * @param gameName Display name of the game
36 * @param runningSeconds How long the game has been running
37 * @param fps Current FPS (0 if unavailable)
38 * @param frametime Current frametime in ms (0 if unavailable)
39 * @param frametimeHistory Recent frametimes for sparkline
40 * @param trackedProcessName Optional - actual game process name (e.g., "WoWClassic.exe" when
41 * gameName is "Battle.net")
42 */
43 void updateStatus(const QString& gameId, const QString& gameName, int runningSeconds,
44 double fps, double frametime, const std::vector<double>& frametimeHistory,
45 const QString& trackedProcessName = QString());
46
47 /**
48 * @brief Set detailed tooltip info about launch configuration
49 * @param optimizations List of applied optimizations (e.g., "MangoHud", "GameMode")
50 * @param runner Runner type (e.g., "Proton", "Wine", "Native")
51 * @param protonVersion Proton version if applicable
52 */
53 void setLaunchInfo(const QStringList& optimizations, const QString& runner,
54 const QString& protonVersion);
55
56 /**
57 * @brief Clear the widget (no game running)
58 */
59 void clear();
60
61 /**
62 * @brief Check if widget has active game data
63 */
64 bool hasActiveGame() const
65 {
66 return !currentGameId_.isEmpty();
67 }
68
69 /**
70 * @brief Get current game ID
71 */
72 QString currentGameId() const
73 {
74 return currentGameId_;
75 }
76
77 signals:
78 /**
79 * @brief Emitted when widget is clicked
80 */
81 void clicked();
82
83 /**
84 * @brief Emitted when user wants to show details for this game
85 */
86 void showDetailsRequested(const QString& gameId);
87
88 public slots:
89 /**
90 * @brief Apply current theme colors
91 */
92 void applyTheme();
93
94 protected:
95 void paintEvent(QPaintEvent* event) override;
96 void mousePressEvent(QMouseEvent* event) override;
97 void enterEvent(QEnterEvent* event) override;
98 void leaveEvent(QEvent* event) override;
99
100 private:
101 void updateTooltip();
102 void updateStyleSheet();
103 void drawSparkline(QPainter& painter, const QRect& rect);
104 QString formatDuration(int seconds) const;
105
106 // Current state
107 QString currentGameId_;
108 QString gameName_;
109 QString trackedProcessName_; // Actual game process for launcher games
110 int runningSeconds_ = 0;
111 double fps_ = 0.0;
112 double frametime_ = 0.0;
113 std::vector<double> frametimeHistory_;
114
115 // Launch info for tooltip
116 QStringList optimizations_;
117 QString runner_;
118 QString protonVersion_;
119
120 // Visual state
121 bool hovered_ = false;
122
123 // Layout elements
124 QHBoxLayout* layout_ = nullptr;
125 QLabel* iconLabel_ = nullptr;
126 QLabel* nameLabel_ = nullptr;
127 QLabel* timeLabel_ = nullptr;
128 QLabel* fpsLabel_ = nullptr;
129 QWidget* sparklineWidget_ = nullptr;
130
131 // Constants
132 static constexpr int SPARKLINE_WIDTH = 50;
133 static constexpr int SPARKLINE_HEIGHT = 16;
134
135 ThemeManager* themeManager_;
136};
void updateStatus(const QString &gameId, const QString &gameName, int runningSeconds, double fps, double frametime, const std::vector< double > &frametimeHistory, const QString &trackedProcessName=QString())
Update the widget with current game info.
void clear()
Clear the widget (no game running).
~RunningGameStatusWidget() override=default
void mousePressEvent(QMouseEvent *event) override
void enterEvent(QEnterEvent *event) override
QString currentGameId() const
Get current game ID.
void applyTheme()
Apply current theme colors.
RunningGameStatusWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void leaveEvent(QEvent *event) override
bool hasActiveGame() const
Check if widget has active game data.
void paintEvent(QPaintEvent *event) override
void clicked()
Emitted when widget is clicked.
void setLaunchInfo(const QStringList &optimizations, const QString &runner, const QString &protonVersion)
Set detailed tooltip info about launch configuration.
void showDetailsRequested(const QString &gameId)
Emitted when user wants to show details for this game.