|
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: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 met: |
|
14 ** - Redistributions of source code must retain the above copyright notice, |
|
15 ** this list of conditions and the following disclaimer. |
|
16 ** - Redistributions in binary form must reproduce the above copyright notice, |
|
17 ** this list of conditions and the following disclaimer in the documentation |
|
18 ** and/or other materials provided with the distribution. |
|
19 ** - Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the |
|
20 ** names of its contributors may be used to endorse or promote products |
|
21 ** derived from this software without specific prior written permission. |
|
22 ** |
|
23 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
24 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
25 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
26 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
27 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
28 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
29 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
30 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
31 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
32 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
33 ** POSSIBILITY OF SUCH DAMAGE. |
|
34 ** $QT_END_LICENSE$ |
|
35 ** |
|
36 *****************************************************************************/ |
|
37 |
|
38 #ifndef MAINWIDGET_H |
|
39 #define MAINWIDGET_H |
|
40 |
|
41 #include <QWidget> |
|
42 #include <QIcon> |
|
43 #include <QtMultimedia/qaudio.h> |
|
44 |
|
45 class Engine; |
|
46 class FrequencySpectrum; |
|
47 class ProgressBar; |
|
48 class Spectrograph; |
|
49 class Waveform; |
|
50 class LevelMeter; |
|
51 class SettingsDialog; |
|
52 class ToneGeneratorDialog; |
|
53 class QAudioFormat; |
|
54 class QLabel; |
|
55 class QPushButton; |
|
56 class QMenu; |
|
57 class QAction; |
|
58 |
|
59 /** |
|
60 * Main application widget, responsible for connecting the various UI |
|
61 * elements to the Engine. |
|
62 */ |
|
63 class MainWidget : public QWidget { |
|
64 Q_OBJECT |
|
65 public: |
|
66 MainWidget(QWidget *parent = 0); |
|
67 ~MainWidget(); |
|
68 |
|
69 // QObject |
|
70 void timerEvent(QTimerEvent *event); |
|
71 |
|
72 public slots: |
|
73 void stateChanged(QAudio::Mode mode, QAudio::State state); |
|
74 void formatChanged(const QAudioFormat &format); |
|
75 void spectrumChanged(qint64 position, qint64 length, |
|
76 const FrequencySpectrum &spectrum); |
|
77 void infoMessage(const QString &message, int timeoutMs); |
|
78 void errorMessage(const QString &heading, const QString &detail); |
|
79 void positionChanged(qint64 position); |
|
80 void bufferDurationChanged(qint64 duration); |
|
81 |
|
82 private slots: |
|
83 void showFileDialog(); |
|
84 void showSettingsDialog(); |
|
85 void showToneGeneratorDialog(); |
|
86 void initializeRecord(); |
|
87 void dataDurationChanged(qint64 duration); |
|
88 |
|
89 private: |
|
90 void createUi(); |
|
91 void createMenus(); |
|
92 void connectUi(); |
|
93 void updateButtonStates(); |
|
94 void reset(); |
|
95 |
|
96 enum Mode { |
|
97 NoMode, |
|
98 RecordMode, |
|
99 GenerateToneMode, |
|
100 LoadFileMode |
|
101 }; |
|
102 |
|
103 void setMode(Mode mode); |
|
104 |
|
105 private: |
|
106 Mode m_mode; |
|
107 |
|
108 Engine* m_engine; |
|
109 |
|
110 Waveform* m_waveform; |
|
111 ProgressBar* m_progressBar; |
|
112 Spectrograph* m_spectrograph; |
|
113 LevelMeter* m_levelMeter; |
|
114 |
|
115 QPushButton* m_modeButton; |
|
116 QPushButton* m_recordButton; |
|
117 QIcon m_recordIcon; |
|
118 QPushButton* m_pauseButton; |
|
119 QIcon m_pauseIcon; |
|
120 QPushButton* m_playButton; |
|
121 QIcon m_playIcon; |
|
122 QPushButton* m_settingsButton; |
|
123 QIcon m_settingsIcon; |
|
124 |
|
125 QLabel* m_infoMessage; |
|
126 int m_infoMessageTimerId; |
|
127 |
|
128 SettingsDialog* m_settingsDialog; |
|
129 ToneGeneratorDialog* m_toneGeneratorDialog; |
|
130 |
|
131 QMenu* m_modeMenu; |
|
132 QAction* m_loadFileAction; |
|
133 QAction* m_generateToneAction; |
|
134 QAction* m_recordAction; |
|
135 |
|
136 }; |
|
137 |
|
138 #endif // MAINWIDGET_H |