Skip to content

Commit

Permalink
Qt: Ignore mouse wheel event in combo and spin boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesthobe committed Jul 3, 2023
1 parent d9dbf2c commit 0be6400
Show file tree
Hide file tree
Showing 47 changed files with 632 additions and 321 deletions.
2 changes: 1 addition & 1 deletion common/vsprops/QtCompile.props
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<Message Text="moc %(QtMoc.Filename) $(QtToolOutDir)%(QtMoc.RelativeDir)moc_%(QtMoc.Filename).cpp" Importance="High" />
<Error Condition="!$(QtDirValid)" Text="Qt directory non-existent (download/extract the zip)" />
<MakeDir Directories="$(QtToolOutDir)" />
<Exec Command="&quot;$(QtHostBinDir)moc.exe&quot; &quot;%(QtMoc.FullPath)&quot; -b &quot;PrecompiledHeader.h&quot; -o &quot;$(QtToolOutDir)%(QtMoc.RelativeDir)moc_%(QtMoc.Filename).cpp&quot; -f%(QtMoc.Filename)%(QtMoc.Extension) $(MocDefines) $(MocIncludes)" />
<Exec Command="mkdir &quot;$(QtToolOutDir)%(QtMoc.RelativeDir)&quot; &amp; &quot;$(QtHostBinDir)moc.exe&quot; &quot;%(QtMoc.FullPath)&quot; -b &quot;PrecompiledHeader.h&quot; -o &quot;$(QtToolOutDir)%(QtMoc.RelativeDir)moc_%(QtMoc.Filename).cpp&quot; -f%(QtMoc.Filename)%(QtMoc.Extension) $(MocDefines) $(MocIncludes)" />
</Target>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions pcsx2-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ target_sources(pcsx2-qt PRIVATE
Settings/SettingsDialog.ui
Settings/USBBindingWidget_DrivingForce.ui
Settings/USBBindingWidget_GTForce.ui
CustomQtWidgets/NoScrollQComboBox.h
CustomQtWidgets/NoScrollQDoubleSpinBox.h
CustomQtWidgets/NoScrollQSlider.h
CustomQtWidgets/NoScrollQSpinBox.h
Debugger/CpuWidget.cpp
Debugger/CpuWidget.h
Debugger/CpuWidget.ui
Expand Down Expand Up @@ -186,6 +190,7 @@ target_include_directories(pcsx2-qt PRIVATE
"${CMAKE_BINARY_DIR}/common/include"
"${CMAKE_SOURCE_DIR}/pcsx2"
"${CMAKE_SOURCE_DIR}/pcsx2-qt"
"${CMAKE_SOURCE_DIR}/pcsx2-qt/CustomQtWidgets"
)

target_link_libraries(pcsx2-qt PRIVATE
Expand Down
36 changes: 36 additions & 0 deletions pcsx2-qt/CustomQtWidgets/NoScrollQComboBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include <QtWidgets/QComboBox>

class NoScrollQComboBox : public QComboBox
{
Q_OBJECT
void wheelEvent(QWheelEvent* event) override
{
if (hasFocus())
{
QComboBox::wheelEvent(event);
}
else
((QEvent*)event)->ignore();
};
void focusInEvent(QFocusEvent* event) override
{
QComboBox::focusInEvent(event);
setPalette(HighlightPalette);
};
void focusOutEvent(QFocusEvent* event) override
{
QComboBox::focusOutEvent(event);
setPalette(DefaultPalette);
};
QPalette DefaultPalette;
QPalette HighlightPalette;
public:
explicit NoScrollQComboBox(QWidget *parent = nullptr) : QComboBox(parent)
{
setFocusPolicy(Qt::StrongFocus);
DefaultPalette = QPalette();
HighlightPalette = QPalette();
HighlightPalette.setColor(QPalette::Window, Qt::black);
}
};
21 changes: 21 additions & 0 deletions pcsx2-qt/CustomQtWidgets/NoScrollQDoubleSpinBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <QtWidgets/QDoubleSpinBox>

class NoScrollQDoubleSpinBox : public QDoubleSpinBox
{
Q_OBJECT
void wheelEvent(QWheelEvent* event) override
{
if (hasFocus())
{
QDoubleSpinBox::wheelEvent(event);
}
else
((QEvent*)event)->ignore();
};
public:
explicit NoScrollQDoubleSpinBox(QWidget *parent = nullptr) : QDoubleSpinBox(parent)
{
setFocusPolicy(Qt::StrongFocus);
}
};
36 changes: 36 additions & 0 deletions pcsx2-qt/CustomQtWidgets/NoScrollQSlider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include <QtWidgets/QSlider>

class NoScrollQSlider : public QSlider
{
Q_OBJECT
void wheelEvent(QWheelEvent* event) override
{
if (hasFocus())
{
QSlider::wheelEvent(event);
}
else
((QEvent*)event)->ignore();
};
void focusInEvent(QFocusEvent* event) override
{
QSlider::focusInEvent(event);
setPalette(HighlightPalette);
};
void focusOutEvent(QFocusEvent* event) override
{
QSlider::focusOutEvent(event);
setPalette(DefaultPalette);
};
QPalette DefaultPalette;
QPalette HighlightPalette;
public:
explicit NoScrollQSlider(QWidget *parent = nullptr) : QSlider(parent)
{
setFocusPolicy(Qt::StrongFocus);
DefaultPalette = QPalette();
HighlightPalette = QPalette();
HighlightPalette.setColor(QPalette::Window, Qt::black);
}
};
21 changes: 21 additions & 0 deletions pcsx2-qt/CustomQtWidgets/NoScrollQSpinBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <QtWidgets/QSpinBox>

class NoScrollQSpinBox : public QSpinBox
{
Q_OBJECT
void wheelEvent(QWheelEvent* event) override
{
if (hasFocus())
{
QSpinBox::wheelEvent(event);
}
else
((QEvent*)event)->ignore();
};
public:
explicit NoScrollQSpinBox(QWidget *parent = nullptr) : QSpinBox(parent)
{
setFocusPolicy(Qt::StrongFocus);
}
};
2 changes: 1 addition & 1 deletion pcsx2-qt/Debugger/CpuWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CpuWidget::CpuWidget(QWidget* parent, DebugInterface& cpu)

connect(m_ui.btnSearch, &QPushButton::clicked, this, &CpuWidget::onSearchButtonClicked);
connect(m_ui.listSearchResults, &QListWidget::itemDoubleClicked, [this](QListWidgetItem* item) { m_ui.memoryviewWidget->gotoAddress(item->data(256).toUInt()); });
connect(m_ui.cmbSearchType, &QComboBox::currentIndexChanged, [this](int i) {
connect(m_ui.cmbSearchType, &NoScrollQComboBox::currentIndexChanged, [this](int i) {
if (i < 4)
m_ui.chkSearchHex->setEnabled(true);
else
Expand Down
7 changes: 6 additions & 1 deletion pcsx2-qt/Debugger/CpuWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbSearchType">
<widget class="NoScrollQComboBox" name="cmbSearchType">
<item>
<property name="text">
<string>1 Byte (8 bits)</string>
Expand Down Expand Up @@ -524,6 +524,11 @@
<header>pcsx2-qt/Debugger/MemoryViewWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>NoScrollQComboBox</class>
<extends>QComboBox</extends>
<header>NoScrollQComboBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
6 changes: 3 additions & 3 deletions pcsx2-qt/GameList/GameListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ void GameListWidget::initialize()

connect(m_ui.viewGameList, &QPushButton::clicked, this, &GameListWidget::showGameList);
connect(m_ui.viewGameGrid, &QPushButton::clicked, this, &GameListWidget::showGameGrid);
connect(m_ui.gridScale, &QSlider::valueChanged, this, &GameListWidget::gridIntScale);
connect(m_ui.gridScale, &NoScrollQSlider::valueChanged, this, &GameListWidget::gridIntScale);
connect(m_ui.viewGridTitles, &QPushButton::toggled, this, &GameListWidget::setShowCoverTitles);
connect(m_ui.filterType, &QComboBox::currentIndexChanged, this, [this](int index) {
connect(m_ui.filterType, &NoScrollQComboBox::currentIndexChanged, this, [this](int index) {
m_sort_model->setFilterType((index == 0) ? GameList::EntryType::Count : static_cast<GameList::EntryType>(index - 1));
});
connect(m_ui.filterRegion, &QComboBox::currentIndexChanged, this, [this](int index) {
connect(m_ui.filterRegion, &NoScrollQComboBox::currentIndexChanged, this, [this](int index) {
m_sort_model->setFilterRegion((index == 0) ? GameList::Region::Count : static_cast<GameList::Region>(index - 1));
});
connect(m_ui.searchText, &QLineEdit::textChanged, this, [this](const QString& text) {
Expand Down
18 changes: 15 additions & 3 deletions pcsx2-qt/GameList/GameListWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</widget>
</item>
<item>
<widget class="QSlider" name="gridScale">
<widget class="NoScrollQSlider" name="gridScale">
<property name="minimumSize">
<size>
<width>125</width>
Expand Down Expand Up @@ -163,7 +163,7 @@
<number>6</number>
</property>
<item>
<widget class="QComboBox" name="filterType">
<widget class="NoScrollQComboBox" name="filterType">
<item>
<property name="text">
<string>All Types</string>
Expand All @@ -176,7 +176,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="filterRegion">
<widget class="NoScrollQComboBox" name="filterRegion">
<item>
<property name="text">
<string>All Regions</string>
Expand Down Expand Up @@ -213,6 +213,18 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>NoScrollQComboBox</class>
<extends>QComboBox</extends>
<header>NoScrollQComboBox.h</header>
</customwidget>
<customwidget>
<class>NoScrollQSlider</class>
<extends>QSlider</extends>
<header>NoScrollQSlider.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/resources.qrc"/>
</resources>
Expand Down
2 changes: 1 addition & 1 deletion pcsx2-qt/QtUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QtGui/QDesktopServices>
#include <QtGui/QKeyEvent>
#include <QtGui/QScreen>
#include <QtWidgets/QComboBox>
#include "CustomQtWidgets/NoScrollQComboBox.h"
#include <QtWidgets/QDialog>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QInputDialog>
Expand Down
2 changes: 1 addition & 1 deletion pcsx2-qt/QtUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class ByteStream;

class QAction;
class QComboBox;
class NoScrollQComboBox;
class QFrame;
class QKeyEvent;
class QTableView;
Expand Down
Loading

0 comments on commit 0be6400

Please sign in to comment.