[767] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[767] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
| 11 | **
|
---|
| 12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
| 13 | ** modification, are permitted provided that the following conditions are
|
---|
| 14 | ** met:
|
---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
---|
| 19 | ** the documentation and/or other materials provided with the
|
---|
| 20 | ** distribution.
|
---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
---|
| 23 | ** products derived from this software without specific prior written
|
---|
| 24 | ** permission.
|
---|
| 25 | **
|
---|
| 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
| 37 | ** $QT_END_LICENSE$
|
---|
| 38 | **
|
---|
| 39 | ****************************************************************************/
|
---|
| 40 |
|
---|
| 41 | #include "settingsdialog.h"
|
---|
| 42 | #include <QComboBox>
|
---|
| 43 | #include <QDialogButtonBox>
|
---|
| 44 | #include <QLabel>
|
---|
| 45 | #include <QPushButton>
|
---|
| 46 | #include <QVBoxLayout>
|
---|
| 47 | #include <QCheckBox>
|
---|
| 48 | #include <QSlider>
|
---|
| 49 | #include <QSpinBox>
|
---|
| 50 |
|
---|
| 51 | SettingsDialog::SettingsDialog(
|
---|
| 52 | const QList<QAudioDeviceInfo> &availableInputDevices,
|
---|
| 53 | const QList<QAudioDeviceInfo> &availableOutputDevices,
|
---|
| 54 | QWidget *parent)
|
---|
| 55 | : QDialog(parent)
|
---|
| 56 | , m_windowFunction(DefaultWindowFunction)
|
---|
| 57 | , m_inputDeviceComboBox(new QComboBox(this))
|
---|
| 58 | , m_outputDeviceComboBox(new QComboBox(this))
|
---|
| 59 | , m_windowFunctionComboBox(new QComboBox(this))
|
---|
| 60 | {
|
---|
| 61 | QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
---|
| 62 |
|
---|
| 63 | // Populate combo boxes
|
---|
| 64 |
|
---|
| 65 | QAudioDeviceInfo device;
|
---|
| 66 | foreach (device, availableInputDevices)
|
---|
| 67 | m_inputDeviceComboBox->addItem(device.deviceName(),
|
---|
| 68 | qVariantFromValue(device));
|
---|
| 69 | foreach (device, availableOutputDevices)
|
---|
| 70 | m_outputDeviceComboBox->addItem(device.deviceName(),
|
---|
| 71 | qVariantFromValue(device));
|
---|
| 72 |
|
---|
| 73 | m_windowFunctionComboBox->addItem(tr("None"), qVariantFromValue(int(NoWindow)));
|
---|
| 74 | m_windowFunctionComboBox->addItem("Hann", qVariantFromValue(int(HannWindow)));
|
---|
| 75 | m_windowFunctionComboBox->setCurrentIndex(m_windowFunction);
|
---|
| 76 |
|
---|
| 77 | // Initialize default devices
|
---|
| 78 | if (!availableInputDevices.empty())
|
---|
| 79 | m_inputDevice = availableInputDevices.front();
|
---|
| 80 | if (!availableOutputDevices.empty())
|
---|
| 81 | m_outputDevice = availableOutputDevices.front();
|
---|
| 82 |
|
---|
| 83 | // Add widgets to layout
|
---|
| 84 |
|
---|
| 85 | QScopedPointer<QHBoxLayout> inputDeviceLayout(new QHBoxLayout);
|
---|
| 86 | QLabel *inputDeviceLabel = new QLabel(tr("Input device"), this);
|
---|
| 87 | inputDeviceLayout->addWidget(inputDeviceLabel);
|
---|
| 88 | inputDeviceLayout->addWidget(m_inputDeviceComboBox);
|
---|
| 89 | dialogLayout->addLayout(inputDeviceLayout.data());
|
---|
| 90 | inputDeviceLayout.take(); // ownership transferred to dialogLayout
|
---|
| 91 |
|
---|
| 92 | QScopedPointer<QHBoxLayout> outputDeviceLayout(new QHBoxLayout);
|
---|
| 93 | QLabel *outputDeviceLabel = new QLabel(tr("Output device"), this);
|
---|
| 94 | outputDeviceLayout->addWidget(outputDeviceLabel);
|
---|
| 95 | outputDeviceLayout->addWidget(m_outputDeviceComboBox);
|
---|
| 96 | dialogLayout->addLayout(outputDeviceLayout.data());
|
---|
| 97 | outputDeviceLayout.take(); // ownership transferred to dialogLayout
|
---|
| 98 |
|
---|
| 99 | QScopedPointer<QHBoxLayout> windowFunctionLayout(new QHBoxLayout);
|
---|
| 100 | QLabel *windowFunctionLabel = new QLabel(tr("Window function"), this);
|
---|
| 101 | windowFunctionLayout->addWidget(windowFunctionLabel);
|
---|
| 102 | windowFunctionLayout->addWidget(m_windowFunctionComboBox);
|
---|
| 103 | dialogLayout->addLayout(windowFunctionLayout.data());
|
---|
| 104 | windowFunctionLayout.take(); // ownership transferred to dialogLayout
|
---|
| 105 |
|
---|
| 106 | // Connect
|
---|
| 107 | CHECKED_CONNECT(m_inputDeviceComboBox, SIGNAL(activated(int)),
|
---|
| 108 | this, SLOT(inputDeviceChanged(int)));
|
---|
| 109 | CHECKED_CONNECT(m_outputDeviceComboBox, SIGNAL(activated(int)),
|
---|
| 110 | this, SLOT(outputDeviceChanged(int)));
|
---|
| 111 | CHECKED_CONNECT(m_windowFunctionComboBox, SIGNAL(activated(int)),
|
---|
| 112 | this, SLOT(windowFunctionChanged(int)));
|
---|
| 113 |
|
---|
| 114 | // Add standard buttons to layout
|
---|
| 115 | QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
---|
| 116 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
---|
| 117 | dialogLayout->addWidget(buttonBox);
|
---|
| 118 |
|
---|
| 119 | // Connect standard buttons
|
---|
| 120 | CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
|
---|
| 121 | this, SLOT(accept()));
|
---|
| 122 | CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
|
---|
| 123 | this, SLOT(reject()));
|
---|
| 124 |
|
---|
| 125 | setLayout(dialogLayout);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | SettingsDialog::~SettingsDialog()
|
---|
| 129 | {
|
---|
| 130 |
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void SettingsDialog::windowFunctionChanged(int index)
|
---|
| 134 | {
|
---|
| 135 | m_windowFunction = static_cast<WindowFunction>(
|
---|
| 136 | m_windowFunctionComboBox->itemData(index).value<int>());
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | void SettingsDialog::inputDeviceChanged(int index)
|
---|
| 140 | {
|
---|
| 141 | m_inputDevice = m_inputDeviceComboBox->itemData(index).value<QAudioDeviceInfo>();
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | void SettingsDialog::outputDeviceChanged(int index)
|
---|
| 145 | {
|
---|
| 146 | m_outputDevice = m_outputDeviceComboBox->itemData(index).value<QAudioDeviceInfo>();
|
---|
| 147 | }
|
---|
| 148 |
|
---|