1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
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 "tonegeneratordialog.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 | const int ToneGeneratorFreqMin = 1;
|
---|
52 | const int ToneGeneratorFreqMax = 1000;
|
---|
53 | const int ToneGeneratorFreqDefault = 440;
|
---|
54 | const int ToneGeneratorAmplitudeDefault = 75;
|
---|
55 |
|
---|
56 | ToneGeneratorDialog::ToneGeneratorDialog(QWidget *parent)
|
---|
57 | : QDialog(parent)
|
---|
58 | , m_toneGeneratorSweepCheckBox(new QCheckBox(tr("Frequency sweep"), this))
|
---|
59 | , m_frequencySweepEnabled(true)
|
---|
60 | , m_toneGeneratorControl(new QWidget(this))
|
---|
61 | , m_toneGeneratorFrequencyControl(new QWidget(this))
|
---|
62 | , m_frequencySlider(new QSlider(Qt::Horizontal, this))
|
---|
63 | , m_frequencySpinBox(new QSpinBox(this))
|
---|
64 | , m_frequency(ToneGeneratorFreqDefault)
|
---|
65 | , m_amplitudeSlider(new QSlider(Qt::Horizontal, this))
|
---|
66 | {
|
---|
67 | QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
---|
68 |
|
---|
69 | m_toneGeneratorSweepCheckBox->setChecked(true);
|
---|
70 |
|
---|
71 | // Configure tone generator controls
|
---|
72 | m_frequencySlider->setRange(ToneGeneratorFreqMin, ToneGeneratorFreqMax);
|
---|
73 | m_frequencySlider->setValue(ToneGeneratorFreqDefault);
|
---|
74 | m_frequencySpinBox->setRange(ToneGeneratorFreqMin, ToneGeneratorFreqMax);
|
---|
75 | m_frequencySpinBox->setValue(ToneGeneratorFreqDefault);
|
---|
76 | m_amplitudeSlider->setRange(0, 100);
|
---|
77 | m_amplitudeSlider->setValue(ToneGeneratorAmplitudeDefault);
|
---|
78 |
|
---|
79 | // Add widgets to layout
|
---|
80 |
|
---|
81 | QScopedPointer<QGridLayout> frequencyControlLayout(new QGridLayout);
|
---|
82 | QLabel *frequencyLabel = new QLabel(tr("Frequency (Hz)"), this);
|
---|
83 | frequencyControlLayout->addWidget(frequencyLabel, 0, 0, 2, 1);
|
---|
84 | frequencyControlLayout->addWidget(m_frequencySlider, 0, 1);
|
---|
85 | frequencyControlLayout->addWidget(m_frequencySpinBox, 1, 1);
|
---|
86 | m_toneGeneratorFrequencyControl->setLayout(frequencyControlLayout.data());
|
---|
87 | frequencyControlLayout.take(); // ownership transferred to m_toneGeneratorFrequencyControl
|
---|
88 | m_toneGeneratorFrequencyControl->setEnabled(false);
|
---|
89 |
|
---|
90 | QScopedPointer<QGridLayout> toneGeneratorLayout(new QGridLayout);
|
---|
91 | QLabel *amplitudeLabel = new QLabel(tr("Amplitude"), this);
|
---|
92 | toneGeneratorLayout->addWidget(m_toneGeneratorSweepCheckBox, 0, 1);
|
---|
93 | toneGeneratorLayout->addWidget(m_toneGeneratorFrequencyControl, 1, 0, 1, 2);
|
---|
94 | toneGeneratorLayout->addWidget(amplitudeLabel, 2, 0);
|
---|
95 | toneGeneratorLayout->addWidget(m_amplitudeSlider, 2, 1);
|
---|
96 | m_toneGeneratorControl->setLayout(toneGeneratorLayout.data());
|
---|
97 | m_toneGeneratorControl->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
---|
98 | dialogLayout->addWidget(m_toneGeneratorControl);
|
---|
99 | toneGeneratorLayout.take(); // ownership transferred
|
---|
100 |
|
---|
101 | // Connect
|
---|
102 | CHECKED_CONNECT(m_toneGeneratorSweepCheckBox, SIGNAL(toggled(bool)),
|
---|
103 | this, SLOT(frequencySweepEnabled(bool)));
|
---|
104 | CHECKED_CONNECT(m_frequencySlider, SIGNAL(valueChanged(int)),
|
---|
105 | m_frequencySpinBox, SLOT(setValue(int)));
|
---|
106 | CHECKED_CONNECT(m_frequencySpinBox, SIGNAL(valueChanged(int)),
|
---|
107 | m_frequencySlider, SLOT(setValue(int)));
|
---|
108 |
|
---|
109 | // Add standard buttons to layout
|
---|
110 | QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
---|
111 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
---|
112 | dialogLayout->addWidget(buttonBox);
|
---|
113 |
|
---|
114 | // Connect standard buttons
|
---|
115 | CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
|
---|
116 | this, SLOT(accept()));
|
---|
117 | CHECKED_CONNECT(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
|
---|
118 | this, SLOT(reject()));
|
---|
119 |
|
---|
120 | setLayout(dialogLayout);
|
---|
121 | }
|
---|
122 |
|
---|
123 | ToneGeneratorDialog::~ToneGeneratorDialog()
|
---|
124 | {
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | bool ToneGeneratorDialog::isFrequencySweepEnabled() const
|
---|
129 | {
|
---|
130 | return m_toneGeneratorSweepCheckBox->isChecked();
|
---|
131 | }
|
---|
132 |
|
---|
133 | qreal ToneGeneratorDialog::frequency() const
|
---|
134 | {
|
---|
135 | return qreal(m_frequencySlider->value());
|
---|
136 | }
|
---|
137 |
|
---|
138 | qreal ToneGeneratorDialog::amplitude() const
|
---|
139 | {
|
---|
140 | return qreal(m_amplitudeSlider->value()) / 100.0;
|
---|
141 | }
|
---|
142 |
|
---|
143 | void ToneGeneratorDialog::frequencySweepEnabled(bool enabled)
|
---|
144 | {
|
---|
145 | m_frequencySweepEnabled = enabled;
|
---|
146 | m_toneGeneratorFrequencyControl->setEnabled(!enabled);
|
---|
147 | }
|
---|