|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "settingsdialog.h" |
|
43 #include <QComboBox> |
|
44 #include <QDialogButtonBox> |
|
45 #include <QLabel> |
|
46 #include <QPushButton> |
|
47 #include <QVBoxLayout> |
|
48 #include <QCheckBox> |
|
49 #include <QSlider> |
|
50 #include <QSpinBox> |
|
51 |
|
52 SettingsDialog::SettingsDialog( |
|
53 const QList<QAudioDeviceInfo> &availableInputDevices, |
|
54 const QList<QAudioDeviceInfo> &availableOutputDevices, |
|
55 QWidget *parent) |
|
56 : QDialog(parent) |
|
57 , m_windowFunction(DefaultWindowFunction) |
|
58 , m_inputDeviceComboBox(new QComboBox(this)) |
|
59 , m_outputDeviceComboBox(new QComboBox(this)) |
|
60 , m_windowFunctionComboBox(new QComboBox(this)) |
|
61 { |
|
62 QVBoxLayout *dialogLayout = new QVBoxLayout(this); |
|
63 |
|
64 // Populate combo boxes |
|
65 |
|
66 QAudioDeviceInfo device; |
|
67 foreach (device, availableInputDevices) |
|
68 m_inputDeviceComboBox->addItem(device.deviceName(), |
|
69 qVariantFromValue(device)); |
|
70 foreach (device, availableOutputDevices) |
|
71 m_outputDeviceComboBox->addItem(device.deviceName(), |
|
72 qVariantFromValue(device)); |
|
73 |
|
74 m_windowFunctionComboBox->addItem(tr("None"), qVariantFromValue(int(NoWindow))); |
|
75 m_windowFunctionComboBox->addItem("Hann", qVariantFromValue(int(HannWindow))); |
|
76 m_windowFunctionComboBox->setCurrentIndex(m_windowFunction); |
|
77 |
|
78 // Initialize default devices |
|
79 if (!availableInputDevices.empty()) |
|
80 m_inputDevice = availableInputDevices.front(); |
|
81 if (!availableOutputDevices.empty()) |
|
82 m_outputDevice = availableOutputDevices.front(); |
|
83 |
|
84 // Add widgets to layout |
|
85 |
|
86 QScopedPointer<QHBoxLayout> inputDeviceLayout(new QHBoxLayout); |
|
87 QLabel *inputDeviceLabel = new QLabel(tr("Input device"), this); |
|
88 inputDeviceLayout->addWidget(inputDeviceLabel); |
|
89 inputDeviceLayout->addWidget(m_inputDeviceComboBox); |
|
90 dialogLayout->addLayout(inputDeviceLayout.data()); |
|
91 inputDeviceLayout.take(); // ownership transferred to dialogLayout |
|
92 |
|
93 QScopedPointer<QHBoxLayout> outputDeviceLayout(new QHBoxLayout); |
|
94 QLabel *outputDeviceLabel = new QLabel(tr("Output device"), this); |
|
95 outputDeviceLayout->addWidget(outputDeviceLabel); |
|
96 outputDeviceLayout->addWidget(m_outputDeviceComboBox); |
|
97 dialogLayout->addLayout(outputDeviceLayout.data()); |
|
98 outputDeviceLayout.take(); // ownership transferred to dialogLayout |
|
99 |
|
100 QScopedPointer<QHBoxLayout> windowFunctionLayout(new QHBoxLayout); |
|
101 QLabel *windowFunctionLabel = new QLabel(tr("Window function"), this); |
|
102 windowFunctionLayout->addWidget(windowFunctionLabel); |
|
103 windowFunctionLayout->addWidget(m_windowFunctionComboBox); |
|
104 dialogLayout->addLayout(windowFunctionLayout.data()); |
|
105 windowFunctionLayout.take(); // ownership transferred to dialogLayout |
|
106 |
|
107 // Connect |
|
108 CHECKED_CONNECT(m_inputDeviceComboBox, SIGNAL(activated(int)), |
|
109 this, SLOT(inputDeviceChanged(int))); |
|
110 CHECKED_CONNECT(m_outputDeviceComboBox, SIGNAL(activated(int)), |
|
111 this, SLOT(outputDeviceChanged(int))); |
|
112 CHECKED_CONNECT(m_windowFunctionComboBox, SIGNAL(activated(int)), |
|
113 this, SLOT(windowFunctionChanged(int))); |
|
114 |
|
115 // Add standard buttons to layout |
|
116 QDialogButtonBox *buttonBox = new QDialogButtonBox(this); |
|
117 buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
118 dialogLayout->addWidget(buttonBox); |
|
119 |
|
120 // Connect standard buttons |
|
121 CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), |
|
122 this, SLOT(accept())); |
|
123 CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), |
|
124 this, SLOT(reject())); |
|
125 |
|
126 setLayout(dialogLayout); |
|
127 } |
|
128 |
|
129 SettingsDialog::~SettingsDialog() |
|
130 { |
|
131 |
|
132 } |
|
133 |
|
134 void SettingsDialog::windowFunctionChanged(int index) |
|
135 { |
|
136 m_windowFunction = static_cast<WindowFunction>( |
|
137 m_windowFunctionComboBox->itemData(index).value<int>()); |
|
138 } |
|
139 |
|
140 void SettingsDialog::inputDeviceChanged(int index) |
|
141 { |
|
142 m_inputDevice = m_inputDeviceComboBox->itemData(index).value<QAudioDeviceInfo>(); |
|
143 } |
|
144 |
|
145 void SettingsDialog::outputDeviceChanged(int index) |
|
146 { |
|
147 m_outputDevice = m_outputDeviceComboBox->itemData(index).value<QAudioDeviceInfo>(); |
|
148 } |
|
149 |