mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-05-07 15:01:49 -04:00
DolphinQt: Improve TAS UI Widgets
Made Stick and IR Widgets bigger Improved Stick and IR layouts to better utilize space Made Stick and IR Widgets Scale at a fixed ratio when window is resized Added Scrollbars to Stick and IR Widgets Reduced Spinbox padding in dark style
This commit is contained in:
@@ -9,13 +9,13 @@
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QEvent>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QScrollArea>
|
||||
#include <QShortcut>
|
||||
#include <QSlider>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "DolphinQt/Host.h"
|
||||
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
|
||||
@@ -108,14 +108,12 @@ QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_vi
|
||||
const int x_default = static_cast<int>(std::round(max_x / 2.));
|
||||
const int y_default = static_cast<int>(std::round(max_y / 2.));
|
||||
|
||||
auto* x_layout = new QHBoxLayout;
|
||||
TASSpinBox* x_value = CreateSliderValuePair(x_layout, x_default, max_x, x_shortcut_key_sequence,
|
||||
auto* box_layout = new QGridLayout;
|
||||
TASSpinBox* x_value = CreateSliderValuePair(box_layout, x_default, max_x, x_shortcut_key_sequence,
|
||||
Qt::Horizontal, box);
|
||||
|
||||
auto* y_layout = new QVBoxLayout;
|
||||
TASSpinBox* y_value =
|
||||
CreateSliderValuePair(y_layout, y_default, max_y, y_shortcut_key_sequence, Qt::Vertical, box);
|
||||
y_value->setMaximumWidth(60);
|
||||
TASSpinBox* y_value = CreateSliderValuePair(box_layout, y_default, max_y, y_shortcut_key_sequence,
|
||||
Qt::Vertical, box);
|
||||
|
||||
auto* visual = new StickWidget(this, max_x, max_y);
|
||||
visual->SetX(x_default);
|
||||
@@ -128,14 +126,10 @@ QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_vi
|
||||
|
||||
auto* visual_ar = new AspectRatioWidget(visual, max_x, max_y);
|
||||
|
||||
auto* visual_layout = new QHBoxLayout;
|
||||
visual_layout->addWidget(visual_ar);
|
||||
visual_layout->addLayout(y_layout);
|
||||
|
||||
auto* layout = new QVBoxLayout;
|
||||
layout->addLayout(x_layout);
|
||||
layout->addLayout(visual_layout);
|
||||
box->setLayout(layout);
|
||||
// This is done to prevent the stick widget from stretching
|
||||
box_layout->addItem(new QSpacerItem(0, 0), 2, 1);
|
||||
box_layout->addWidget(visual_ar, 1, 1);
|
||||
box->setLayout(box_layout);
|
||||
|
||||
overrider->AddFunction(group_name, ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE,
|
||||
[this, x_value, x_default, min_x, max_x](ControlState controller_state) {
|
||||
@@ -150,7 +144,7 @@ QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_vi
|
||||
return box;
|
||||
}
|
||||
|
||||
QBoxLayout* TASInputWindow::CreateSliderValuePairLayout(
|
||||
QGridLayout* TASInputWindow::CreateSliderValuePairLayout(
|
||||
const QString& text, std::string_view group_name, std::string_view control_name,
|
||||
InputOverrider* overrider, int zero, int default_, int min, int max, Qt::Key shortcut_key,
|
||||
QWidget* shortcut_widget, std::optional<ControlState> scale)
|
||||
@@ -160,8 +154,8 @@ QBoxLayout* TASInputWindow::CreateSliderValuePairLayout(
|
||||
auto* label = new QLabel(QStringLiteral("%1 (%2)").arg(
|
||||
text, shortcut_key_sequence.toString(QKeySequence::NativeText)));
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout;
|
||||
layout->addWidget(label);
|
||||
QGridLayout* layout = new QGridLayout;
|
||||
layout->addWidget(label, 0, 0);
|
||||
|
||||
CreateSliderValuePair(group_name, control_name, overrider, layout, zero, default_, min, max,
|
||||
shortcut_key_sequence, Qt::Horizontal, shortcut_widget, scale);
|
||||
@@ -171,7 +165,7 @@ QBoxLayout* TASInputWindow::CreateSliderValuePairLayout(
|
||||
|
||||
TASSpinBox* TASInputWindow::CreateSliderValuePair(
|
||||
std::string_view group_name, std::string_view control_name, InputOverrider* overrider,
|
||||
QBoxLayout* layout, int zero, int default_, int min, int max,
|
||||
QGridLayout* layout, int zero, int default_, int min, int max,
|
||||
QKeySequence shortcut_key_sequence, Qt::Orientation orientation, QWidget* shortcut_widget,
|
||||
std::optional<ControlState> scale)
|
||||
{
|
||||
@@ -199,23 +193,22 @@ TASSpinBox* TASInputWindow::CreateSliderValuePair(
|
||||
|
||||
// The shortcut_widget argument needs to specify the container widget that will be hidden/shown.
|
||||
// This is done to avoid ambiguous shortcuts
|
||||
TASSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_, int max,
|
||||
TASSpinBox* TASInputWindow::CreateSliderValuePair(QGridLayout* layout, int default_, int max,
|
||||
QKeySequence shortcut_key_sequence,
|
||||
Qt::Orientation orientation,
|
||||
QWidget* shortcut_widget)
|
||||
{
|
||||
auto* value = new TASSpinBox();
|
||||
value->setRange(0, 99999);
|
||||
value->setRange(0, max);
|
||||
value->setValue(default_);
|
||||
connect(value, &QSpinBox::valueChanged, [value, max](int i) {
|
||||
if (i > max)
|
||||
value->setValue(max);
|
||||
});
|
||||
|
||||
auto* slider = new TASSlider(default_, orientation);
|
||||
slider->setRange(0, max);
|
||||
slider->setValue(default_);
|
||||
slider->setFocusPolicy(Qt::ClickFocus);
|
||||
|
||||
value->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
connect(slider, &QSlider::valueChanged, value, &QSpinBox::setValue);
|
||||
connect(value, &QSpinBox::valueChanged, slider, &QSlider::setValue);
|
||||
|
||||
@@ -225,14 +218,45 @@ TASSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int defaul
|
||||
value->selectAll();
|
||||
});
|
||||
|
||||
layout->addWidget(slider);
|
||||
layout->addWidget(value);
|
||||
if (orientation == Qt::Vertical)
|
||||
layout->setAlignment(slider, Qt::AlignRight);
|
||||
{
|
||||
layout->addWidget(slider, 1, 2);
|
||||
layout->addWidget(value, 2, 2);
|
||||
|
||||
layout->setAlignment(slider, Qt::AlignHCenter);
|
||||
slider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
}
|
||||
else
|
||||
{
|
||||
layout->addWidget(slider, 0, 1);
|
||||
layout->addWidget(value, 0, 2);
|
||||
|
||||
slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void TASInputWindow::SetupScrollArea(QLayout* layout)
|
||||
{
|
||||
m_scroll_widget = new QWidget;
|
||||
m_scroll_widget->setLayout(layout);
|
||||
|
||||
auto* scroll_area = new QScrollArea;
|
||||
scroll_area->setWidget(m_scroll_widget);
|
||||
scroll_area->setWidgetResizable(true);
|
||||
scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scroll_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
|
||||
auto* outer_layout = new QVBoxLayout;
|
||||
outer_layout->setContentsMargins(0, 0, 0, 0);
|
||||
outer_layout->addWidget(scroll_area);
|
||||
setLayout(outer_layout);
|
||||
|
||||
layout->activate();
|
||||
m_scroll_widget->layout()->activate();
|
||||
}
|
||||
|
||||
std::optional<ControlState> TASInputWindow::GetButton(TASCheckBox* checkbox,
|
||||
ControlState controller_state)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user