31
31
32
32
#include < XdgIcon>
33
33
34
+ #include < QTimer>
34
35
#include < QSlider>
35
36
#include < QStyleOptionButton>
36
37
#include < QPushButton>
@@ -47,7 +48,8 @@ VolumePopup::VolumePopup(QWidget* parent):
47
48
QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::Popup | Qt::X11BypassWindowManagerHint),
48
49
m_pos(0 ,0 ),
49
50
m_anchor(Qt::TopLeftCorner),
50
- m_device(nullptr )
51
+ m_device(nullptr ),
52
+ mWheelTimer(new QTimer(this ))
51
53
{
52
54
// Under some Wayland compositors, setting window flags in the c-tor of the base class
53
55
// may not be enough for a correct positioning of the popup.
@@ -84,6 +86,15 @@ VolumePopup::VolumePopup(QWidget* parent):
84
86
connect (m_mixerButton, &QPushButton::released, this , &VolumePopup::launchMixer);
85
87
connect (m_volumeSlider, &QSlider::valueChanged, this , &VolumePopup::handleSliderValueChanged);
86
88
connect (m_muteToggleButton, &QPushButton::clicked, this , &VolumePopup::handleMuteToggleClicked);
89
+
90
+ mWheelTimer ->setSingleShot (true );
91
+ mWheelTimer ->setInterval (350 ); // "QStyle::SH_ToolTip_WakeUpDelay" is 700 by default
92
+ connect (mWheelTimer , &QTimer::timeout, this , [this ] {
93
+ QTimer::singleShot (0 , this , [this ] {
94
+ if (!QToolTip::isVisible ())
95
+ QToolTip::showText (QCursor::pos (), m_volumeSlider->toolTip ());
96
+ });
97
+ });
87
98
}
88
99
89
100
bool VolumePopup::event (QEvent *event)
@@ -127,7 +138,10 @@ void VolumePopup::handleSliderValueChanged(int value)
127
138
return ;
128
139
// qDebug("VolumePopup::handleSliderValueChanged: %d\n", value);
129
140
m_device->setVolume (value);
130
- QTimer::singleShot (0 , this , [this ] { QToolTip::showText (QCursor::pos (), m_volumeSlider->toolTip ()); });
141
+ QTimer::singleShot (0 , this , [this ] {
142
+ if (!mWheelTimer ->isActive ()) // a wheel event immediately hides the tooltip
143
+ QToolTip::showText (QCursor::pos (), m_volumeSlider->toolTip ());
144
+ });
131
145
}
132
146
133
147
void VolumePopup::handleMuteToggleClicked ()
@@ -197,8 +211,21 @@ void VolumePopup::openAt(QPoint pos, Qt::Corner anchor)
197
211
198
212
void VolumePopup::handleWheelEvent (QWheelEvent *event)
199
213
{
200
- m_volumeSlider->setSliderPosition (m_volumeSlider->sliderPosition ()
201
- + (event->angleDelta ().y () / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep ()));
214
+ static int _delta = 0 ; // for high-resolution mice and touchpad scrolling
215
+
216
+ int delta = event->angleDelta ().y ();
217
+ if ((_delta ^ delta) < 0 )
218
+ _delta = delta; // the wheel direction is reversed
219
+ else
220
+ _delta += delta;
221
+ if (qAbs (_delta) >= QWheelEvent::DefaultDeltasPerStep) {
222
+ m_volumeSlider->setSliderPosition (m_volumeSlider->sliderPosition ()
223
+ + (_delta / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep ()));
224
+ _delta = 0 ;
225
+ }
226
+
227
+ // show the tooltip only after the wheel rotation is stopped
228
+ mWheelTimer ->start ();
202
229
}
203
230
204
231
void VolumePopup::setDevice (AudioDevice *device)
0 commit comments