diff options
Diffstat (limited to 'examples/phonon')
-rw-r--r-- | examples/phonon/README | 39 | ||||
-rw-r--r-- | examples/phonon/capabilities/capabilities.pro | 16 | ||||
-rw-r--r-- | examples/phonon/capabilities/main.cpp | 58 | ||||
-rw-r--r-- | examples/phonon/capabilities/window.cpp | 166 | ||||
-rw-r--r-- | examples/phonon/capabilities/window.h | 97 | ||||
-rw-r--r-- | examples/phonon/musicplayer/main.cpp | 57 | ||||
-rw-r--r-- | examples/phonon/musicplayer/mainwindow.cpp | 352 | ||||
-rw-r--r-- | examples/phonon/musicplayer/mainwindow.h | 112 | ||||
-rw-r--r-- | examples/phonon/musicplayer/musicplayer.pro | 16 | ||||
-rw-r--r-- | examples/phonon/phonon.pro | 10 |
10 files changed, 923 insertions, 0 deletions
diff --git a/examples/phonon/README b/examples/phonon/README new file mode 100644 index 0000000..d0f4462 --- /dev/null +++ b/examples/phonon/README @@ -0,0 +1,39 @@ +Qt usese the Phonon cross-platform multimedia framework to play common +multimedia formats. + +Applications can be written to take advantage of the native multimedia +technologies on each platform via a consistent cross-platform Qt API. + + +Some of the examples in this directory can be run from the example launcher; +others can only be used from within Qt Designer. + +Documentation for these examples can be found via the "Tutorial and Examples" +link in the main Qt documentation. + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/phonon/capabilities/capabilities.pro b/examples/phonon/capabilities/capabilities.pro new file mode 100644 index 0000000..52b6b1b --- /dev/null +++ b/examples/phonon/capabilities/capabilities.pro @@ -0,0 +1,16 @@ +QT += phonon + +HEADERS += window.h +SOURCES += window.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/phonon/capabilities +sources.files = $$SOURCES $$HEADERS capabilities.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/capabilities +INSTALLS += target sources + +wince*{ +DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout +} + diff --git a/examples/phonon/capabilities/main.cpp b/examples/phonon/capabilities/main.cpp new file mode 100644 index 0000000..a746925 --- /dev/null +++ b/examples/phonon/capabilities/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [everything] +int main(int argv, char **args) +{ + QApplication app(argv, args); + app.setApplicationName("Phonon Capabilities Example"); + + Window window; + window.show(); + + return app.exec(); +} +//! [everything] + diff --git a/examples/phonon/capabilities/window.cpp b/examples/phonon/capabilities/window.cpp new file mode 100644 index 0000000..920e3e0 --- /dev/null +++ b/examples/phonon/capabilities/window.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [constructor] +Window::Window() +{ + setupUi(); + updateWidgets(); + + connect(Phonon::BackendCapabilities::notifier(), + SIGNAL(capabilitiesChanged()), this, SLOT(updateWidgets())); + connect(Phonon::BackendCapabilities::notifier(), + SIGNAL(availableAudioOutputDevicesChanged()), SLOT(updateWidgets())); +} +//! [constructor] + +//! [outputDevices] +void Window::updateWidgets() +{ + devicesListView->setModel(new QStandardItemModel()); + Phonon::ObjectDescriptionModel<Phonon::AudioOutputDeviceType> *model = + new Phonon::ObjectDescriptionModel<Phonon::AudioOutputDeviceType>(); + model->setModelData(Phonon::BackendCapabilities::availableAudioOutputDevices()); + devicesListView->setModel(model); +//! [outputDevices] + +//! [mimeTypes] + mimeListWidget->clear(); + QStringList mimeTypes = + Phonon::BackendCapabilities::availableMimeTypes(); + foreach (QString mimeType, mimeTypes) { + QListWidgetItem *item = new QListWidgetItem(mimeListWidget); + item->setText(mimeType); + } +//! [mimeTypes] + +//! [effects] + effectsTreeWidget->clear(); + QList<Phonon::EffectDescription> effects = + Phonon::BackendCapabilities::availableAudioEffects(); + foreach (Phonon::EffectDescription effect, effects) { + QTreeWidgetItem *item = new QTreeWidgetItem(effectsTreeWidget); + item->setText(0, tr("Effect")); + item->setText(1, effect.name()); + item->setText(2, effect.description()); +//! [effects] + +//! [effectsParameters] + Phonon::Effect *instance = new Phonon::Effect(effect, this); + QList<Phonon::EffectParameter> parameters = instance->parameters(); + for (int i = 0; i < parameters.size(); ++i) { + Phonon::EffectParameter parameter = parameters.at(i); + + QVariant defaultValue = parameter.defaultValue(); + QVariant minimumValue = parameter.minimumValue(); + QVariant maximumValue = parameter.maximumValue(); + + QString valueString = QString("%1 / %2 / %3") + .arg(defaultValue.toString()).arg(minimumValue.toString()) + .arg(maximumValue.toString()); + + QTreeWidgetItem *parameterItem = new QTreeWidgetItem(item); + parameterItem->setText(0, tr("Parameter")); + parameterItem->setText(1, parameter.name()); + parameterItem->setText(2, parameter.description()); + parameterItem->setText(3, QVariant::typeToName(parameter.type())); + parameterItem->setText(4, valueString); + } + } +//! [effectsParameters] + for (int i = 0; i < effectsTreeWidget->columnCount(); ++i) { + if (i == 0) + effectsTreeWidget->setColumnWidth(0, 150); + else if (i == 2) + effectsTreeWidget->setColumnWidth(2, 350); + else + effectsTreeWidget->resizeColumnToContents(i); + } +} + +void Window::setupUi() +{ + setupBackendBox(); + + QLayout *layout = new QVBoxLayout; + layout->addWidget(backendBox); + + setLayout(layout); + setWindowTitle(tr("Backend Capabilities Example")); +} + +void Window::setupBackendBox() +{ + backendBox = new QGroupBox(tr("Backend Capabilities")); + + devicesLabel = new QLabel(tr("Available Audio Devices:")); + devicesListView = new QListView; + + mimeTypesLabel = new QLabel(tr("Supported MIME Types:")); + mimeListWidget = new QListWidget; + + effectsLabel = new QLabel(tr("Available Audio Effects:")); + + QStringList headerLabels; + headerLabels << tr("Type") << tr("Name") << tr("Description") << + tr("Value Type") << tr("Default/Min/Max Values"); + + effectsTreeWidget = new QTreeWidget; + effectsTreeWidget->setHeaderLabels(headerLabels); + effectsTreeWidget->setColumnCount(5); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(devicesLabel, 0, 0); + layout->addWidget(devicesListView, 1, 0); + layout->addWidget(mimeTypesLabel, 0, 1); + layout->addWidget(mimeListWidget, 1, 1); + layout->addWidget(effectsLabel, 2, 0); + layout->addWidget(effectsTreeWidget, 3, 0, 2, 2); + layout->setRowStretch(3, 100); + + backendBox = new QGroupBox(tr("Backend Capabilities")); + backendBox->setLayout(layout); +} + diff --git a/examples/phonon/capabilities/window.h b/examples/phonon/capabilities/window.h new file mode 100644 index 0000000..23121d3 --- /dev/null +++ b/examples/phonon/capabilities/window.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +#include <Phonon/AudioOutput> +#include <Phonon/SeekSlider> +#include <Phonon/MediaObject> +#include <Phonon/VolumeSlider> +#include <Phonon/BackendCapabilities> +#include <Phonon/Effect> +#include <Phonon/EffectParameter> +#include <Phonon/ObjectDescriptionModel> +#include <QList> + +QT_BEGIN_NAMESPACE +class QAction; +class QGroupBox; +class QPushButton; +class QLabel; +class QListWidget; +class QListView; +class QTextEdit; +class QTreeWidget; +QT_END_NAMESPACE + + +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +//! [windowMembers] +private slots: + void updateWidgets(); + +private: + void setupUi(); + void setupBackendBox(); + + QGroupBox *backendBox; + + QLabel *devicesLabel; + QLabel *mimeTypesLabel; + QLabel *effectsLabel; + + QListWidget *mimeListWidget; + QListView *devicesListView; + QTreeWidget *effectsTreeWidget; +//! [windowMembers] +}; + +#endif + diff --git a/examples/phonon/musicplayer/main.cpp b/examples/phonon/musicplayer/main.cpp new file mode 100644 index 0000000..4a614c8 --- /dev/null +++ b/examples/phonon/musicplayer/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtGui> + +#include "mainwindow.h" + +//![1] +int main(int argv, char **args) +{ + QApplication app(argv, args); + app.setApplicationName("Music Player"); + app.setQuitOnLastWindowClosed(true); + + MainWindow window; + window.show(); + + return app.exec(); +} +//![1] diff --git a/examples/phonon/musicplayer/mainwindow.cpp b/examples/phonon/musicplayer/mainwindow.cpp new file mode 100644 index 0000000..f50a2bd --- /dev/null +++ b/examples/phonon/musicplayer/mainwindow.cpp @@ -0,0 +1,352 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +//![0] +MainWindow::MainWindow() +{ + audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + mediaObject = new Phonon::MediaObject(this); + metaInformationResolver = new Phonon::MediaObject(this); + + mediaObject->setTickInterval(1000); +//![0] +//![2] + connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); + connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), + this, SLOT(stateChanged(Phonon::State, Phonon::State))); + connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(metaStateChanged(Phonon::State, Phonon::State))); + connect(mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource &)), + this, SLOT(sourceChanged(const Phonon::MediaSource &))); + connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish())); +//![2] + +//![1] + Phonon::createPath(mediaObject, audioOutput); +//![1] + + setupActions(); + setupMenus(); + setupUi(); + timeLcd->display("00:00"); +} + +//![6] +void MainWindow::addFiles() +{ + QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Music Files"), + QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); + + if (files.isEmpty()) + return; + + int index = sources.size(); + foreach (QString string, files) { + Phonon::MediaSource source(string); + + sources.append(source); + } + if (!sources.isEmpty()) + metaInformationResolver->setCurrentSource(sources.at(index)); + +} +//![6] + +void MainWindow::about() +{ + QMessageBox::information(this, tr("About Music Player"), + tr("The Music Player example shows how to use Phonon - the multimedia" + " framework that comes with Qt - to create a simple music player.")); +} + +//![9] +void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) +{ + switch (newState) { + case Phonon::ErrorState: + if (mediaObject->errorType() == Phonon::FatalError) { + QMessageBox::warning(this, tr("Fatal Error"), + mediaObject->errorString()); + } else { + QMessageBox::warning(this, tr("Error"), + mediaObject->errorString()); + } + break; +//![9] +//![10] + case Phonon::PlayingState: + playAction->setEnabled(false); + pauseAction->setEnabled(true); + stopAction->setEnabled(true); + break; + case Phonon::StoppedState: + stopAction->setEnabled(false); + playAction->setEnabled(true); + pauseAction->setEnabled(false); + timeLcd->display("00:00"); + break; + case Phonon::PausedState: + pauseAction->setEnabled(false); + stopAction->setEnabled(true); + playAction->setEnabled(true); + break; +//![10] + case Phonon::BufferingState: + break; + default: + ; + } +} + +//![11] +void MainWindow::tick(qint64 time) +{ + QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60); + + timeLcd->display(displayTime.toString("mm:ss")); +} +//![11] + +//![12] +void MainWindow::tableClicked(int row, int /* column */) +{ + bool wasPlaying = mediaObject->state() == Phonon::PlayingState; + + mediaObject->stop(); + mediaObject->clearQueue(); + + mediaObject->setCurrentSource(sources[row]); + + if (wasPlaying) + mediaObject->play(); + else + mediaObject->stop(); +} +//![12] + +//![13] +void MainWindow::sourceChanged(const Phonon::MediaSource &source) +{ + musicTable->selectRow(sources.indexOf(source)); + timeLcd->display("00:00"); +} +//![13] + +//![14] +void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */) +{ + if (newState == Phonon::ErrorState) { + QMessageBox::warning(this, tr("Error opening files"), + metaInformationResolver->errorString()); + while (!sources.isEmpty() && + !(sources.takeLast() == metaInformationResolver->currentSource())); + return; + } + + if (newState != Phonon::StoppedState && newState != Phonon::PausedState) + return; + + if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid) + return; + + QMap<QString, QString> metaData = metaInformationResolver->metaData(); + + QString title = metaData.value("TITLE"); + if (title == "") + title = metaInformationResolver->currentSource().fileName(); + + QTableWidgetItem *titleItem = new QTableWidgetItem(title); + titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST")); + artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM")); + albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *yearItem = new QTableWidgetItem(metaData.value("DATE")); + yearItem->setFlags(yearItem->flags() ^ Qt::ItemIsEditable); +//![14] + + int currentRow = musicTable->rowCount(); + musicTable->insertRow(currentRow); + musicTable->setItem(currentRow, 0, titleItem); + musicTable->setItem(currentRow, 1, artistItem); + musicTable->setItem(currentRow, 2, albumItem); + musicTable->setItem(currentRow, 3, yearItem); + +//![15] + if (musicTable->selectedItems().isEmpty()) { + musicTable->selectRow(0); + mediaObject->setCurrentSource(metaInformationResolver->currentSource()); + } + + Phonon::MediaSource source = metaInformationResolver->currentSource(); + int index = sources.indexOf(metaInformationResolver->currentSource()) + 1; + if (sources.size() > index) { + metaInformationResolver->setCurrentSource(sources.at(index)); + } + else { + musicTable->resizeColumnsToContents(); + if (musicTable->columnWidth(0) > 300) + musicTable->setColumnWidth(0, 300); + } +} +//![15] + +//![16] +void MainWindow::aboutToFinish() +{ + int index = sources.indexOf(mediaObject->currentSource()) + 1; + if (sources.size() > index) { + mediaObject->enqueue(sources.at(index)); + } +} +//![16] + +void MainWindow::setupActions() +{ + playAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), tr("Play"), this); + playAction->setShortcut(tr("Crl+P")); + playAction->setDisabled(true); + pauseAction = new QAction(style()->standardIcon(QStyle::SP_MediaPause), tr("Pause"), this); + pauseAction->setShortcut(tr("Ctrl+A")); + pauseAction->setDisabled(true); + stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop), tr("Stop"), this); + stopAction->setShortcut(tr("Ctrl+S")); + stopAction->setDisabled(true); + nextAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipForward), tr("Next"), this); + nextAction->setShortcut(tr("Ctrl+N")); + previousAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), tr("Previous"), this); + previousAction->setShortcut(tr("Ctrl+R")); + addFilesAction = new QAction(tr("Add &Files"), this); + addFilesAction->setShortcut(tr("Ctrl+F")); + exitAction = new QAction(tr("E&xit"), this); + exitAction->setShortcut(tr("Ctrl+X")); + aboutAction = new QAction(tr("A&bout"), this); + aboutAction->setShortcut(tr("Ctrl+B")); + aboutQtAction = new QAction(tr("About &Qt"), this); + aboutQtAction->setShortcut(tr("Ctrl+Q")); + +//![5] + connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play())); + connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) ); + connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop())); +//![5] + connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles())); + connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::setupMenus() +{ + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(addFilesAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + QMenu *aboutMenu = menuBar()->addMenu(tr("&Help")); + aboutMenu->addAction(aboutAction); + aboutMenu->addAction(aboutQtAction); +} + +//![3] +void MainWindow::setupUi() +{ +//![3] + QToolBar *bar = new QToolBar; + + bar->addAction(playAction); + bar->addAction(pauseAction); + bar->addAction(stopAction); + +//![4] + seekSlider = new Phonon::SeekSlider(this); + seekSlider->setMediaObject(mediaObject); + + volumeSlider = new Phonon::VolumeSlider(this); + volumeSlider->setAudioOutput(audioOutput); +//![4] + volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + QLabel *volumeLabel = new QLabel; + volumeLabel->setPixmap(QPixmap("images/volume.png")); + + QPalette palette; + palette.setBrush(QPalette::Light, Qt::darkGray); + + timeLcd = new QLCDNumber; + timeLcd->setPalette(palette); + + QStringList headers; + headers << tr("Title") << tr("Artist") << tr("Album") << tr("Year"); + + musicTable = new QTableWidget(0, 4); + musicTable->setHorizontalHeaderLabels(headers); + musicTable->setSelectionMode(QAbstractItemView::SingleSelection); + musicTable->setSelectionBehavior(QAbstractItemView::SelectRows); + connect(musicTable, SIGNAL(cellPressed(int, int)), + this, SLOT(tableClicked(int, int))); + + QHBoxLayout *seekerLayout = new QHBoxLayout; + seekerLayout->addWidget(seekSlider); + seekerLayout->addWidget(timeLcd); + + QHBoxLayout *playbackLayout = new QHBoxLayout; + playbackLayout->addWidget(bar); + playbackLayout->addStretch(); + playbackLayout->addWidget(volumeLabel); + playbackLayout->addWidget(volumeSlider); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(musicTable); + mainLayout->addLayout(seekerLayout); + mainLayout->addLayout(playbackLayout); + + QWidget *widget = new QWidget; + widget->setLayout(mainLayout); + + setCentralWidget(widget); + setWindowTitle("Phonon Music Player"); +} + diff --git a/examples/phonon/musicplayer/mainwindow.h b/examples/phonon/musicplayer/mainwindow.h new file mode 100644 index 0000000..2d4e297 --- /dev/null +++ b/examples/phonon/musicplayer/mainwindow.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <Phonon/AudioOutput> +#include <Phonon/SeekSlider> +#include <Phonon/MediaObject> +#include <Phonon/VolumeSlider> +#include <Phonon/BackendCapabilities> +#include <QList> + +QT_BEGIN_NAMESPACE +class QAction; +class QTableWidget; +class QLCDNumber; +QT_END_NAMESPACE + +//![0] + +class MainWindow : public QMainWindow +{ +//![0] + Q_OBJECT + +public: + MainWindow(); + + QSize sizeHint() const { + return QSize(500, 300); + } + +private slots: + void addFiles(); + void about(); +//![1] + void stateChanged(Phonon::State newState, Phonon::State oldState); + void tick(qint64 time); + void sourceChanged(const Phonon::MediaSource &source); + void metaStateChanged(Phonon::State newState, Phonon::State oldState); + void aboutToFinish(); + void tableClicked(int row, int column); +//![1] + +private: + void setupActions(); + void setupMenus(); + void setupUi(); + +//![2] + Phonon::SeekSlider *seekSlider; + Phonon::MediaObject *mediaObject; + Phonon::MediaObject *metaInformationResolver; + Phonon::AudioOutput *audioOutput; + Phonon::VolumeSlider *volumeSlider; + QList<Phonon::MediaSource> sources; +//![2] + + QAction *playAction; + QAction *pauseAction; + QAction *stopAction; + QAction *nextAction; + QAction *previousAction; + QAction *addFilesAction; + QAction *exitAction; + QAction *aboutAction; + QAction *aboutQtAction; + QLCDNumber *timeLcd; + QTableWidget *musicTable; +}; + +#endif diff --git a/examples/phonon/musicplayer/musicplayer.pro b/examples/phonon/musicplayer/musicplayer.pro new file mode 100644 index 0000000..0a93dc2 --- /dev/null +++ b/examples/phonon/musicplayer/musicplayer.pro @@ -0,0 +1,16 @@ +QT += phonon + +HEADERS += mainwindow.h +SOURCES += main.cpp \ + mainwindow.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/phonon/musicplayer +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images +sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/musicplayer +INSTALLS += target sources + +wince*{ +DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout +} + diff --git a/examples/phonon/phonon.pro b/examples/phonon/phonon.pro new file mode 100644 index 0000000..0dea766 --- /dev/null +++ b/examples/phonon/phonon.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs +CONFIG += ordered +SUBDIRS = musicplayer \ + capabilities + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/phonon +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS phonon.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/phonon +INSTALLS += target sources |