mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-11 17:04:33 +00:00
Qt: Make LED settings clearer
This commit is contained in:
@@ -69,8 +69,6 @@ set(SRCS
|
||||
emulationsettingswidget.cpp
|
||||
emulationsettingswidget.h
|
||||
emulationsettingswidget.ui
|
||||
flowlayout.cpp
|
||||
flowlayout.h
|
||||
foldersettingswidget.cpp
|
||||
foldersettingswidget.h
|
||||
foldersettingswidget.ui
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "controllerbindingwidgets.h"
|
||||
#include "controllersettingswindow.h"
|
||||
#include "controllersettingwidgetbinder.h"
|
||||
#include "flowlayout.h"
|
||||
#include "qtutils.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
|
||||
@@ -17,6 +16,7 @@
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QGridLayout>
|
||||
#include <QtWidgets/QGroupBox>
|
||||
#include <QtWidgets/QScrollArea>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
||||
#include "moc_controllerglobalsettingswidget.cpp"
|
||||
@@ -140,11 +140,33 @@ void ControllerGlobalSettingsWidget::ledSettingsClicked()
|
||||
|
||||
QDialog dlg(this);
|
||||
dlg.setWindowTitle(tr("Controller LED Settings"));
|
||||
dlg.setMaximumWidth(550);
|
||||
dlg.setFixedWidth(450);
|
||||
dlg.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
QVBoxLayout* const main_layout = new QVBoxLayout(&dlg);
|
||||
FlowLayout* const flow_layout = new FlowLayout();
|
||||
|
||||
QHBoxLayout* const heading_layout = new QHBoxLayout();
|
||||
QLabel* const icon = new QLabel(&dlg);
|
||||
icon->setPixmap(QIcon::fromTheme(QStringLiteral("lightbulb-line")).pixmap(32, 32));
|
||||
QLabel* const heading = new QLabel(
|
||||
tr("<strong>Controller LED Settings</strong><br>\nThe \"alternate\" color is used when analog mode is active."),
|
||||
&dlg);
|
||||
heading->setWordWrap(true);
|
||||
heading_layout->addWidget(icon, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
heading_layout->addWidget(heading, 1);
|
||||
main_layout->addLayout(heading_layout);
|
||||
|
||||
QScrollArea* const scroll_area = new QScrollArea(&dlg);
|
||||
scroll_area->setWidgetResizable(true);
|
||||
scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scroll_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
main_layout->addWidget(scroll_area, 1);
|
||||
|
||||
QWidget* const scroll_area_widget = new QWidget(scroll_area);
|
||||
scroll_area->setWidget(scroll_area_widget);
|
||||
|
||||
QVBoxLayout* const scroll_area_layout = new QVBoxLayout(scroll_area_widget);
|
||||
scroll_area_layout->setContentsMargins(10, 10, 10, 10);
|
||||
|
||||
for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel()->getDeviceList())
|
||||
{
|
||||
@@ -152,11 +174,11 @@ void ControllerGlobalSettingsWidget::ledSettingsClicked()
|
||||
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);
|
||||
gbox_layout->addWidget(new QLabel(active ? tr("Alternate Mode:") : tr("Normal Mode:"), &dlg),
|
||||
static_cast<int>(active), 0);
|
||||
|
||||
ColorPickerButton* const button = new ColorPickerButton(gbox);
|
||||
button->setColor(SDLInputSource::ParseRGBForPlayerId(
|
||||
@@ -170,10 +192,10 @@ void ControllerGlobalSettingsWidget::ledSettingsClicked()
|
||||
});
|
||||
}
|
||||
|
||||
flow_layout->addWidget(gbox);
|
||||
scroll_area_layout->addWidget(gbox);
|
||||
}
|
||||
|
||||
main_layout->addLayout(flow_layout);
|
||||
scroll_area_layout->addStretch(1);
|
||||
|
||||
QDialogButtonBox* const bbox = new QDialogButtonBox(QDialogButtonBox::Close, &dlg);
|
||||
connect(bbox, &QDialogButtonBox::rejected, &dlg, &QDialog::accept);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
<ClCompile Include="emulationsettingswidget.cpp" />
|
||||
<ClCompile Include="debuggermodels.cpp" />
|
||||
<ClCompile Include="debuggerwindow.cpp" />
|
||||
<ClCompile Include="flowlayout.cpp" />
|
||||
<ClCompile Include="foldersettingswidget.cpp" />
|
||||
<ClCompile Include="gamecheatsettingswidget.cpp" />
|
||||
<ClCompile Include="gamepatchsettingswidget.cpp" />
|
||||
@@ -90,7 +89,6 @@
|
||||
<QtMoc Include="gamepatchsettingswidget.h" />
|
||||
<QtMoc Include="isobrowserwindow.h" />
|
||||
<QtMoc Include="debuggercodeview.h" />
|
||||
<ClInclude Include="flowlayout.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<QtMoc Include="selectdiscdialog.h" />
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
<ClCompile Include="debuggercodeview.cpp" />
|
||||
<ClCompile Include="togglebutton.cpp" />
|
||||
<ClCompile Include="memoryeditorwindow.cpp" />
|
||||
<ClCompile Include="flowlayout.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="qtutils.h" />
|
||||
@@ -58,7 +57,6 @@
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="controllersettingwidgetbinder.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="flowlayout.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="resources">
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "flowlayout.h"
|
||||
|
||||
//! [1]
|
||||
FlowLayout::FlowLayout(QWidget* parent, int margin, int hSpacing, int vSpacing)
|
||||
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||
{
|
||||
setContentsMargins(margin, margin, margin, margin);
|
||||
}
|
||||
|
||||
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) : m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||
{
|
||||
setContentsMargins(margin, margin, margin, margin);
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
FlowLayout::~FlowLayout()
|
||||
{
|
||||
QLayoutItem* item;
|
||||
while ((item = takeAt(0)))
|
||||
delete item;
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
void FlowLayout::addItem(QLayoutItem* item)
|
||||
{
|
||||
itemList.append(item);
|
||||
}
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
int FlowLayout::horizontalSpacing() const
|
||||
{
|
||||
if (m_hSpace >= 0)
|
||||
{
|
||||
return m_hSpace;
|
||||
}
|
||||
else
|
||||
{
|
||||
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
|
||||
}
|
||||
}
|
||||
|
||||
int FlowLayout::verticalSpacing() const
|
||||
{
|
||||
if (m_vSpace >= 0)
|
||||
{
|
||||
return m_vSpace;
|
||||
}
|
||||
else
|
||||
{
|
||||
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
||||
}
|
||||
}
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
int FlowLayout::count() const
|
||||
{
|
||||
return itemList.size();
|
||||
}
|
||||
|
||||
QLayoutItem* FlowLayout::itemAt(int index) const
|
||||
{
|
||||
return itemList.value(index);
|
||||
}
|
||||
|
||||
QLayoutItem* FlowLayout::takeAt(int index)
|
||||
{
|
||||
if (index >= 0 && index < itemList.size())
|
||||
return itemList.takeAt(index);
|
||||
return nullptr;
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
Qt::Orientations FlowLayout::expandingDirections() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
bool FlowLayout::hasHeightForWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int FlowLayout::heightForWidth(int width) const
|
||||
{
|
||||
int height = doLayout(QRect(0, 0, width, 0), true);
|
||||
return height;
|
||||
}
|
||||
//! [7]
|
||||
|
||||
//! [8]
|
||||
void FlowLayout::setGeometry(const QRect& rect)
|
||||
{
|
||||
QLayout::setGeometry(rect);
|
||||
doLayout(rect, false);
|
||||
}
|
||||
|
||||
QSize FlowLayout::sizeHint() const
|
||||
{
|
||||
return minimumSize();
|
||||
}
|
||||
|
||||
QSize FlowLayout::minimumSize() const
|
||||
{
|
||||
QSize size;
|
||||
for (const QLayoutItem* item : std::as_const(itemList))
|
||||
size = size.expandedTo(item->minimumSize());
|
||||
|
||||
const QMargins margins = contentsMargins();
|
||||
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
|
||||
return size;
|
||||
}
|
||||
//! [8]
|
||||
|
||||
//! [9]
|
||||
int FlowLayout::doLayout(const QRect& rect, bool testOnly) const
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
|
||||
int x = effectiveRect.x();
|
||||
int y = effectiveRect.y();
|
||||
int lineHeight = 0;
|
||||
//! [9]
|
||||
|
||||
//! [10]
|
||||
for (QLayoutItem* item : std::as_const(itemList))
|
||||
{
|
||||
const QWidget* wid = item->widget();
|
||||
int spaceX = horizontalSpacing();
|
||||
if (spaceX == -1)
|
||||
spaceX = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
||||
int spaceY = verticalSpacing();
|
||||
if (spaceY == -1)
|
||||
spaceY = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
||||
//! [10]
|
||||
//! [11]
|
||||
int nextX = x + item->sizeHint().width() + spaceX;
|
||||
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0)
|
||||
{
|
||||
x = effectiveRect.x();
|
||||
y = y + lineHeight + spaceY;
|
||||
nextX = x + item->sizeHint().width() + spaceX;
|
||||
lineHeight = 0;
|
||||
}
|
||||
|
||||
if (!testOnly)
|
||||
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
||||
|
||||
x = nextX;
|
||||
lineHeight = qMax(lineHeight, item->sizeHint().height());
|
||||
}
|
||||
return y + lineHeight - rect.y() + bottom;
|
||||
}
|
||||
//! [11]
|
||||
//! [12]
|
||||
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
|
||||
{
|
||||
QObject* parent = this->parent();
|
||||
if (!parent)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (parent->isWidgetType())
|
||||
{
|
||||
QWidget* pw = static_cast<QWidget*>(parent);
|
||||
return pw->style()->pixelMetric(pm, nullptr, pw);
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<QLayout*>(parent)->spacing();
|
||||
}
|
||||
}
|
||||
//! [12]
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QRect>
|
||||
#include <QtWidgets/QLayout>
|
||||
#include <QtWidgets/QStyle>
|
||||
|
||||
// https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/layouts/flowlayout?h=6.9
|
||||
|
||||
//! [0]
|
||||
class FlowLayout : public QLayout
|
||||
{
|
||||
public:
|
||||
explicit FlowLayout(QWidget* parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||
~FlowLayout();
|
||||
|
||||
void addItem(QLayoutItem* item) override;
|
||||
int horizontalSpacing() const;
|
||||
int verticalSpacing() const;
|
||||
Qt::Orientations expandingDirections() const override;
|
||||
bool hasHeightForWidth() const override;
|
||||
int heightForWidth(int) const override;
|
||||
int count() const override;
|
||||
QLayoutItem* itemAt(int index) const override;
|
||||
QSize minimumSize() const override;
|
||||
void setGeometry(const QRect& rect) override;
|
||||
QSize sizeHint() const override;
|
||||
QLayoutItem* takeAt(int index) override;
|
||||
|
||||
private:
|
||||
int doLayout(const QRect& rect, bool testOnly) const;
|
||||
int smartSpacing(QStyle::PixelMetric pm) const;
|
||||
|
||||
QList<QLayoutItem*> itemList;
|
||||
int m_hSpace;
|
||||
int m_vSpace;
|
||||
};
|
||||
//! [0]
|
||||
Reference in New Issue
Block a user