configure_graphics: Reimplement bg_color

To specialized a setting to be worth adding to the shared_widget imo,
so add it roughly like before.
This commit is contained in:
lat9nq 2023-05-09 15:10:22 -04:00
parent c1748b229a
commit 23f874ae60
3 changed files with 111 additions and 15 deletions

View file

@ -88,7 +88,7 @@ ConfigureGraphics::ConfigureGraphics(
ui->setupUi(this);
SetConfiguration();
Setup();
for (const auto& device : vulkan_devices) {
vulkan_device_combobox->addItem(device);
@ -128,20 +128,22 @@ ConfigureGraphics::ConfigureGraphics(
connect(shader_backend_combobox, qOverload<int>(&QComboBox::activated), this,
[this](int backend) { UpdateShaderBackendSelection(backend); });
// connect(ui->bg_button, &QPushButton::clicked, this, [this] {
// const QColor new_bg_color = QColorDialog::getColor(bg_color);
// if (!new_bg_color.isValid()) {
// return;
// }
// UpdateBackgroundColorButton(new_bg_color);
// });
// ui->bg_label->setVisible(Settings::IsConfiguringGlobal());
// ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal());
connect(ui->bg_button, &QPushButton::clicked, this, [this] {
const QColor new_bg_color = QColorDialog::getColor(bg_color);
if (!new_bg_color.isValid()) {
return;
}
UpdateBackgroundColorButton(new_bg_color);
});
api_combobox->setEnabled(!UISettings::values.has_broken_vulkan && api_combobox->isEnabled());
ui->api_widget->setEnabled(
(!UISettings::values.has_broken_vulkan || Settings::IsConfiguringGlobal()) &&
ui->api_widget->isEnabled());
if (Settings::IsConfiguringGlobal()) {
ui->bg_widget->setEnabled(Settings::values.bg_red.UsingGlobal());
}
}
void ConfigureGraphics::PopulateVSyncModeSelection() {
@ -205,7 +207,9 @@ void ConfigureGraphics::UpdateShaderBackendSelection(int backend) {
ConfigureGraphics::~ConfigureGraphics() = default;
void ConfigureGraphics::SetConfiguration() {
void ConfigureGraphics::SetConfiguration() {}
void ConfigureGraphics::Setup() {
const bool runtime_lock = !system.IsPoweredOn();
QLayout* api_layout = ui->api_widget->layout();
QWidget* api_grid_widget = new QWidget(this);
@ -305,6 +309,46 @@ void ConfigureGraphics::SetConfiguration() {
for (auto widget : hold_api) {
api_grid_layout->addWidget(widget);
}
if (Settings::IsConfiguringGlobal()) {
apply_funcs.push_front([this](bool powered_on) {
Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
});
} else {
QPushButton* bg_restore_button = ConfigurationShared::Widget::CreateRestoreGlobalButton(
Settings::values.bg_red, ui->bg_widget);
ui->bg_widget->layout()->addWidget(bg_restore_button);
QObject::connect(bg_restore_button, &QAbstractButton::clicked,
[bg_restore_button, this](bool) {
const int r = Settings::values.bg_red.GetValue(true);
const int g = Settings::values.bg_green.GetValue(true);
const int b = Settings::values.bg_blue.GetValue(true);
UpdateBackgroundColorButton(QColor::fromRgb(r, g, b));
bg_restore_button->setVisible(false);
bg_restore_button->setEnabled(false);
});
QObject::connect(ui->bg_button, &QAbstractButton::clicked, [bg_restore_button](bool) {
bg_restore_button->setVisible(true);
bg_restore_button->setEnabled(true);
});
apply_funcs.push_front([bg_restore_button, this](bool powered_on) {
const bool using_global = !bg_restore_button->isEnabled();
Settings::values.bg_red.SetGlobal(using_global);
Settings::values.bg_green.SetGlobal(using_global);
Settings::values.bg_blue.SetGlobal(using_global);
if (!using_global) {
Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
}
});
}
}
const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode,
@ -375,11 +419,11 @@ void ConfigureGraphics::RetranslateUI() {
void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) {
bg_color = color;
// QPixmap pixmap(ui->bg_button->size());
// pixmap.fill(bg_color);
QPixmap pixmap(ui->bg_button->size());
pixmap.fill(bg_color);
// const QIcon color_icon(pixmap);
// ui->bg_button->setIcon(color_icon);
const QIcon color_icon(pixmap);
ui->bg_button->setIcon(color_icon);
}
void ConfigureGraphics::UpdateAPILayout() {

View file

@ -51,6 +51,8 @@ private:
void changeEvent(QEvent* event) override;
void RetranslateUI();
void Setup();
void PopulateVSyncModeSelection();
void UpdateBackgroundColorButton(QColor color);
void UpdateAPILayout();

View file

@ -76,6 +76,56 @@
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="bg_widget" native="true">
<layout class="QHBoxLayout" name="bg_layout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Background Color:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bg_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>