14 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
16 setMouseTracking(
true);
17 setCursor(Qt::PointingHandCursor);
20 layout_ =
new QHBoxLayout(
this);
21 layout_->setContentsMargins(12, 6, 12, 6);
22 layout_->setSpacing(0);
25 iconLabel_ =
new QLabel(
this);
27 iconLabel_->setStyleSheet(
28 QString(
"color: %1; font-family: '%2'; font-size: 12px;")
30 layout_->addWidget(iconLabel_);
32 layout_->addSpacing(8);
35 nameLabel_ =
new QLabel(
this);
36 nameLabel_->setMaximumWidth(150);
37 layout_->addWidget(nameLabel_);
39 layout_->addSpacing(12);
43 clockIcon->setStyleSheet(
45 layout_->addWidget(clockIcon);
46 layout_->addSpacing(4);
48 timeLabel_ =
new QLabel(
this);
49 timeLabel_->setMinimumWidth(50);
50 layout_->addWidget(timeLabel_);
52 layout_->addSpacing(12);
55 fpsLabel_ =
new QLabel(
this);
56 fpsLabel_->setMinimumWidth(70);
57 layout_->addWidget(fpsLabel_);
59 layout_->addSpacing(8);
62 sparklineWidget_ =
new QWidget(
this);
63 sparklineWidget_->setFixedSize(SPARKLINE_WIDTH, SPARKLINE_HEIGHT);
64 layout_->addWidget(sparklineWidget_);
75void RunningGameStatusWidget::updateStyleSheet()
84 QString(
"RunningGameStatusWidget { background-color: %1; border-radius: 6px; border: 1px "
86 "QLabel { color: %2; font-size: 11px; background: transparent; border: none; }")
91 setStyleSheet(baseStyle);
96 nameLabel_->setStyleSheet(QString(
"color: %1; font-weight: 600; font-size: 11px; "
97 "background: transparent; border: none;")
104 timeLabel_->setStyleSheet(
105 QString(
"color: %1; font-size: 11px; background: transparent; border: none;")
111 int runningSeconds,
double fps,
double frametime,
112 const std::vector<double>& frametimeHistory,
113 const QString& trackedProcessName)
117 bool needsUpdate = currentGameId_ != gameId || gameName_ != gameName ||
118 runningSeconds_ != runningSeconds ||
119 trackedProcessName_ != trackedProcessName || std::abs(fps_ - fps) > 0.5 ||
120 std::abs(frametime_ - frametime) > 0.1;
127 currentGameId_ = gameId;
128 gameName_ = gameName;
129 trackedProcessName_ = trackedProcessName;
130 runningSeconds_ = runningSeconds;
132 frametime_ = frametime;
133 frametimeHistory_ = frametimeHistory;
138 QString displayName = trackedProcessName.isEmpty() ? gameName : trackedProcessName;
141 if (displayName.endsWith(
".exe", Qt::CaseInsensitive))
143 displayName = displayName.left(displayName.length() - 4);
146 if (displayName.length() > 20)
149 qsizetype cutoff = 18;
150 qsizetype lastSpace = displayName.lastIndexOf(
' ', cutoff);
153 displayName = displayName.left(cutoff).trimmed() +
"…";
155 nameLabel_->setText(displayName);
158 if (!trackedProcessName.isEmpty())
160 nameLabel_->setToolTip(QString(
"%1 (via %2)").arg(trackedProcessName, gameName));
164 nameLabel_->setToolTip(gameName);
168 timeLabel_->setText(formatDuration(runningSeconds));
173 if (fps >= 144 * 0.95)
178 fpsColor = tc.
error.name();
185 QString ftStr = frametime > 0
186 ? QString(
" <span style='color: %1; font-size: 9px;'>%2ms</span>")
187 .arg(themeManager_->colors().textMuted.name())
188 .arg(frametime, 0,
'f', 1)
191 QString(
"<span style='color: %1; font-weight: bold; font-size: 12px;'>%2</span>"
192 "<span style='color: %3; font-size: 10px;'> FPS</span>%4")
194 .arg(
static_cast<int>(fps))
195 .arg(themeManager_->colors().textMuted.name())
200 fpsLabel_->setText(QString(
"<span style='color: %1; font-size: 10px;'>-- FPS</span>")
201 .arg(themeManager_->colors().textMuted.name()));
209 const QString& protonVersion)
211 optimizations_ = optimizations;
213 protonVersion_ = protonVersion;
219 currentGameId_.clear();
224 frametimeHistory_.clear();
225 optimizations_.clear();
227 protonVersion_.clear();
232void RunningGameStatusWidget::updateTooltip()
234 if (currentGameId_.isEmpty())
240 const ThemeColors& c = themeManager_->colors();
243 lines << QString(
"<b style='font-size: 12px;'>%1</b>").arg(gameName_.toHtmlEscaped());
244 lines << QString(
"<span style='color: %1;'>Running for %2</span>")
246 .arg(formatDuration(runningSeconds_));
251 lines << QString(
"<b>Frame Metrics</b>");
252 lines << QString(
" FPS: <b>%1</b>").arg(
static_cast<int>(fps_));
254 lines << QString(
" Frametime: %1 ms").arg(frametime_, 0,
'f', 2);
258 if (!runner_.isEmpty())
260 lines << QString(
"<b>Launch Config</b>");
263 if (!protonVersion_.isEmpty() && protonVersion_ !=
"Proton (Steam-managed)")
265 lines << QString(
" Runner: %1").arg(protonVersion_.toHtmlEscaped());
269 lines << QString(
" Runner: %1").arg(runner_.toHtmlEscaped());
273 if (!optimizations_.isEmpty())
276 lines << QString(
"<b>Optimizations</b>");
277 for (
const QString& opt : optimizations_)
279 lines << QString(
" • %1").arg(opt.toHtmlEscaped());
284 lines << QString(
"<i style='color: %1;'>Click to show details panel</i>")
285 .arg(themeManager_->colors().textMuted.name());
287 setToolTip(lines.join(
"<br>"));
290QString RunningGameStatusWidget::formatDuration(
int seconds)
const
292 int hours = seconds / 3600;
293 int mins = (seconds % 3600) / 60;
294 int secs = seconds % 60;
297 return QString(
"%1h %2m").arg(hours).arg(mins, 2, 10, QChar(
'0'));
299 return QString(
"%1:%2").arg(mins).arg(secs, 2, 10, QChar(
'0'));
301 return QString(
"0:%1").arg(secs, 2, 10, QChar(
'0'));
306 QWidget::paintEvent(event);
309 if (!frametimeHistory_.empty() && sparklineWidget_ && sparklineWidget_->isVisible())
311 QPainter painter(
this);
312 painter.setRenderHint(QPainter::Antialiasing);
314 QRect sparklineRect = sparklineWidget_->geometry();
315 drawSparkline(painter, sparklineRect);
319void RunningGameStatusWidget::drawSparkline(QPainter& painter,
const QRect& rect)
321 if (frametimeHistory_.empty() || frametimeHistory_.size() < 2)
325 double minFt = *std::min_element(frametimeHistory_.begin(), frametimeHistory_.end());
326 double maxFt = *std::max_element(frametimeHistory_.begin(), frametimeHistory_.end());
329 if (maxFt - minFt < 1.0)
331 minFt = std::max(0.0, minFt - 2.0);
336 double range = maxFt - minFt;
337 minFt -= range * 0.1;
338 maxFt += range * 0.1;
339 range = maxFt - minFt;
342 QColor sparkBg = themeManager_->colors().panelBackground;
343 sparkBg.setAlpha(80);
344 painter.fillRect(rect, sparkBg);
348 size_t numPoints = frametimeHistory_.size();
350 static_cast<double>(rect.width()) /
static_cast<double>(std::max(
size_t(1), numPoints - 1));
352 for (
size_t i = 0; i < numPoints; ++i)
354 double value = frametimeHistory_[i];
355 double normalized = (value - minFt) / range;
356 double x = rect.left() +
static_cast<double>(i) * xStep;
357 double y = rect.bottom() - normalized * rect.height();
367 for (
double ft : frametimeHistory_)
369 avgFt /=
static_cast<double>(frametimeHistory_.size());
371 const ThemeColors& sc = themeManager_->colors();
375 else if (avgFt <= 16.7)
378 lineColor = sc.
error;
381 QPen glowPen(lineColor.darker(150), 3.0);
382 glowPen.setCapStyle(Qt::RoundCap);
383 glowPen.setJoinStyle(Qt::RoundJoin);
384 painter.setPen(glowPen);
385 painter.setOpacity(0.3);
386 painter.drawPath(path);
389 painter.setOpacity(1.0);
390 QPen pen(lineColor, 1.5);
391 pen.setCapStyle(Qt::RoundCap);
392 pen.setJoinStyle(Qt::RoundJoin);
394 painter.drawPath(path);
397 if (!frametimeHistory_.empty())
399 double lastValue = frametimeHistory_.back();
400 double normalized = (lastValue - minFt) / range;
401 double x = rect.right() - 1;
402 double y = rect.bottom() - normalized * rect.height();
405 painter.setBrush(lineColor);
406 painter.setPen(Qt::NoPen);
407 painter.setOpacity(0.4);
408 painter.drawEllipse(QPointF(x, y), 4, 4);
411 painter.setOpacity(1.0);
412 painter.drawEllipse(QPointF(x, y), 2.5, 2.5);
418 if (event->button() == Qt::LeftButton)
421 if (!currentGameId_.isEmpty())
426 QWidget::mousePressEvent(event);
433 QWidget::enterEvent(event);
440 QWidget::leaveEvent(event);
450 iconLabel_->setStyleSheet(QString(
"color: %1; font-size: 12px;").arg(c.
success.name()));
static const QString & solidFamily()
Get the loaded Solid font family name.
static QString text(char32_t codepoint)
Convert a codepoint to a QString glyph.
void themeChanged()
Emitted when theme or accent color changes.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
constexpr char32_t ClockRotateLeft