summaryrefslogtreecommitdiff
path: root/examples/multimediawidgets/player/playercontrols.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@qt.io>2016-05-19 16:38:11 +0200
committerYoann Lopes <yoann.lopes@qt.io>2016-06-03 21:12:02 +0000
commit838c12bce8d0d48ef50f485e6f611990742d7b8f (patch)
tree5260582241f92f586bcb11ad8ae84913ed5875f5 /examples/multimediawidgets/player/playercontrols.cpp
parentfe46759fc0a39418a3b5f32cf78a162c35a7aef7 (diff)
downloadqtmultimedia-838c12bce8d0d48ef50f485e6f611990742d7b8f.tar.gz
Use new volume conversion API in examples.
Volumes sliders are now scaled cubically so that loudness changes are perceived linearly. Change-Id: Ibf00d6a97d872063d92457493417be5eb42f79ac Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'examples/multimediawidgets/player/playercontrols.cpp')
-rw-r--r--examples/multimediawidgets/player/playercontrols.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/examples/multimediawidgets/player/playercontrols.cpp b/examples/multimediawidgets/player/playercontrols.cpp
index 07aa2e731..80abf59b6 100644
--- a/examples/multimediawidgets/player/playercontrols.cpp
+++ b/examples/multimediawidgets/player/playercontrols.cpp
@@ -45,6 +45,7 @@
#include <QStyle>
#include <QToolButton>
#include <QComboBox>
+#include <QAudio>
PlayerControls::PlayerControls(QWidget *parent)
: QWidget(parent)
@@ -87,7 +88,7 @@ PlayerControls::PlayerControls(QWidget *parent)
volumeSlider = new QSlider(Qt::Horizontal, this);
volumeSlider->setRange(0, 100);
- connect(volumeSlider, SIGNAL(sliderMoved(int)), this, SIGNAL(changeVolume(int)));
+ connect(volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(onVolumeSliderValueChanged()));
rateBox = new QComboBox(this);
rateBox->addItem("0.5x", QVariant(0.5));
@@ -138,13 +139,20 @@ void PlayerControls::setState(QMediaPlayer::State state)
int PlayerControls::volume() const
{
- return volumeSlider ? volumeSlider->value() : 0;
+ qreal linearVolume = QAudio::convertVolume(volumeSlider->value() / qreal(100),
+ QAudio::CubicVolumeScale,
+ QAudio::LinearVolumeScale);
+
+ return qRound(linearVolume * 100);
}
void PlayerControls::setVolume(int volume)
{
- if (volumeSlider)
- volumeSlider->setValue(volume);
+ qreal cubicVolume = QAudio::convertVolume(volume / qreal(100),
+ QAudio::LinearVolumeScale,
+ QAudio::CubicVolumeScale);
+
+ volumeSlider->setValue(qRound(cubicVolume * 100));
}
bool PlayerControls::isMuted() const
@@ -203,3 +211,8 @@ void PlayerControls::updateRate()
{
emit changeRate(playbackRate());
}
+
+void PlayerControls::onVolumeSliderValueChanged()
+{
+ emit changeVolume(volume());
+}