Skip to content

Commit

Permalink
Merge pull request #1811 from akapar2016/UI_scrollWheelEvents
Browse files Browse the repository at this point in the history
Ui scroll wheel events
  • Loading branch information
jp9000 authored Apr 14, 2019
2 parents 7dacd58 + 9249403 commit 88391b8
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 10 deletions.
6 changes: 6 additions & 0 deletions UI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ set(obs_SOURCES
focus-list.cpp
menu-button.cpp
double-slider.cpp
slider-ignorewheel.cpp
comboBox-ignorewheel.cpp
spinBox-ignorewheel.cpp
volume-control.cpp
adv-audio-control.cpp
item-widget-helpers.cpp
Expand Down Expand Up @@ -283,6 +286,9 @@ set(obs_HEADERS
display-helpers.hpp
balance-slider.hpp
double-slider.hpp
slider-ignorewheel.hpp
comboBox-ignorewheel.hpp
spinBox-ignorewheel.hpp
focus-list.hpp
menu-button.hpp
mute-checkbox.hpp
Expand Down
19 changes: 19 additions & 0 deletions UI/comboBox-ignorewheel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "comboBox-ignorewheel.hpp"

ComboBoxIgnoreScroll::ComboBoxIgnoreScroll(QWidget *parent) : QComboBox(parent)
{
setFocusPolicy(Qt::StrongFocus);
}

void ComboBoxIgnoreScroll::wheelEvent(QWheelEvent * event)
{
if (!hasFocus())
event->ignore();
else
QComboBox::wheelEvent(event);
}

void ComboBoxIgnoreScroll::leaveEvent(QEvent * event)
{
clearFocus();
}
20 changes: 20 additions & 0 deletions UI/comboBox-ignorewheel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QComboBox>
#include <QInputEvent>
#include <QtCore/QObject>


class ComboBoxIgnoreScroll : public QComboBox {
Q_OBJECT

public:
ComboBoxIgnoreScroll(QWidget *parent = nullptr);

protected:

virtual void wheelEvent(QWheelEvent *event) override;
virtual void leaveEvent(QEvent *event) override;
};


2 changes: 1 addition & 1 deletion UI/double-slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cmath>

DoubleSlider::DoubleSlider(QWidget *parent) : QSlider(parent)
DoubleSlider::DoubleSlider(QWidget *parent) : SliderIgnoreScroll(parent)
{
connect(this, SIGNAL(valueChanged(int)),
this, SLOT(intValChanged(int)));
Expand Down
3 changes: 2 additions & 1 deletion UI/double-slider.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <QSlider>
#include "slider-ignorewheel.hpp"

class DoubleSlider : public QSlider {
class DoubleSlider : public SliderIgnoreScroll {
Q_OBJECT

double minVal, maxVal, minStep;
Expand Down
6 changes: 6 additions & 0 deletions UI/frontend-plugins/decklink-output-ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ set(decklink-ouput-ui_HEADERS
../../properties-view.moc.hpp
../../vertical-scroll-area.hpp
../../double-slider.hpp
../../slider-ignorewheel.hpp
../../comboBox-ignorewheel.hpp
../../spinBox-ignorewheel.hpp
./DecklinkOutputUI.h
decklink-ui-main.h
)
Expand All @@ -25,6 +28,9 @@ set(decklink-ouput-ui_SOURCES
../../properties-view.cpp
../../vertical-scroll-area.cpp
../../double-slider.cpp
../../slider-ignorewheel.cpp
../../comboBox-ignorewheel.cpp
../../spinBox-ignorewheel.cpp
./DecklinkOutputUI.cpp
decklink-ui-main.cpp
)
Expand Down
6 changes: 6 additions & 0 deletions UI/frontend-plugins/frontend-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ set(frontend-tools_HEADERS
../../horizontal-scroll-area.hpp
../../vertical-scroll-area.hpp
../../double-slider.hpp
../../slider-ignorewheel.hpp
../../comboBox-ignorewheel.hpp
../../spinBox-ignorewheel.hpp
)
set(frontend-tools_SOURCES
${frontend-tools_SOURCES}
Expand All @@ -38,6 +41,9 @@ set(frontend-tools_SOURCES
../../horizontal-scroll-area.cpp
../../vertical-scroll-area.cpp
../../double-slider.cpp
../../slider-ignorewheel.cpp
../../comboBox-ignorewheel.cpp
../../spinBox-ignorewheel.cpp
)
set(frontend-tools_UI
${frontend-tools_UI}
Expand Down
19 changes: 11 additions & 8 deletions UI/properties-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <QStackedWidget>
#include <QDir>
#include "double-slider.hpp"
#include "slider-ignorewheel.hpp"
#include "spinBox-ignorewheel.hpp"
#include "comboBox-ignorewheel.hpp"
#include "qt-wrappers.hpp"
#include "properties-view.hpp"
#include "properties-view.moc.hpp"
Expand Down Expand Up @@ -321,7 +324,7 @@ void OBSPropertiesView::AddInt(obs_property_t *prop, QFormLayout *layout,

const char *name = obs_property_name(prop);
int val = (int)obs_data_get_int(settings, name);
QSpinBox *spin = new QSpinBox();
QSpinBox *spin = new SpinBoxIgnoreScroll();

if (!obs_property_enabled(prop))
spin->setEnabled(false);
Expand All @@ -340,7 +343,7 @@ void OBSPropertiesView::AddInt(obs_property_t *prop, QFormLayout *layout,
children.emplace_back(info);

if (type == OBS_NUMBER_SLIDER) {
QSlider *slider = new QSlider();
QSlider *slider = new SliderIgnoreScroll();
slider->setMinimum(minVal);
slider->setMaximum(maxVal);
slider->setPageStep(stepVal);
Expand Down Expand Up @@ -481,7 +484,7 @@ static string from_obs_data_autoselect(obs_data_t *data, const char *name,
QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning)
{
const char *name = obs_property_name(prop);
QComboBox *combo = new QComboBox();
QComboBox *combo = new ComboBoxIgnoreScroll();
obs_combo_type type = obs_property_list_type(prop);
obs_combo_format format = obs_property_list_format(prop);
size_t count = obs_property_list_item_count(prop);
Expand Down Expand Up @@ -913,7 +916,7 @@ static QWidget *CreateSimpleFPSValues(OBSFrameRatePropertyWidget *fpsProps,
auto items = vector<common_frame_rate>{};
items.reserve(sizeof(common_fps)/sizeof(common_frame_rate));

auto combo = fpsProps->simpleFPS = new QComboBox{};
auto combo = fpsProps->simpleFPS = new ComboBoxIgnoreScroll{};

combo->addItem("", QVariant::fromValue(make_fps(0, 0)));
for (const auto &fps : common_fps) {
Expand Down Expand Up @@ -993,7 +996,7 @@ static QWidget *CreateRationalFPS(OBSFrameRatePropertyWidget *fpsProps,
auto str = QTStr("Basic.PropertiesView.FPS.ValidFPSRanges");
auto rlabel = new QLabel{str};

auto combo = fpsProps->fpsRange = new QComboBox{};
auto combo = fpsProps->fpsRange = new ComboBoxIgnoreScroll{};
auto convert_fps = media_frames_per_second_to_fps;
//auto convert_fi = media_frames_per_second_to_frame_interval;

Expand All @@ -1014,8 +1017,8 @@ static QWidget *CreateRationalFPS(OBSFrameRatePropertyWidget *fpsProps,

layout->addRow(rlabel, combo);

auto num_edit = fpsProps->numEdit = new QSpinBox{};
auto den_edit = fpsProps->denEdit = new QSpinBox{};
auto num_edit = fpsProps->numEdit = new SpinBoxIgnoreScroll{};
auto den_edit = fpsProps->denEdit = new SpinBoxIgnoreScroll{};

num_edit->setRange(0, INT_MAX);
den_edit->setRange(0, INT_MAX);
Expand Down Expand Up @@ -1044,7 +1047,7 @@ static OBSFrameRatePropertyWidget *CreateFrameRateWidget(obs_property_t *prop,

swap(widget->fps_ranges, fps_ranges);

auto combo = widget->modeSelect = new QComboBox{};
auto combo = widget->modeSelect = new ComboBoxIgnoreScroll{};
combo->addItem(QTStr("Basic.PropertiesView.FPS.Simple"),
QVariant::fromValue(frame_rate_tag::simple()));
combo->addItem(QTStr("Basic.PropertiesView.FPS.Rational"),
Expand Down
19 changes: 19 additions & 0 deletions UI/slider-ignorewheel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "slider-ignorewheel.hpp"

SliderIgnoreScroll::SliderIgnoreScroll(QWidget *parent) : QSlider(parent)
{
setFocusPolicy(Qt::StrongFocus);
}

void SliderIgnoreScroll::wheelEvent(QWheelEvent * event)
{
if (!hasFocus())
event->ignore();
else
QSlider::wheelEvent(event);
}

void SliderIgnoreScroll::leaveEvent(QEvent * event)
{
clearFocus();
}
20 changes: 20 additions & 0 deletions UI/slider-ignorewheel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QSlider>
#include <QInputEvent>
#include <QtCore/QObject>


class SliderIgnoreScroll : public QSlider {
Q_OBJECT

public:
SliderIgnoreScroll(QWidget *parent = nullptr);

protected:

virtual void wheelEvent(QWheelEvent *event) override;
virtual void leaveEvent(QEvent *event) override;
};


19 changes: 19 additions & 0 deletions UI/spinBox-ignorewheel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "spinBox-ignorewheel.hpp"

SpinBoxIgnoreScroll::SpinBoxIgnoreScroll(QWidget *parent) : QSpinBox(parent)
{
setFocusPolicy(Qt::StrongFocus);
}

void SpinBoxIgnoreScroll::wheelEvent(QWheelEvent * event)
{
if (!hasFocus())
event->ignore();
else
QSpinBox::wheelEvent(event);
}

void SpinBoxIgnoreScroll::leaveEvent(QEvent * event)
{
clearFocus();
}
20 changes: 20 additions & 0 deletions UI/spinBox-ignorewheel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QSpinBox>
#include <QInputEvent>
#include <QtCore/QObject>


class SpinBoxIgnoreScroll : public QSpinBox {
Q_OBJECT

public:
SpinBoxIgnoreScroll(QWidget *parent = nullptr);

protected:

virtual void wheelEvent(QWheelEvent *event) override;
virtual void leaveEvent(QEvent *event) override;
};


0 comments on commit 88391b8

Please sign in to comment.