| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 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 | 
|---|
| 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 audioPositionChanged(qint64 position); | 
|---|
| 84 | void bufferLengthChanged(qint64 length); | 
|---|
| 85 |  | 
|---|
| 86 | private slots: | 
|---|
| 87 | void showFileDialog(); | 
|---|
| 88 | void showSettingsDialog(); | 
|---|
| 89 | void showToneGeneratorDialog(); | 
|---|
| 90 | void initializeRecord(); | 
|---|
| 91 | void updateModeMenu(); | 
|---|
| 92 | void updateButtonStates(); | 
|---|
| 93 |  | 
|---|
| 94 | private: | 
|---|
| 95 | void createUi(); | 
|---|
| 96 | void createMenus(); | 
|---|
| 97 | void connectUi(); | 
|---|
| 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 | #ifndef DISABLE_WAVEFORM | 
|---|
| 115 | Waveform*               m_waveform; | 
|---|
| 116 | #endif | 
|---|
| 117 | ProgressBar*            m_progressBar; | 
|---|
| 118 | Spectrograph*           m_spectrograph; | 
|---|
| 119 | LevelMeter*             m_levelMeter; | 
|---|
| 120 |  | 
|---|
| 121 | QPushButton*            m_modeButton; | 
|---|
| 122 | QPushButton*            m_recordButton; | 
|---|
| 123 | QIcon                   m_recordIcon; | 
|---|
| 124 | QPushButton*            m_pauseButton; | 
|---|
| 125 | QIcon                   m_pauseIcon; | 
|---|
| 126 | QPushButton*            m_playButton; | 
|---|
| 127 | QIcon                   m_playIcon; | 
|---|
| 128 | QPushButton*            m_settingsButton; | 
|---|
| 129 | QIcon                   m_settingsIcon; | 
|---|
| 130 |  | 
|---|
| 131 | QLabel*                 m_infoMessage; | 
|---|
| 132 | int                     m_infoMessageTimerId; | 
|---|
| 133 |  | 
|---|
| 134 | SettingsDialog*         m_settingsDialog; | 
|---|
| 135 | ToneGeneratorDialog*    m_toneGeneratorDialog; | 
|---|
| 136 |  | 
|---|
| 137 | QMenu*                  m_modeMenu; | 
|---|
| 138 | QAction*                m_loadFileAction; | 
|---|
| 139 | QAction*                m_generateToneAction; | 
|---|
| 140 | QAction*                m_recordAction; | 
|---|
| 141 |  | 
|---|
| 142 | }; | 
|---|
| 143 |  | 
|---|
| 144 | #endif // MAINWIDGET_H | 
|---|