mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-19 13:05:45 -04:00
Qt: Add Controller LED options (where supported)
This commit is contained in:
50
src/duckstation-qt/colorpickerbutton.cpp
Normal file
50
src/duckstation-qt/colorpickerbutton.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// SPDX-FileCopyrightText: 2023 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#include "colorpickerbutton.h"
|
||||
#include "qtutils.h"
|
||||
|
||||
#include <QtWidgets/QColorDialog>
|
||||
|
||||
ColorPickerButton::ColorPickerButton(QWidget* parent) : QPushButton(parent)
|
||||
{
|
||||
connect(this, &QPushButton::clicked, this, &ColorPickerButton::onClicked);
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
||||
u32 ColorPickerButton::color()
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void ColorPickerButton::setColor(u32 rgb)
|
||||
{
|
||||
if (m_color == rgb)
|
||||
return;
|
||||
|
||||
m_color = rgb;
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
||||
void ColorPickerButton::updateBackgroundColor()
|
||||
{
|
||||
setStyleSheet(QStringLiteral("background-color: #%1;").arg(static_cast<uint>(m_color), 8, 16, QChar('0')));
|
||||
}
|
||||
|
||||
void ColorPickerButton::onClicked()
|
||||
{
|
||||
const u32 red = (m_color >> 16) & 0xff;
|
||||
const u32 green = (m_color >> 8) & 0xff;
|
||||
const u32 blue = m_color & 0xff;
|
||||
|
||||
const QColor initial(QColor::fromRgb(red, green, blue));
|
||||
const QColor selected(QColorDialog::getColor(initial, QtUtils::GetRootWidget(this), tr("Select LED Color")));
|
||||
if (initial == selected)
|
||||
return;
|
||||
|
||||
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();
|
||||
emit colorChanged(new_rgb);
|
||||
}
|
Reference in New Issue
Block a user