Skip to content

Commit

Permalink
Add waveform preference for inverting scroll wheel zoom
Browse files Browse the repository at this point in the history
As the scroll direction has been "inverted" from some time already
added a preference toggle to invert it, so that users can keep the behaviour if they prefer
  • Loading branch information
raphabigal committed Aug 11, 2021
1 parent f6f13b3 commit 64c5f92
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/preferences/dialog/dlgprefwaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ DlgPrefWaveform::DlgPrefWaveform(QWidget* pParent, MixxxMainWindow* pMixxx,
&QCheckBox::clicked,
this,
&DlgPrefWaveform::slotSetZoomSynchronization);
connect(invertScrollWheelZoom,
&QCheckBox::clicked,
this,
&DlgPrefWaveform::slotSetInvertScrollWheelZoom);
connect(allVisualGain,
QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
Expand Down Expand Up @@ -156,6 +160,7 @@ void DlgPrefWaveform::slotUpdate() {
endOfTrackWarningTimeSpinBox->setValue(factory->getEndOfTrackWarningTime());
endOfTrackWarningTimeSlider->setValue(factory->getEndOfTrackWarningTime());
synchronizeZoomCheckBox->setChecked(factory->isZoomSync());
invertScrollWheelZoom->setChecked(factory->isScrollWheelZoomInverted());
allVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::All));
lowVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::Low));
midVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::Mid));
Expand Down Expand Up @@ -213,6 +218,8 @@ void DlgPrefWaveform::slotResetToDefaults() {

synchronizeZoomCheckBox->setChecked(true);

invertScrollWheelZoom->setChecked(false);

// RGB overview.
waveformOverviewComboBox->setCurrentIndex(2);

Expand Down Expand Up @@ -265,6 +272,10 @@ void DlgPrefWaveform::slotSetZoomSynchronization(bool checked) {
WaveformWidgetFactory::instance()->setZoomSync(checked);
}

void DlgPrefWaveform::slotSetInvertScrollWheelZoom(bool checked) {
WaveformWidgetFactory::instance()->setInvertScrollWheelZoom(checked);
}

void DlgPrefWaveform::slotSetVisualGainAll(double gain) {
WaveformWidgetFactory::instance()->setVisualGain(WaveformWidgetFactory::All,gain);
}
Expand Down
1 change: 1 addition & 0 deletions src/preferences/dialog/dlgprefwaveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DlgPrefWaveform : public DlgPreferencePage, public Ui::DlgPrefWaveformDlg
void slotSetWaveformOverviewType(int index);
void slotSetDefaultZoom(int index);
void slotSetZoomSynchronization(bool checked);
void slotSetInvertScrollWheelZoom(bool checked);
void slotSetVisualGainAll(double gain);
void slotSetVisualGainLow(double gain);
void slotSetVisualGainMid(double gain);
Expand Down
10 changes: 10 additions & 0 deletions src/preferences/dialog/dlgprefwaveformdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ Select from different types of displays for the waveform, which differ primarily
</property>
</widget>
</item>
<item row="8" column="1" colspan="3">
<widget class="QCheckBox" name="invertScrollWheelZoom">
<property name="toolTip">
<string>Inverts the zoom direction when using the scroll wheel. When checked, it will act in reverse of your operational system default behaviour.</string>
</property>
<property name="text">
<string>Invert zoom direction when using the scroll wheel</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="cachedWaveforms">
<property name="text">
Expand Down
11 changes: 11 additions & 0 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ WaveformWidgetFactory::WaveformWidgetFactory()
m_endOfTrackWarningTime(30),
m_defaultZoom(WaveformWidgetRenderer::s_waveformDefaultZoom),
m_zoomSync(true),
m_invertScrollWheelZoom(false),
m_overviewNormalized(false),
m_openGlAvailable(false),
m_openGlesAvailable(false),
Expand Down Expand Up @@ -307,6 +308,9 @@ bool WaveformWidgetFactory::setConfig(UserSettingsPointer config) {
bool zoomSync = m_config->getValue(ConfigKey("[Waveform]", "ZoomSynchronization"), m_zoomSync);
setZoomSync(zoomSync);

bool invertScrollWheelZoom = m_config->getValue(ConfigKey("[Waveform]", "InvertScrollWheelZoom"), m_invertScrollWheelZoom);
setInvertScrollWheelZoom(invertScrollWheelZoom);

int beatGridAlpha = m_config->getValue(ConfigKey("[Waveform]", "beatGridAlpha"), m_beatGridAlpha);
setDisplayBeatGridAlpha(beatGridAlpha);

Expand Down Expand Up @@ -569,6 +573,13 @@ void WaveformWidgetFactory::setZoomSync(bool sync) {
}
}

void WaveformWidgetFactory::setInvertScrollWheelZoom(bool invert) {
m_invertScrollWheelZoom = invert;
if (m_config) {
m_config->set(ConfigKey("[Waveform]", "InvertScrollWheelZoom"), ConfigValue(m_invertScrollWheelZoom));
}
}

void WaveformWidgetFactory::setDisplayBeatGridAlpha(int alpha) {
m_beatGridAlpha = alpha;
if (m_waveformWidgetHolders.size() == 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/waveform/waveformwidgetfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
void setZoomSync(bool sync);
int isZoomSync() const { return m_zoomSync;}

void setInvertScrollWheelZoom(bool invert);
bool isScrollWheelZoomInverted() const { return m_invertScrollWheelZoom; }

void setDisplayBeatGridAlpha(int alpha);
int getBeatGridAlpha() const { return m_beatGridAlpha; }

Expand Down Expand Up @@ -178,6 +181,7 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
int m_endOfTrackWarningTime;
double m_defaultZoom;
bool m_zoomSync;
bool m_invertScrollWheelZoom;
double m_visualGain[FilterCount];
bool m_overviewNormalized;

Expand Down
7 changes: 6 additions & 1 deletion src/widget/wwaveformviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ void WWaveformViewer::mouseReleaseEvent(QMouseEvent* /*event*/) {

void WWaveformViewer::wheelEvent(QWheelEvent* event) {
if (m_waveformWidget) {
if (event->angleDelta().y() > 0) {
int y = event->angleDelta().y();
if (WaveformWidgetFactory::instance()->isScrollWheelZoomInverted()) {
y *= -1;
}

if (y > 0) {
onZoomChange(m_waveformWidget->getZoomFactor() / 1.05);
} else {
onZoomChange(m_waveformWidget->getZoomFactor() * 1.05);
Expand Down

0 comments on commit 64c5f92

Please sign in to comment.