summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorhawcroft <derick.hawcroft@nokia.com>2011-09-28 13:04:18 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-28 05:34:16 +0200
commitee0ea8c4424dc89e3bb44895a5510729f15eb0c3 (patch)
tree66c0fb88665ddfebdd0227208011745effc3b557 /examples
parenta645b75e35b2d545d4bd5c9f592f4efc9c303a11 (diff)
Update audiooutput example with volume slider
Update example for new volume API Change-Id: I1b9ccbccc62930549e667f0063b3d76feb23a2ea Reviewed-on: http://codereview.qt-project.org/5662 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: derick hawcroft <derick.hawcroft@nokia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/audiooutput/audiooutput.cpp20
-rw-r--r--examples/audiooutput/audiooutput.h6
2 files changed, 26 insertions, 0 deletions
diff --git a/examples/audiooutput/audiooutput.cpp b/examples/audiooutput/audiooutput.cpp
index 68fbbcc3d..b8193fbb4 100644
--- a/examples/audiooutput/audiooutput.cpp
+++ b/examples/audiooutput/audiooutput.cpp
@@ -51,6 +51,7 @@ const QString AudioTest::PushModeLabel(tr("Enable push mode"));
const QString AudioTest::PullModeLabel(tr("Enable pull mode"));
const QString AudioTest::SuspendLabel(tr("Suspend playback"));
const QString AudioTest::ResumeLabel(tr("Resume playback"));
+const QString AudioTest::VolumeLabel(tr("Volume:"));
const int DurationSeconds = 1;
const int ToneFrequencyHz = 600;
@@ -190,6 +191,18 @@ void AudioTest::initializeWindow()
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
layout->addWidget(m_suspendResumeButton);
+ QHBoxLayout *volumeBox = new QHBoxLayout;
+ m_volumeLabel = new QLabel;
+ m_volumeLabel->setText(VolumeLabel);
+ m_volumeSlider = new QSlider(Qt::Horizontal);
+ m_volumeSlider->setMinimum(0);
+ m_volumeSlider->setMaximum(100);
+ m_volumeSlider->setSingleStep(10);
+ connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int)));
+ volumeBox->addWidget(m_volumeLabel);
+ volumeBox->addWidget(m_volumeSlider);
+ layout->addLayout(volumeBox);
+
window->setLayout(layout.data());
layout.take(); // ownership transferred
@@ -231,6 +244,7 @@ void AudioTest::createAudioOutput()
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
m_generator->start();
m_audioOutput->start(m_generator);
+ m_volumeSlider->setValue(int(m_audioOutput->volume()*100.0f));
}
AudioTest::~AudioTest()
@@ -248,6 +262,12 @@ void AudioTest::deviceChanged(int index)
createAudioOutput();
}
+void AudioTest::volumeChanged(int value)
+{
+ if (m_audioOutput)
+ m_audioOutput->setVolume(qreal(value/100.0f));
+}
+
void AudioTest::notified()
{
qWarning() << "bytesFree = " << m_audioOutput->bytesFree()
diff --git a/examples/audiooutput/audiooutput.h b/examples/audiooutput/audiooutput.h
index 519fa0c46..3a07039a2 100644
--- a/examples/audiooutput/audiooutput.h
+++ b/examples/audiooutput/audiooutput.h
@@ -45,6 +45,8 @@
#include <QObject>
#include <QMainWindow>
+#include <QLabel>
+#include <QSlider>
#include <QIODevice>
#include <QTimer>
#include <QPushButton>
@@ -94,6 +96,8 @@ private:
QPushButton* m_modeButton;
QPushButton* m_suspendResumeButton;
QComboBox* m_deviceBox;
+ QLabel* m_volumeLabel;
+ QSlider* m_volumeSlider;
QAudioDeviceInfo m_device;
Generator* m_generator;
@@ -108,6 +112,7 @@ private:
static const QString PullModeLabel;
static const QString SuspendLabel;
static const QString ResumeLabel;
+ static const QString VolumeLabel;
private slots:
void notified();
@@ -116,6 +121,7 @@ private slots:
void toggleSuspendResume();
void stateChanged(QAudio::State state);
void deviceChanged(int index);
+ void volumeChanged(int);
};
#endif