1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +01:00

Qt: Fix SnapSlider in settings

The SnapSlider function is used to snap the current slider to certain values if modified with the mouse.
But it only triggered if the user was dragging the handle of the slider and not if the bar itself was clicked.

This is fixed by using an eventFilter that listens for mousepress and mouserelease events instead of the sliderPressed and sliderReleased signals.
Maybe this is a Qt bug, but I don't want to bother with reporting this right now.
This commit is contained in:
Megamouse 2021-09-26 11:57:19 +02:00
parent df96be199b
commit b217e8384c
2 changed files with 23 additions and 9 deletions

View File

@ -1869,24 +1869,25 @@ void settings_dialog::EnhanceSlider(emu_settings_type settings_type, QSlider* sl
void settings_dialog::SnapSlider(QSlider *slider, int interval)
{
connect(slider, &QSlider::sliderPressed, [this, slider]()
if (!slider)
{
m_current_slider = slider;
});
connect(slider, &QSlider::sliderReleased, [this]()
{
m_current_slider = nullptr;
});
return;
}
// Snap the slider to the next best interval position if the slider is currently modified with the mouse.
connect(slider, &QSlider::valueChanged, [this, slider, interval](int value)
{
if (slider != m_current_slider)
if (!slider || slider != m_current_slider)
{
return;
}
slider->setValue(utils::rounded_div(value, interval) * interval);
});
// Register the slider for the event filter which updates m_current_slider if a QSlider was pressed or released with the mouse.
// We can't just use sliderPressed and sliderReleased signals to update m_current_slider because those only trigger if the handle was clicked.
slider->installEventFilter(this);
m_snap_sliders.insert(slider);
}
void settings_dialog::AddStylesheets()
@ -1987,6 +1988,18 @@ void settings_dialog::SubscribeTooltip(QObject* object, const QString& tooltip)
// Thanks Dolphin
bool settings_dialog::eventFilter(QObject* object, QEvent* event)
{
if (m_snap_sliders.contains(object))
{
if (event->type() == QEvent::MouseButtonPress)
{
m_current_slider = static_cast<QSlider*>(object);
}
else if (event->type() == QEvent::MouseButtonRelease)
{
m_current_slider = nullptr;
}
}
if (!m_descriptions.contains(object))
{
return QDialog::eventFilter(object, event);

View File

@ -34,6 +34,7 @@ private:
// Snapping of sliders when moved with mouse
void SnapSlider(QSlider* slider, int interval);
QSlider* m_current_slider = nullptr;
std::set<QObject*> m_snap_sliders;
// Gui tab
void AddStylesheets();