diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/qmediaplayer/main.cpp | 52 | ||||
-rw-r--r-- | demos/qmediaplayer/mediaplayer.cpp | 24 | ||||
-rw-r--r-- | demos/qmediaplayer/mediaplayer.h | 7 | ||||
-rw-r--r-- | demos/qtdemo/itemcircleanimation.h | 2 | ||||
-rw-r--r-- | demos/qtdemo/mainwindow.cpp | 2 | ||||
-rw-r--r-- | demos/qtdemo/mainwindow.h | 2 | ||||
-rw-r--r-- | demos/qtdemo/qmlShell.qml | 2 | ||||
-rw-r--r-- | demos/qtdemo/textbutton.h | 2 | ||||
-rw-r--r-- | demos/spectrum/app/engine.h | 2 | ||||
-rw-r--r-- | demos/spectrum/app/levelmeter.h | 2 | ||||
-rw-r--r-- | demos/spectrum/app/main.cpp | 2 | ||||
-rw-r--r-- | demos/spectrum/app/spectrograph.h | 2 | ||||
-rw-r--r-- | demos/spectrum/app/spectrumanalyser.cpp | 2 | ||||
-rw-r--r-- | demos/spectrum/app/wavfile.cpp | 168 | ||||
-rw-r--r-- | demos/spectrum/app/wavfile.h | 1 | ||||
-rw-r--r-- | demos/spreadsheet/spreadsheet.cpp | 2 | ||||
-rw-r--r-- | demos/symbianpkgrules.pri | 4 |
17 files changed, 151 insertions, 127 deletions
diff --git a/demos/qmediaplayer/main.cpp b/demos/qmediaplayer/main.cpp index 02c579b..9f15e43 100644 --- a/demos/qmediaplayer/main.cpp +++ b/demos/qmediaplayer/main.cpp @@ -42,6 +42,8 @@ #include <QtGui> #include "mediaplayer.h" +const qreal DefaultVolume = -1.0; + int main (int argc, char *argv[]) { Q_INIT_RESOURCE(mediaplayer); @@ -50,36 +52,38 @@ int main (int argc, char *argv[]) app.setOrganizationName("Qt"); app.setQuitOnLastWindowClosed(true); - bool hasSmallScreen = + QString fileName; + qreal volume = DefaultVolume; + bool smallScreen = false; #ifdef Q_OS_SYMBIAN - /* On Symbian, we always want fullscreen. One reason is that it's not - * possible to launch any demos from the fluidlauncher due to a - * limitation in the emulator. */ - true -#else - false + smallScreen = true; #endif - ; - - QString fileString; - const QStringList args(app.arguments()); - /* We have a minor problem here, we accept two arguments, both are - * optional: - * - A file name - * - the option "-small-screen", so let's try to cope with that. - */ - for (int i = 0; i < args.count(); ++i) { - const QString &at = args.at(i); - if (at == QLatin1String("-small-screen")) - hasSmallScreen = true; - else if (i > 0) // We don't want the app name. - fileString = at; + QStringList args(app.arguments()); + args.removeFirst(); // remove name of executable + while (!args.empty()) { + const QString &arg = args.first(); + if (QLatin1String("-small-screen") == arg || QLatin1String("--small-screen") == arg) { + smallScreen = true; + } else if (QLatin1String("-volume") == arg || QLatin1String("--volume") == arg) { + if (!args.empty()) { + args.removeFirst(); + volume = qMax(qMin(args.first().toFloat(), float(1.0)), float(0.0)); + } + } else if (fileName.isNull()) { + fileName = arg; + } + args.removeFirst(); } - MediaPlayer player(fileString, hasSmallScreen); + MediaPlayer player; + player.setSmallScreen(smallScreen); + if (DefaultVolume != volume) + player.setVolume(volume); + if (!fileName.isNull()) + player.setFile(fileName); - if (hasSmallScreen) + if (smallScreen) player.showMaximized(); else player.show(); diff --git a/demos/qmediaplayer/mediaplayer.cpp b/demos/qmediaplayer/mediaplayer.cpp index 97a8e35..5bf7d6d 100644 --- a/demos/qmediaplayer/mediaplayer.cpp +++ b/demos/qmediaplayer/mediaplayer.cpp @@ -152,12 +152,10 @@ void MediaVideoWidget::dragEnterEvent(QDragEnterEvent *e) { } -MediaPlayer::MediaPlayer(const QString &filePath, - const bool hasSmallScreen) : +MediaPlayer::MediaPlayer() : playButton(0), nextEffect(0), settingsDialog(0), ui(0), m_AudioOutput(Phonon::VideoCategory), - m_videoWidget(new MediaVideoWidget(this)), - m_hasSmallScreen(hasSmallScreen) + m_videoWidget(new MediaVideoWidget(this)) { setWindowTitle(tr("Media Player")); setContextMenuPolicy(Qt::CustomContextMenu); @@ -346,8 +344,6 @@ MediaPlayer::MediaPlayer(const QString &filePath, m_audioOutputPath = Phonon::createPath(&m_MediaObject, &m_AudioOutput); Phonon::createPath(&m_MediaObject, m_videoWidget); - if (!filePath.isEmpty()) - setFile(filePath); resize(minimumSizeHint()); } @@ -358,7 +354,7 @@ void MediaPlayer::stateChanged(Phonon::State newstate, Phonon::State oldstate) if (oldstate == Phonon::LoadingState) { QRect videoHintRect = QRect(QPoint(0, 0), m_videoWindow.sizeHint()); QRect newVideoRect = QApplication::desktop()->screenGeometry().intersected(videoHintRect); - if (!m_hasSmallScreen) { + if (!m_smallScreen) { if (m_MediaObject.hasVideo()) { // Flush event que so that sizeHint takes the // recently shown/hidden m_videoWindow into account: @@ -466,6 +462,16 @@ void MediaPlayer::initSettingsDialog() } +void MediaPlayer::setVolume(qreal volume) +{ + m_AudioOutput.setVolume(volume); +} + +void MediaPlayer::setSmallScreen(bool smallScreen) +{ + m_smallScreen = smallScreen; +} + void MediaPlayer::effectChanged() { int currentIndex = ui->audioEffectsCombo->currentIndex(); @@ -589,7 +595,7 @@ void MediaPlayer::configureEffect() effectDialog.exec(); if (effectDialog.result() != QDialog::Accepted) { - //we need to restore the paramaters values + //we need to restore the parameters values int currentIndex = 0; foreach(Phonon::EffectParameter param, nextEffect->parameters()) { nextEffect->setParameterValue(param, savedParamValues.at(currentIndex++)); @@ -685,7 +691,7 @@ bool MediaPlayer::playPauseForDialog() // If we're running on a small screen, we want to pause the video when // popping up dialogs. We neither want to tamper with the state if the // user has paused. - if (m_hasSmallScreen && m_MediaObject.hasVideo()) { + if (m_smallScreen && m_MediaObject.hasVideo()) { if (Phonon::PlayingState == m_MediaObject.state()) { m_MediaObject.pause(); return true; diff --git a/demos/qmediaplayer/mediaplayer.h b/demos/qmediaplayer/mediaplayer.h index d6ae58b..73450fe 100644 --- a/demos/qmediaplayer/mediaplayer.h +++ b/demos/qmediaplayer/mediaplayer.h @@ -104,8 +104,7 @@ class MediaPlayer : { Q_OBJECT public: - MediaPlayer(const QString &, - const bool hasSmallScreen); + MediaPlayer(); void dragEnterEvent(QDragEnterEvent *e); void dragMoveEvent(QDragMoveEvent *e); @@ -115,6 +114,8 @@ public: void setLocation(const QString &location); void initVideoWindow(); void initSettingsDialog(); + void setVolume(qreal volume); + void setSmallScreen(bool smallScreen); public slots: void openFile(); @@ -171,7 +172,7 @@ private: Phonon::AudioOutput m_AudioOutput; MediaVideoWidget *m_videoWidget; Phonon::Path m_audioOutputPath; - const bool m_hasSmallScreen; + bool m_smallScreen; }; #endif //MEDIAPLAYER_H diff --git a/demos/qtdemo/itemcircleanimation.h b/demos/qtdemo/itemcircleanimation.h index 425d2f5..7276f7f 100644 --- a/demos/qtdemo/itemcircleanimation.h +++ b/demos/qtdemo/itemcircleanimation.h @@ -61,7 +61,7 @@ public: ItemCircleAnimation(QGraphicsScene *scene = 0, QGraphicsItem *parent = 0); virtual ~ItemCircleAnimation(); - // overidden methods: + // overridden methods: QRectF boundingRect() const; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0); void hoverEnterEvent(QGraphicsSceneHoverEvent *event); diff --git a/demos/qtdemo/mainwindow.cpp b/demos/qtdemo/mainwindow.cpp index 16c5bf3..e39802a 100644 --- a/demos/qtdemo/mainwindow.cpp +++ b/demos/qtdemo/mainwindow.cpp @@ -388,7 +388,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) s += "\nAdapt: "; s += Colors::noAdapt ? "off" : "on"; - s += "\nAdaption occured: "; + s += "\nAdaption occurred: "; s += Colors::adapted ? "yes" : "no"; s += "\nOpenGL version: "; s += Colors::glVersion; diff --git a/demos/qtdemo/mainwindow.h b/demos/qtdemo/mainwindow.h index b8cfda6..460f941 100644 --- a/demos/qtdemo/mainwindow.h +++ b/demos/qtdemo/mainwindow.h @@ -74,7 +74,7 @@ public: DemoTextItem *fpsLabel; protected: - // Overidden methods: + // Overridden methods: void showEvent(QShowEvent *event); void keyPressEvent(QKeyEvent *event); void resizeEvent(QResizeEvent *event); diff --git a/demos/qtdemo/qmlShell.qml b/demos/qtdemo/qmlShell.qml index 2764865..8ca06f1 100644 --- a/demos/qtdemo/qmlShell.qml +++ b/demos/qtdemo/qmlShell.qml @@ -85,7 +85,7 @@ Item { MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton - onClicked: loader.focus=true;/* and don't propogate to the 'exit' area*/ + onClicked: loader.focus=true;/* and don't propagate to the 'exit' area*/ } Rectangle{ id: innerFrame diff --git a/demos/qtdemo/textbutton.h b/demos/qtdemo/textbutton.h index 55b4edc..039f923 100644 --- a/demos/qtdemo/textbutton.h +++ b/demos/qtdemo/textbutton.h @@ -61,7 +61,7 @@ public: QGraphicsScene *scene = 0, QGraphicsItem *parent = 0, BUTTONTYPE color = SIDEBAR); virtual ~TextButton(); - // overidden methods: + // overridden methods: virtual QRectF boundingRect() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0){}; virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); diff --git a/demos/spectrum/app/engine.h b/demos/spectrum/app/engine.h index b6fe3ed..e14ac83 100644 --- a/demos/spectrum/app/engine.h +++ b/demos/spectrum/app/engine.h @@ -227,7 +227,7 @@ signals: * Level changed * \param rmsLevel RMS level in range 0.0 - 1.0 * \param peakLevel Peak level in range 0.0 - 1.0 - * \param numSamples Number of audio samples analysed + * \param numSamples Number of audio samples analyzed */ void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples); diff --git a/demos/spectrum/app/levelmeter.h b/demos/spectrum/app/levelmeter.h index 38d13b1..683dba7 100644 --- a/demos/spectrum/app/levelmeter.h +++ b/demos/spectrum/app/levelmeter.h @@ -46,7 +46,7 @@ /** * Widget which displays a vertical audio level meter, indicating the - * RMS and peak levels of the window of audio samples most recently analysed + * RMS and peak levels of the window of audio samples most recently analyzed * by the Engine. */ class LevelMeter : public QWidget { diff --git a/demos/spectrum/app/main.cpp b/demos/spectrum/app/main.cpp index 3bdfb7d..fb5183e 100644 --- a/demos/spectrum/app/main.cpp +++ b/demos/spectrum/app/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char **argv) { QApplication app(argc, argv); - app.setApplicationName("QtMultimedia spectrum analyser"); + app.setApplicationName("QtMultimedia spectrum analyzer"); MainWidget w; #ifdef Q_OS_SYMBIAN diff --git a/demos/spectrum/app/spectrograph.h b/demos/spectrum/app/spectrograph.h index ce59d90..fa4a6cf 100644 --- a/demos/spectrum/app/spectrograph.h +++ b/demos/spectrum/app/spectrograph.h @@ -48,7 +48,7 @@ QT_FORWARD_DECLARE_CLASS(QMouseEvent) /** * Widget which displays a spectrograph showing the frequency spectrum - * of the window of audio samples most recently analysed by the Engine. + * of the window of audio samples most recently analyzed by the Engine. */ class Spectrograph : public QWidget { Q_OBJECT diff --git a/demos/spectrum/app/spectrumanalyser.cpp b/demos/spectrum/app/spectrumanalyser.cpp index c467f61..1cc47a6 100644 --- a/demos/spectrum/app/spectrumanalyser.cpp +++ b/demos/spectrum/app/spectrumanalyser.cpp @@ -124,7 +124,7 @@ void SpectrumAnalyserThread::calculateSpectrum(const QByteArray &buffer, // Calculate the FFT m_fft->calculateFFT(m_output.data(), m_input.data()); - // Analyse output to obtain amplitude and phase for each frequency + // Analyze output to obtain amplitude and phase for each frequency for (int i=2; i<=m_numSamples/2; ++i) { // Calculate frequency of this complex sample m_spectrum[i].frequency = qreal(i * inputFrequency) / (m_numSamples); diff --git a/demos/spectrum/app/wavfile.cpp b/demos/spectrum/app/wavfile.cpp index b9467e3..74d5918 100644 --- a/demos/spectrum/app/wavfile.cpp +++ b/demos/spectrum/app/wavfile.cpp @@ -76,80 +76,84 @@ struct CombinedHeader { RIFFHeader riff; WAVEHeader wave; - DATAHeader data; }; -static const int HeaderLength = sizeof(CombinedHeader); WavFile::WavFile(const QAudioFormat &format, qint64 dataLength) - : m_format(format) - , m_dataLength(dataLength) + : m_format(format) + , m_dataLength(dataLength) + , m_dataPosition(0) { - } bool WavFile::readHeader(QIODevice &device) { - bool result = true; - - if (!device.isSequential()) - result = device.seek(0); - // else, assume that current position is the start of the header - - if (result) { - CombinedHeader header; - result = (device.read(reinterpret_cast<char *>(&header), HeaderLength) == HeaderLength); - if (result) { - if ((memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0 - || memcmp(&header.riff.descriptor.id, "RIFX", 4) == 0) - && memcmp(&header.riff.type, "WAVE", 4) == 0 - && memcmp(&header.wave.descriptor.id, "fmt ", 4) == 0 - && header.wave.audioFormat == 1 // PCM - ) { - if (memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0) - m_format.setByteOrder(QAudioFormat::LittleEndian); - else - m_format.setByteOrder(QAudioFormat::BigEndian); - - m_format.setChannels(qFromLittleEndian<quint16>(header.wave.numChannels)); - m_format.setCodec("audio/pcm"); - m_format.setFrequency(qFromLittleEndian<quint32>(header.wave.sampleRate)); - m_format.setSampleSize(qFromLittleEndian<quint16>(header.wave.bitsPerSample)); - - switch(header.wave.bitsPerSample) { - case 8: - m_format.setSampleType(QAudioFormat::UnSignedInt); - break; - case 16: - m_format.setSampleType(QAudioFormat::SignedInt); - break; - default: - result = false; - } - - m_dataLength = device.size() - HeaderLength; - } else { - result = false; - } + if (!device.isSequential()) { + if (!device.seek(0)) + return false; + // XXX: else, assume that current position is the start of the header + } + + CombinedHeader header; + if (device.read(reinterpret_cast<char *>(&header), sizeof(CombinedHeader)) != sizeof(CombinedHeader)) + return false; + + if ((memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0 + || memcmp(&header.riff.descriptor.id, "RIFX", 4) == 0) + && memcmp(&header.riff.type, "WAVE", 4) == 0 + && memcmp(&header.wave.descriptor.id, "fmt ", 4) == 0 + && (header.wave.audioFormat == 1 || header.wave.audioFormat == 0)) { + + // Read off remaining header information + DATAHeader dataHeader; + + if (qFromLittleEndian<quint32>(header.wave.descriptor.size) > sizeof(WAVEHeader)) { + // Extended data available + quint16 extraFormatBytes; + if (device.peek((char*)&extraFormatBytes, sizeof(quint16)) != sizeof(quint16)) + return false; + const qint64 throwAwayBytes = sizeof(quint16) + qFromLittleEndian<quint16>(extraFormatBytes); + if (device.read(throwAwayBytes).size() != throwAwayBytes) + return false; } + + if (device.read((char*)&dataHeader, sizeof(DATAHeader)) != sizeof(DATAHeader)) + return false; + + // Establish format + if (memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0) + m_format.setByteOrder(QAudioFormat::LittleEndian); + else + m_format.setByteOrder(QAudioFormat::BigEndian); + + int bps = qFromLittleEndian<quint16>(header.wave.bitsPerSample); + m_format.setChannels(qFromLittleEndian<quint16>(header.wave.numChannels)); + m_format.setCodec("audio/pcm"); + m_format.setFrequency(qFromLittleEndian<quint32>(header.wave.sampleRate)); + m_format.setSampleSize(qFromLittleEndian<quint16>(header.wave.bitsPerSample)); + m_format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt); + + m_dataLength = qFromLittleEndian<quint32>(dataHeader.descriptor.size); + m_dataPosition = 0; } - return result; + return true; } bool WavFile::writeHeader(QIODevice &device) { CombinedHeader header; + DATAHeader dataHeader; - memset(&header, 0, HeaderLength); + memset(&header, 0, sizeof(CombinedHeader)); // RIFF header if (m_format.byteOrder() == QAudioFormat::LittleEndian) strncpy(&header.riff.descriptor.id[0], "RIFF", 4); else strncpy(&header.riff.descriptor.id[0], "RIFX", 4); - qToLittleEndian<quint32>(quint32(m_dataLength + HeaderLength - 8), + qToLittleEndian<quint32>(quint32(m_dataLength + sizeof(CombinedHeader) + sizeof(DATAHeader) - sizeof(chunk)), reinterpret_cast<unsigned char*>(&header.riff.descriptor.size)); strncpy(&header.riff.type[0], "WAVE", 4); @@ -171,11 +175,12 @@ bool WavFile::writeHeader(QIODevice &device) reinterpret_cast<unsigned char*>(&header.wave.bitsPerSample)); // DATA header - strncpy(&header.data.descriptor.id[0], "data", 4); + strncpy(dataHeader.descriptor.id, "data", 4); qToLittleEndian<quint32>(quint32(m_dataLength), - reinterpret_cast<unsigned char*>(&header.data.descriptor.size)); + reinterpret_cast<unsigned char*>(&dataHeader.descriptor.size)); - return (device.write(reinterpret_cast<const char *>(&header), HeaderLength) == HeaderLength); + return device.write(reinterpret_cast<const char *>(&header), sizeof(CombinedHeader)) == sizeof(CombinedHeader) + && device.write(reinterpret_cast<const char*>(&dataHeader), sizeof(DATAHeader)) == sizeof(DATAHeader); } const QAudioFormat& WavFile::format() const @@ -190,7 +195,7 @@ qint64 WavFile::dataLength() const qint64 WavFile::headerLength() { - return HeaderLength; + return sizeof(CombinedHeader); } bool WavFile::writeDataLength(QIODevice &device, qint64 dataLength) @@ -205,42 +210,47 @@ bool WavFile::writeDataLength(QIODevice &device, qint64 dataLength) return result; } -#include <QFile> -#include <QTextStream> - qint64 WavFile::readData(QIODevice &device, QByteArray &buffer, QAudioFormat outputFormat) { - if (QAudioFormat() == outputFormat) + // Sanity checks + if (!outputFormat.isValid()) outputFormat = m_format; + if (!isPCMS16LE(outputFormat) || !isPCMS16LE(m_format)) + return 0; + + if (m_dataPosition == m_dataLength) + return 0; + + // Process qint64 result = 0; - QFile file("wav.txt"); - file.open(QIODevice::WriteOnly | QIODevice::Text); - QTextStream stream; - stream.setDevice(&file); - - if (isPCMS16LE(outputFormat) && isPCMS16LE(m_format)) { - QVector<char> inputSample(2 * m_format.channels()); - - qint16 *output = reinterpret_cast<qint16*>(buffer.data()); - - while (result < buffer.size()) { - if (device.read(inputSample.data(), inputSample.count())) { - int inputIdx = 0; - for (int outputIdx = 0; outputIdx < outputFormat.channels(); ++outputIdx) { - const qint16* input = reinterpret_cast<const qint16*>(inputSample.data() + 2 * inputIdx); - *output++ = qFromLittleEndian<qint16>(*input); - result += 2; - if (inputIdx < m_format.channels()) - ++inputIdx; - } - } else { - break; + const int frameSize = 2 * m_format.channels(); // 16 bit samples + QVector<char> inputSample(frameSize); + + qint16 *output = reinterpret_cast<qint16*>(buffer.data()); + + while (result < buffer.size()) { + if (m_dataPosition == m_dataLength) + break; + + // XXX only working with particular alignments + if (device.read(inputSample.data(), inputSample.count())) { + int inputIdx = 0; + for (int outputIdx = 0; outputIdx < outputFormat.channels(); ++outputIdx) { + const qint16* input = reinterpret_cast<const qint16*>(inputSample.data() + 2 * inputIdx); + *output++ = qFromLittleEndian<qint16>(*input); + result += 2; + if (inputIdx < m_format.channels()) + ++inputIdx; } + m_dataPosition += frameSize; + } else { + break; } } + return result; } diff --git a/demos/spectrum/app/wavfile.h b/demos/spectrum/app/wavfile.h index f2f3304..fc14b08 100644 --- a/demos/spectrum/app/wavfile.h +++ b/demos/spectrum/app/wavfile.h @@ -77,6 +77,7 @@ public: private: QAudioFormat m_format; qint64 m_dataLength; + qint64 m_dataPosition; }; #endif diff --git a/demos/spreadsheet/spreadsheet.cpp b/demos/spreadsheet/spreadsheet.cpp index f2a1738..519afe9 100644 --- a/demos/spreadsheet/spreadsheet.cpp +++ b/demos/spreadsheet/spreadsheet.cpp @@ -511,7 +511,7 @@ void SpreadSheet::setupContents() // column 2 table->setItem(0, 2, new SpreadSheetItem("Price")); table->item(0, 2)->setBackgroundColor(titleBackground); - table->item(0, 2)->setToolTip("This collumn shows the price of the purchase"); + table->item(0, 2)->setToolTip("This column shows the price of the purchase"); table->item(0, 2)->setFont(titleFont); table->setItem(1, 2, new SpreadSheetItem("150")); diff --git a/demos/symbianpkgrules.pri b/demos/symbianpkgrules.pri index d42f188..c9cc492 100644 --- a/demos/symbianpkgrules.pri +++ b/demos/symbianpkgrules.pri @@ -13,4 +13,6 @@ vendorinfo = \ demos_deployment.pkg_prerules += vendorinfo DEPLOYMENT += demos_deployment -contains(TEMPLATE,app):isEmpty(ICON):ICON = $$QT_SOURCE_TREE/src/s60installs/qt.svg +isEmpty(ICON):contains(TEMPLATE, ".*app"):contains(QT, gui):contains(CONFIG, qt):!contains(CONFIG, "no_icon") { + ICON = $$QT_SOURCE_TREE/src/s60installs/qt.svg +} |