game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
env_var_checkbox.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// env_var_checkbox.cpp
4// ==============================================================================
5// Custom checkbox widget implementation
6// ==============================================================================
7
9#include "theme_manager.h"
10
11#include <QFont>
12#include <QVBoxLayout>
13
14EnvVarCheckBox::EnvVarCheckBox(const QString& label, const QString& envVar, const QString& tooltip,
15 QWidget* parent, ThemeManager* themeManager)
16 : QWidget(parent), envVar_(envVar),
17 themeManager_(themeManager ? themeManager : &ThemeManager::instance())
18{
19 QVBoxLayout* layout = new QVBoxLayout(this);
20 layout->setContentsMargins(0, 2, 0, 2);
21 layout->setSpacing(0);
22
23 checkbox_ = new QCheckBox(label, this);
24 if (!tooltip.isEmpty())
25 {
26 checkbox_->setToolTip(tooltip);
27 }
28 layout->addWidget(checkbox_);
29
30 // Show the env var in a smaller, monospace font
31 envVarLabel_ = new QLabel(QString(" %1").arg(envVar), this);
32 QFont monoFont("monospace", 9);
33 envVarLabel_->setFont(monoFont);
34 layout->addWidget(envVarLabel_);
35
36 applyTheme();
37
38 connect(checkbox_, &QCheckBox::toggled, this, &EnvVarCheckBox::toggled);
39 connect(themeManager_, &ThemeManager::themeChanged, this, &EnvVarCheckBox::applyTheme);
40}
41
42void EnvVarCheckBox::applyTheme()
43{
44 // The muted-text color is not a standard QPalette role, and the 20px
45 // margin is structural, so this stays as a stylesheet — reapplied on
46 // every theme change rather than being baked in once at construction.
47 envVarLabel_->setStyleSheet(
48 QString("color: %1; margin-left: 20px;").arg(themeManager_->colors().textMuted.name()));
49}
50
52{
53 return checkbox_->isChecked();
54}
55
57{
58 checkbox_->setChecked(checked);
59}
60
62{
63 checkbox_->setEnabled(enabled);
64 envVarLabel_->setEnabled(enabled);
65}
66
68{
69 // Extract key from "KEY=value" format
70 qsizetype eqPos = envVar_.indexOf('=');
71 if (eqPos > 0)
72 {
73 return envVar_.left(eqPos);
74 }
75 return envVar_;
76}
EnvVarCheckBox(const QString &label, const QString &envVar, const QString &tooltip=QString(), QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
Construct an EnvVarCheckBox.
void toggled(bool checked)
QString envVarKey() const
Get the environment variable key (everything before '=').
void setEnabled(bool enabled)
bool isChecked() const
void setChecked(bool checked)
void themeChanged()
Emitted when theme or accent color changes.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
QColor textMuted