Skip to content

Commit 195978b

Browse files
committed
Allow to change the volume using a mouse hires wheel
The Volume control plugin allows to change the volume using the mouse wheel. However for hires wheel this doesn't work. The volume change is controlled by the following formula: m_volumeSlider->setSliderPosition(m_volumeSlider->sliderPosition() + (event->angleDelta().y() / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep())); For some kind of mouse where the wheel event is compose by a lot of small 'delta'; the ratio event->angleDelta().y() / QWheelEvent::DefaultDeltasPerStep is less than 1; and because this ratio is between two integers it is rounded to 0. So store the fraction part of the wheel stroke in a static variable.
1 parent 45f26c2 commit 195978b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plugin-volume/volumepopup.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,21 @@ void VolumePopup::openAt(QPoint pos, Qt::Corner anchor)
197197

198198
void VolumePopup::handleWheelEvent(QWheelEvent *event)
199199
{
200-
m_volumeSlider->setSliderPosition(m_volumeSlider->sliderPosition()
201-
+ (event->angleDelta().y() / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep()));
200+
// With a hig res mouse wheel, event->angleDelta().y() may be
201+
// less than QWheelEvent::DefaultDeltasPerStep, so we need to
202+
// accomulate the fraction between each handleWheelEvent call.
203+
// We can declare it static, because even if it would another
204+
// instance of VolumePopup, this would impact onlythe start
205+
// of the strokes.
206+
static int fractionalAngleDelta = 0;
207+
208+
fractionalAngleDelta += event->angleDelta().y();
209+
if (fractionalAngleDelta / QWheelEvent::DefaultDeltasPerStep != 0) {
210+
m_volumeSlider->setSliderPosition(m_volumeSlider->sliderPosition()
211+
+ (fractionalAngleDelta / QWheelEvent::DefaultDeltasPerStep *
212+
m_volumeSlider->singleStep()));
213+
fractionalAngleDelta %= QWheelEvent::DefaultDeltasPerStep;
214+
}
202215
}
203216

204217
void VolumePopup::setDevice(AudioDevice *device)

0 commit comments

Comments
 (0)