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