forked from qt-creator/qt-creator
ProjectExplorer: Avoid accidental changes on spinbox via mouse scroll
- Introduced an Utils::attachWheelBlocker() to disable mouse wheel events on the "Parallel Jobs" field. - This prevents unintentional modifications when users inadvertently scroll over the input. Change-Id: Iccb93305fbcf399cae683412078782b5ea9f4ad6 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -69,6 +69,7 @@ add_qtc_library(Utils
|
|||||||
genericconstants.h
|
genericconstants.h
|
||||||
globalfilechangeblocker.cpp globalfilechangeblocker.h
|
globalfilechangeblocker.cpp globalfilechangeblocker.h
|
||||||
guard.cpp guard.h
|
guard.cpp guard.h
|
||||||
|
guiutils.cpp guiutils.h
|
||||||
headerviewstretcher.cpp headerviewstretcher.h
|
headerviewstretcher.cpp headerviewstretcher.h
|
||||||
highlightingitemdelegate.cpp highlightingitemdelegate.h
|
highlightingitemdelegate.cpp highlightingitemdelegate.h
|
||||||
historycompleter.cpp historycompleter.h
|
historycompleter.cpp historycompleter.h
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "checkablemessagebox.h"
|
#include "checkablemessagebox.h"
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
#include "fancylineedit.h"
|
#include "fancylineedit.h"
|
||||||
|
#include "guiutils.h"
|
||||||
#include "iconbutton.h"
|
#include "iconbutton.h"
|
||||||
#include "layoutbuilder.h"
|
#include "layoutbuilder.h"
|
||||||
#include "passworddialog.h"
|
#include "passworddialog.h"
|
||||||
@@ -2195,6 +2196,7 @@ void IntegerAspect::addToLayout(Layouting::LayoutItem &parent)
|
|||||||
d->m_spinBox->setRange(int(d->m_minimumValue.value() / d->m_displayScaleFactor),
|
d->m_spinBox->setRange(int(d->m_minimumValue.value() / d->m_displayScaleFactor),
|
||||||
int(d->m_maximumValue.value() / d->m_displayScaleFactor));
|
int(d->m_maximumValue.value() / d->m_displayScaleFactor));
|
||||||
d->m_spinBox->setValue(int(value() / d->m_displayScaleFactor)); // Must happen after setRange()
|
d->m_spinBox->setValue(int(value() / d->m_displayScaleFactor)); // Must happen after setRange()
|
||||||
|
attachWheelBlocker(d->m_spinBox);
|
||||||
addLabeledItem(parent, d->m_spinBox);
|
addLabeledItem(parent, d->m_spinBox);
|
||||||
connect(d->m_spinBox.data(), &QSpinBox::valueChanged,
|
connect(d->m_spinBox.data(), &QSpinBox::valueChanged,
|
||||||
this, &IntegerAspect::handleGuiChanged);
|
this, &IntegerAspect::handleGuiChanged);
|
||||||
@@ -2294,6 +2296,7 @@ void DoubleAspect::addToLayout(LayoutItem &builder)
|
|||||||
d->m_spinBox->setSpecialValueText(d->m_specialValueText);
|
d->m_spinBox->setSpecialValueText(d->m_specialValueText);
|
||||||
if (d->m_maximumValue && d->m_maximumValue)
|
if (d->m_maximumValue && d->m_maximumValue)
|
||||||
d->m_spinBox->setRange(d->m_minimumValue.value(), d->m_maximumValue.value());
|
d->m_spinBox->setRange(d->m_minimumValue.value(), d->m_maximumValue.value());
|
||||||
|
attachWheelBlocker(d->m_spinBox);
|
||||||
bufferToGui(); // Must happen after setRange()!
|
bufferToGui(); // Must happen after setRange()!
|
||||||
addLabeledItem(builder, d->m_spinBox);
|
addLabeledItem(builder, d->m_spinBox);
|
||||||
connect(d->m_spinBox.data(), &QDoubleSpinBox::valueChanged,
|
connect(d->m_spinBox.data(), &QDoubleSpinBox::valueChanged,
|
||||||
|
|||||||
34
src/libs/utils/guiutils.cpp
Normal file
34
src/libs/utils/guiutils.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (C) 2023 Tasuku Suzuki <tasuku.suzuki@signal-slot.co.jp>
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "guiutils.h"
|
||||||
|
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class WheelEventFilter : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event) override {
|
||||||
|
auto widget = qobject_cast<QWidget *>(watched);
|
||||||
|
return event->type() == QEvent::Wheel
|
||||||
|
&& widget
|
||||||
|
&& widget->focusPolicy() != Qt::WheelFocus
|
||||||
|
&& !widget->hasFocus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
|
||||||
|
void QTCREATOR_UTILS_EXPORT attachWheelBlocker(QWidget *widget)
|
||||||
|
{
|
||||||
|
static Internal::WheelEventFilter instance;
|
||||||
|
widget->installEventFilter(&instance);
|
||||||
|
widget->setFocusPolicy(Qt::StrongFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
14
src/libs/utils/guiutils.h
Normal file
14
src/libs/utils/guiutils.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2023 Tasuku Suzuki <tasuku.suzuki@signal-slot.co.jp>
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils_global.h"
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
void QTCREATOR_UTILS_EXPORT attachWheelBlocker(QWidget *widget);
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/guiutils.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
@@ -105,6 +106,7 @@ GeneralSettingsPageWidget::GeneralSettingsPageWidget()
|
|||||||
zoomSpinBox->setSingleStep(10);
|
zoomSpinBox->setSingleStep(10);
|
||||||
zoomSpinBox->setValue(100);
|
zoomSpinBox->setValue(100);
|
||||||
zoomSpinBox->setSuffix(Tr::tr("%"));
|
zoomSpinBox->setSuffix(Tr::tr("%"));
|
||||||
|
attachWheelBlocker(zoomSpinBox);
|
||||||
antialiasCheckBox = new QCheckBox(Tr::tr("Antialias"));
|
antialiasCheckBox = new QCheckBox(Tr::tr("Antialias"));
|
||||||
|
|
||||||
auto fontGroupBox = new QGroupBox(Tr::tr("Font"));
|
auto fontGroupBox = new QGroupBox(Tr::tr("Font"));
|
||||||
|
|||||||
Reference in New Issue
Block a user