1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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 | #ifndef MAINWIDGET_H
|
---|
42 | #define MAINWIDGET_H
|
---|
43 |
|
---|
44 | #include <QWidget>
|
---|
45 | #include <QIcon>
|
---|
46 | #include <QtMultimedia/qaudio.h>
|
---|
47 |
|
---|
48 | class Engine;
|
---|
49 | class FrequencySpectrum;
|
---|
50 | class ProgressBar;
|
---|
51 | class Spectrograph;
|
---|
52 | class Waveform;
|
---|
53 | class LevelMeter;
|
---|
54 | class SettingsDialog;
|
---|
55 | class ToneGeneratorDialog;
|
---|
56 |
|
---|
57 | QT_FORWARD_DECLARE_CLASS(QAudioFormat)
|
---|
58 | QT_FORWARD_DECLARE_CLASS(QLabel)
|
---|
59 | QT_FORWARD_DECLARE_CLASS(QPushButton)
|
---|
60 | QT_FORWARD_DECLARE_CLASS(QMenu)
|
---|
61 | QT_FORWARD_DECLARE_CLASS(QAction)
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Main application widget, responsible for connecting the various UI
|
---|
65 | * elements to the Engine.
|
---|
66 | */
|
---|
67 | class MainWidget : public QWidget {
|
---|
68 | Q_OBJECT
|
---|
69 | public:
|
---|
70 | MainWidget(QWidget *parent = 0);
|
---|
71 | ~MainWidget();
|
---|
72 |
|
---|
73 | // QObject
|
---|
74 | void timerEvent(QTimerEvent *event);
|
---|
75 |
|
---|
76 | public slots:
|
---|
77 | void stateChanged(QAudio::Mode mode, QAudio::State state);
|
---|
78 | void formatChanged(const QAudioFormat &format);
|
---|
79 | void spectrumChanged(qint64 position, qint64 length,
|
---|
80 | const FrequencySpectrum &spectrum);
|
---|
81 | void infoMessage(const QString &message, int timeoutMs);
|
---|
82 | void errorMessage(const QString &heading, const QString &detail);
|
---|
83 | void positionChanged(qint64 position);
|
---|
84 | void bufferDurationChanged(qint64 duration);
|
---|
85 |
|
---|
86 | private slots:
|
---|
87 | void showFileDialog();
|
---|
88 | void showSettingsDialog();
|
---|
89 | void showToneGeneratorDialog();
|
---|
90 | void initializeRecord();
|
---|
91 | void dataDurationChanged(qint64 duration);
|
---|
92 |
|
---|
93 | private:
|
---|
94 | void createUi();
|
---|
95 | void createMenus();
|
---|
96 | void connectUi();
|
---|
97 | void updateButtonStates();
|
---|
98 | void reset();
|
---|
99 |
|
---|
100 | enum Mode {
|
---|
101 | NoMode,
|
---|
102 | RecordMode,
|
---|
103 | GenerateToneMode,
|
---|
104 | LoadFileMode
|
---|
105 | };
|
---|
106 |
|
---|
107 | void setMode(Mode mode);
|
---|
108 |
|
---|
109 | private:
|
---|
110 | Mode m_mode;
|
---|
111 |
|
---|
112 | Engine* m_engine;
|
---|
113 |
|
---|
114 | Waveform* m_waveform;
|
---|
115 | ProgressBar* m_progressBar;
|
---|
116 | Spectrograph* m_spectrograph;
|
---|
117 | LevelMeter* m_levelMeter;
|
---|
118 |
|
---|
119 | QPushButton* m_modeButton;
|
---|
120 | QPushButton* m_recordButton;
|
---|
121 | QIcon m_recordIcon;
|
---|
122 | QPushButton* m_pauseButton;
|
---|
123 | QIcon m_pauseIcon;
|
---|
124 | QPushButton* m_playButton;
|
---|
125 | QIcon m_playIcon;
|
---|
126 | QPushButton* m_settingsButton;
|
---|
127 | QIcon m_settingsIcon;
|
---|
128 |
|
---|
129 | QLabel* m_infoMessage;
|
---|
130 | int m_infoMessageTimerId;
|
---|
131 |
|
---|
132 | SettingsDialog* m_settingsDialog;
|
---|
133 | ToneGeneratorDialog* m_toneGeneratorDialog;
|
---|
134 |
|
---|
135 | QMenu* m_modeMenu;
|
---|
136 | QAction* m_loadFileAction;
|
---|
137 | QAction* m_generateToneAction;
|
---|
138 | QAction* m_recordAction;
|
---|
139 |
|
---|
140 | };
|
---|
141 |
|
---|
142 | #endif // MAINWIDGET_H
|
---|