Merge pull request #1811 from akapar2016/UI_scrollWheelEvents

Ui scroll wheel events
This commit is contained in:
Jim
2019-04-14 13:58:54 -07:00
committed by GitHub
12 changed files with 149 additions and 10 deletions
+6
View File
@@ -232,6 +232,9 @@ set(obs_SOURCES
focus-list.cpp focus-list.cpp
menu-button.cpp menu-button.cpp
double-slider.cpp double-slider.cpp
slider-ignorewheel.cpp
comboBox-ignorewheel.cpp
spinBox-ignorewheel.cpp
volume-control.cpp volume-control.cpp
adv-audio-control.cpp adv-audio-control.cpp
item-widget-helpers.cpp item-widget-helpers.cpp
@@ -283,6 +286,9 @@ set(obs_HEADERS
display-helpers.hpp display-helpers.hpp
balance-slider.hpp balance-slider.hpp
double-slider.hpp double-slider.hpp
slider-ignorewheel.hpp
comboBox-ignorewheel.hpp
spinBox-ignorewheel.hpp
focus-list.hpp focus-list.hpp
menu-button.hpp menu-button.hpp
mute-checkbox.hpp mute-checkbox.hpp
+19
View File
@@ -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
View File
@@ -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;
};
+1 -1
View File
@@ -2,7 +2,7 @@
#include <cmath> #include <cmath>
DoubleSlider::DoubleSlider(QWidget *parent) : QSlider(parent) DoubleSlider::DoubleSlider(QWidget *parent) : SliderIgnoreScroll(parent)
{ {
connect(this, SIGNAL(valueChanged(int)), connect(this, SIGNAL(valueChanged(int)),
this, SLOT(intValChanged(int))); this, SLOT(intValChanged(int)));
+2 -1
View File
@@ -1,8 +1,9 @@
#pragma once #pragma once
#include <QSlider> #include <QSlider>
#include "slider-ignorewheel.hpp"
class DoubleSlider : public QSlider { class DoubleSlider : public SliderIgnoreScroll {
Q_OBJECT Q_OBJECT
double minVal, maxVal, minStep; double minVal, maxVal, minStep;
@@ -17,6 +17,9 @@ set(decklink-ouput-ui_HEADERS
../../properties-view.moc.hpp ../../properties-view.moc.hpp
../../vertical-scroll-area.hpp ../../vertical-scroll-area.hpp
../../double-slider.hpp ../../double-slider.hpp
../../slider-ignorewheel.hpp
../../comboBox-ignorewheel.hpp
../../spinBox-ignorewheel.hpp
./DecklinkOutputUI.h ./DecklinkOutputUI.h
decklink-ui-main.h decklink-ui-main.h
) )
@@ -25,6 +28,9 @@ set(decklink-ouput-ui_SOURCES
../../properties-view.cpp ../../properties-view.cpp
../../vertical-scroll-area.cpp ../../vertical-scroll-area.cpp
../../double-slider.cpp ../../double-slider.cpp
../../slider-ignorewheel.cpp
../../comboBox-ignorewheel.cpp
../../spinBox-ignorewheel.cpp
./DecklinkOutputUI.cpp ./DecklinkOutputUI.cpp
decklink-ui-main.cpp decklink-ui-main.cpp
) )
@@ -28,6 +28,9 @@ set(frontend-tools_HEADERS
../../horizontal-scroll-area.hpp ../../horizontal-scroll-area.hpp
../../vertical-scroll-area.hpp ../../vertical-scroll-area.hpp
../../double-slider.hpp ../../double-slider.hpp
../../slider-ignorewheel.hpp
../../comboBox-ignorewheel.hpp
../../spinBox-ignorewheel.hpp
) )
set(frontend-tools_SOURCES set(frontend-tools_SOURCES
${frontend-tools_SOURCES} ${frontend-tools_SOURCES}
@@ -38,6 +41,9 @@ set(frontend-tools_SOURCES
../../horizontal-scroll-area.cpp ../../horizontal-scroll-area.cpp
../../vertical-scroll-area.cpp ../../vertical-scroll-area.cpp
../../double-slider.cpp ../../double-slider.cpp
../../slider-ignorewheel.cpp
../../comboBox-ignorewheel.cpp
../../spinBox-ignorewheel.cpp
) )
set(frontend-tools_UI set(frontend-tools_UI
${frontend-tools_UI} ${frontend-tools_UI}
+11 -8
View File
@@ -20,6 +20,9 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QDir> #include <QDir>
#include "double-slider.hpp" #include "double-slider.hpp"
#include "slider-ignorewheel.hpp"
#include "spinBox-ignorewheel.hpp"
#include "comboBox-ignorewheel.hpp"
#include "qt-wrappers.hpp" #include "qt-wrappers.hpp"
#include "properties-view.hpp" #include "properties-view.hpp"
#include "properties-view.moc.hpp" #include "properties-view.moc.hpp"
@@ -321,7 +324,7 @@ void OBSPropertiesView::AddInt(obs_property_t *prop, QFormLayout *layout,
const char *name = obs_property_name(prop); const char *name = obs_property_name(prop);
int val = (int)obs_data_get_int(settings, name); int val = (int)obs_data_get_int(settings, name);
QSpinBox *spin = new QSpinBox(); QSpinBox *spin = new SpinBoxIgnoreScroll();
if (!obs_property_enabled(prop)) if (!obs_property_enabled(prop))
spin->setEnabled(false); spin->setEnabled(false);
@@ -340,7 +343,7 @@ void OBSPropertiesView::AddInt(obs_property_t *prop, QFormLayout *layout,
children.emplace_back(info); children.emplace_back(info);
if (type == OBS_NUMBER_SLIDER) { if (type == OBS_NUMBER_SLIDER) {
QSlider *slider = new QSlider(); QSlider *slider = new SliderIgnoreScroll();
slider->setMinimum(minVal); slider->setMinimum(minVal);
slider->setMaximum(maxVal); slider->setMaximum(maxVal);
slider->setPageStep(stepVal); slider->setPageStep(stepVal);
@@ -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) QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning)
{ {
const char *name = obs_property_name(prop); 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_type type = obs_property_list_type(prop);
obs_combo_format format = obs_property_list_format(prop); obs_combo_format format = obs_property_list_format(prop);
size_t count = obs_property_list_item_count(prop); size_t count = obs_property_list_item_count(prop);
@@ -913,7 +916,7 @@ static QWidget *CreateSimpleFPSValues(OBSFrameRatePropertyWidget *fpsProps,
auto items = vector<common_frame_rate>{}; auto items = vector<common_frame_rate>{};
items.reserve(sizeof(common_fps)/sizeof(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))); combo->addItem("", QVariant::fromValue(make_fps(0, 0)));
for (const auto &fps : common_fps) { for (const auto &fps : common_fps) {
@@ -993,7 +996,7 @@ static QWidget *CreateRationalFPS(OBSFrameRatePropertyWidget *fpsProps,
auto str = QTStr("Basic.PropertiesView.FPS.ValidFPSRanges"); auto str = QTStr("Basic.PropertiesView.FPS.ValidFPSRanges");
auto rlabel = new QLabel{str}; 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_fps = media_frames_per_second_to_fps;
//auto convert_fi = media_frames_per_second_to_frame_interval; //auto convert_fi = media_frames_per_second_to_frame_interval;
@@ -1014,8 +1017,8 @@ static QWidget *CreateRationalFPS(OBSFrameRatePropertyWidget *fpsProps,
layout->addRow(rlabel, combo); layout->addRow(rlabel, combo);
auto num_edit = fpsProps->numEdit = new QSpinBox{}; auto num_edit = fpsProps->numEdit = new SpinBoxIgnoreScroll{};
auto den_edit = fpsProps->denEdit = new QSpinBox{}; auto den_edit = fpsProps->denEdit = new SpinBoxIgnoreScroll{};
num_edit->setRange(0, INT_MAX); num_edit->setRange(0, INT_MAX);
den_edit->setRange(0, INT_MAX); den_edit->setRange(0, INT_MAX);
@@ -1044,7 +1047,7 @@ static OBSFrameRatePropertyWidget *CreateFrameRateWidget(obs_property_t *prop,
swap(widget->fps_ranges, fps_ranges); 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"), combo->addItem(QTStr("Basic.PropertiesView.FPS.Simple"),
QVariant::fromValue(frame_rate_tag::simple())); QVariant::fromValue(frame_rate_tag::simple()));
combo->addItem(QTStr("Basic.PropertiesView.FPS.Rational"), combo->addItem(QTStr("Basic.PropertiesView.FPS.Rational"),
+19
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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;
};