mirror of
https://github.com/stenzek/duckstation.git
synced 2026-05-20 23:16:35 +00:00
Qt: Allow binding both active and inactive LED colours
This commit is contained in:
@@ -46,7 +46,6 @@ set(SRCS
|
||||
controllerglobalsettingswidget.cpp
|
||||
controllerglobalsettingswidget.h
|
||||
controllerglobalsettingswidget.ui
|
||||
controllerledsettingsdialog.ui
|
||||
controllermacroeditwidget.ui
|
||||
controllermacrowidget.ui
|
||||
controllersettingswindow.cpp
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
#include "colorpickerbutton.h"
|
||||
#include "qtutils.h"
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtWidgets/QColorDialog>
|
||||
#include <QtWidgets/QStyle>
|
||||
#include <QtWidgets/QStyleOptionButton>
|
||||
|
||||
#include "moc_colorpickerbutton.cpp"
|
||||
|
||||
ColorPickerButton::ColorPickerButton(QWidget* parent) : QPushButton(parent)
|
||||
{
|
||||
connect(this, &QPushButton::clicked, this, &ColorPickerButton::onClicked);
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
||||
u32 ColorPickerButton::color()
|
||||
@@ -25,12 +27,42 @@ void ColorPickerButton::setColor(u32 rgb)
|
||||
return;
|
||||
|
||||
m_color = rgb;
|
||||
updateBackgroundColor();
|
||||
update();
|
||||
}
|
||||
|
||||
void ColorPickerButton::updateBackgroundColor()
|
||||
void ColorPickerButton::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
setStyleSheet(QStringLiteral("background-color: #%1;").arg(static_cast<uint>(m_color), 8, 16, QChar('0')));
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainter painter(this);
|
||||
QStyleOptionButton option;
|
||||
option.initFrom(this);
|
||||
|
||||
if (isDown())
|
||||
option.state |= QStyle::State_Sunken;
|
||||
if (isDefault())
|
||||
option.features |= QStyleOptionButton::DefaultButton;
|
||||
|
||||
// Get the content rect (area inside the border)
|
||||
const QRect contentRect = style()->subElementRect(QStyle::SE_PushButtonContents, &option, this);
|
||||
|
||||
// Draw the button frame first (this includes the border but should not fill the interior)
|
||||
style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &option, &painter, this);
|
||||
|
||||
// Fill the content area with our custom color
|
||||
painter.fillRect(contentRect, QColor::fromRgb(m_color));
|
||||
|
||||
// Draw the focus rectangle if needed
|
||||
if (option.state & QStyle::State_HasFocus)
|
||||
{
|
||||
QStyleOptionFocusRect focusOption;
|
||||
focusOption.initFrom(this);
|
||||
focusOption.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &option, this);
|
||||
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOption, &painter, this);
|
||||
}
|
||||
|
||||
// Draw the button label (text/icon) on top
|
||||
style()->drawControl(QStyle::CE_PushButtonLabel, &option, &painter, this);
|
||||
}
|
||||
|
||||
void ColorPickerButton::onClicked()
|
||||
@@ -49,6 +81,6 @@ void ColorPickerButton::onClicked()
|
||||
const u32 new_rgb = (static_cast<u32>(selected.red()) << 16) | (static_cast<u32>(selected.green()) << 8) |
|
||||
static_cast<u32>(selected.blue());
|
||||
m_color = new_rgb;
|
||||
updateBackgroundColor();
|
||||
update();
|
||||
emit colorChanged(new_rgb);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@ public:
|
||||
Q_SIGNALS:
|
||||
void colorChanged(quint32 new_color);
|
||||
|
||||
private:
|
||||
void updateBackgroundColor();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
void onClicked();
|
||||
|
||||
u32 m_color = 0;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "controllerbindingwidgets.h"
|
||||
#include "controllersettingswindow.h"
|
||||
#include "controllersettingwidgetbinder.h"
|
||||
#include "flowlayout.h"
|
||||
#include "qtutils.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
|
||||
@@ -13,6 +14,11 @@
|
||||
#include "util/ini_settings_interface.h"
|
||||
#include "util/sdl_input_source.h"
|
||||
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QGridLayout>
|
||||
#include <QtWidgets/QGroupBox>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
||||
#include "moc_controllerglobalsettingswidget.cpp"
|
||||
|
||||
ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, ControllerSettingsWindow* dialog)
|
||||
@@ -94,12 +100,6 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent,
|
||||
|
||||
ControllerGlobalSettingsWidget::~ControllerGlobalSettingsWidget() = default;
|
||||
|
||||
void ControllerGlobalSettingsWidget::ledSettingsClicked()
|
||||
{
|
||||
ControllerLEDSettingsDialog dialog(this, m_dialog);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void ControllerGlobalSettingsWidget::sdlHelpTextLinkClicked(const QString& link)
|
||||
{
|
||||
if (link == QStringLiteral("ADVANCED_SDL_OPTIONS"))
|
||||
@@ -124,30 +124,60 @@ void ControllerGlobalSettingsWidget::updateSDLOptionsEnabled()
|
||||
m_ui.ledSettings->setEnabled(enabled);
|
||||
}
|
||||
|
||||
ControllerLEDSettingsDialog::ControllerLEDSettingsDialog(QWidget* parent, ControllerSettingsWindow* dialog)
|
||||
: QDialog(parent), m_dialog(dialog)
|
||||
void ControllerGlobalSettingsWidget::ledSettingsClicked()
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
m_ui.buttonBox->button(QDialogButtonBox::Close)->setDefault(true);
|
||||
static constexpr auto config_key = [](u32 player_id, bool active) {
|
||||
return TinyString::from_format("Player{}{}LED", player_id, active ? "Active" : "");
|
||||
};
|
||||
|
||||
linkButton(m_ui.SDL0LED, 0);
|
||||
linkButton(m_ui.SDL1LED, 1);
|
||||
linkButton(m_ui.SDL2LED, 2);
|
||||
linkButton(m_ui.SDL3LED, 3);
|
||||
if (std::ranges::none_of(
|
||||
g_emu_thread->getInputDeviceListModel()->getDeviceList(),
|
||||
[](const InputDeviceListModel::Device& dev) { return (dev.key.source_type == InputSourceType::SDL); }))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("No SDL devices are currently connected."));
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::accept);
|
||||
}
|
||||
|
||||
ControllerLEDSettingsDialog::~ControllerLEDSettingsDialog() = default;
|
||||
|
||||
void ControllerLEDSettingsDialog::linkButton(ColorPickerButton* button, u32 player_id)
|
||||
{
|
||||
std::string key = fmt::format("Player{}LED", player_id);
|
||||
const u32 current_value =
|
||||
SDLInputSource::ParseRGBForPlayerId(m_dialog->getStringValue("SDLExtra", key.c_str(), ""), player_id, false);
|
||||
button->setColor(current_value);
|
||||
|
||||
connect(button, &ColorPickerButton::colorChanged, this, [this, key = std::move(key)](u32 new_rgb) {
|
||||
m_dialog->setStringValue("SDLExtra", key.c_str(), fmt::format("{:06X}", new_rgb).c_str());
|
||||
});
|
||||
QDialog dlg(this);
|
||||
dlg.setWindowTitle(tr("Controller LED Settings"));
|
||||
dlg.setMaximumWidth(550);
|
||||
dlg.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
QVBoxLayout* const main_layout = new QVBoxLayout(&dlg);
|
||||
FlowLayout* const flow_layout = new FlowLayout();
|
||||
|
||||
for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel()->getDeviceList())
|
||||
{
|
||||
if (dev.key.source_type != InputSourceType::SDL)
|
||||
continue;
|
||||
|
||||
QGroupBox* const gbox = new QGroupBox(QStringLiteral("%1: %2").arg(dev.identifier).arg(dev.display_name), &dlg);
|
||||
gbox->setFixedWidth(250);
|
||||
QGridLayout* const gbox_layout = new QGridLayout(gbox);
|
||||
for (u32 active = 0; active < 2; active++)
|
||||
{
|
||||
gbox_layout->addWidget(new QLabel(active ? tr("Active:") : tr("Inactive:"), &dlg), static_cast<int>(active), 0);
|
||||
|
||||
ColorPickerButton* const button = new ColorPickerButton(gbox);
|
||||
button->setColor(SDLInputSource::ParseRGBForPlayerId(
|
||||
m_dialog->getStringValue("SDLExtra", config_key(dev.key.source_index, active != 0), ""), dev.key.source_index,
|
||||
active != 0));
|
||||
gbox_layout->addWidget(button, static_cast<int>(active), 1);
|
||||
connect(button, &ColorPickerButton::colorChanged, this,
|
||||
[this, player_id = dev.key.source_index, active](u32 new_rgb) {
|
||||
m_dialog->setStringValue("SDLExtra", config_key(player_id, active),
|
||||
TinyString::from_format("{:06X}", new_rgb));
|
||||
});
|
||||
}
|
||||
|
||||
flow_layout->addWidget(gbox);
|
||||
}
|
||||
|
||||
main_layout->addLayout(flow_layout);
|
||||
|
||||
QDialogButtonBox* const bbox = new QDialogButtonBox(QDialogButtonBox::Close, &dlg);
|
||||
connect(bbox, &QDialogButtonBox::rejected, &dlg, &QDialog::accept);
|
||||
main_layout->addWidget(bbox);
|
||||
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
#pragma once
|
||||
#include "common/types.h"
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "colorpickerbutton.h"
|
||||
|
||||
#include "ui_controllerglobalsettingswidget.h"
|
||||
#include "ui_controllerledsettingsdialog.h"
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
class ControllerSettingsWindow;
|
||||
|
||||
@@ -30,24 +24,9 @@ Q_SIGNALS:
|
||||
|
||||
private:
|
||||
void updateSDLOptionsEnabled();
|
||||
void ledSettingsClicked();
|
||||
void sdlHelpTextLinkClicked(const QString& link);
|
||||
void ledSettingsClicked();
|
||||
|
||||
Ui::ControllerGlobalSettingsWidget m_ui;
|
||||
ControllerSettingsWindow* m_dialog;
|
||||
};
|
||||
|
||||
class ControllerLEDSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ControllerLEDSettingsDialog(QWidget* parent, ControllerSettingsWindow* dialog);
|
||||
~ControllerLEDSettingsDialog();
|
||||
|
||||
private:
|
||||
void linkButton(ColorPickerButton* button, u32 player_id);
|
||||
|
||||
Ui::ControllerLEDSettingsDialog m_ui;
|
||||
ControllerSettingsWindow* m_dialog;
|
||||
};
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ControllerLEDSettingsDialog</class>
|
||||
<widget class="QDialog" name="ControllerLEDSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>118</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Controller LED Settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>SDL-0 LED</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="ColorPickerButton" name="SDL0LED"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>SDL-3 LED</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="ColorPickerButton" name="SDL3LED"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>SDL-1 LED</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="ColorPickerButton" name="SDL1LED"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>SDL-2 LED</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="ColorPickerButton" name="SDL2LED"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ColorPickerButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>colorpickerbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -268,9 +268,6 @@
|
||||
</QtTs>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUi Include="controllerledsettingsdialog.ui">
|
||||
<FileType>Document</FileType>
|
||||
</QtUi>
|
||||
<QtUi Include="setupwizarddialog.ui">
|
||||
<FileType>Document</FileType>
|
||||
</QtUi>
|
||||
|
||||
@@ -151,7 +151,6 @@
|
||||
<QtUi Include="controllerbindingwidget_mouse.ui" />
|
||||
<QtUi Include="coverdownloadwindow.ui" />
|
||||
<QtUi Include="setupwizarddialog.ui" />
|
||||
<QtUi Include="controllerledsettingsdialog.ui" />
|
||||
<QtUi Include="debuggeraddbreakpointdialog.ui" />
|
||||
<QtUi Include="graphicssettingswidget.ui" />
|
||||
<QtUi Include="memoryscannerwindow.ui" />
|
||||
|
||||
Reference in New Issue
Block a user