diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-10-11 15:21:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-07 10:30:54 +0100 |
commit | fa9ca95729252226b681b641d6b928d450e459a1 (patch) | |
tree | bb095e7579c8fdacd5bcc422a6a00266a6e12329 | |
parent | c86f2988bb8ef59fd9952ab4a90a9032a18738bb (diff) |
Add Quick Player example
This is a simplified Qt Quick-based version of the Music Player example.
Change-Id: Ica9da1b388ccbc4d22ae0dccecb8fbd2b270522a
Reviewed-by: Ivan Vizir <define-true-false@yandex.com>
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
20 files changed, 384 insertions, 0 deletions
diff --git a/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-composited.png b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-composited.png Binary files differnew file mode 100644 index 0000000..76c8734 --- /dev/null +++ b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-composited.png diff --git a/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-non-composited.png b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-non-composited.png Binary files differnew file mode 100644 index 0000000..23fdc56 --- /dev/null +++ b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-non-composited.png diff --git a/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-taskbar.png b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-taskbar.png Binary files differnew file mode 100644 index 0000000..17d62b8 --- /dev/null +++ b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-taskbar.png diff --git a/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-thumbnail.png b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-thumbnail.png Binary files differnew file mode 100644 index 0000000..0312ee2 --- /dev/null +++ b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-thumbnail.png diff --git a/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc b/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc new file mode 100644 index 0000000..68a08e8 --- /dev/null +++ b/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example quickplayer + \title Quick Player + \ingroup examples-qtwinextras + \brief Demonstrates using QtWinExtras in Qt Quick. + + \image qtwinextras-quickplayer-composited.png Screenshot of the Quick Player example + + The Quick Player example demonstrates how to use the various features + provided by the QtWinExtras module in Qt Quick. + + \note This example is a simplified Qt Quick-based version of the \l {Music Player} example. + + \section1 DWM Features + + The example uses Windows DWM (Desktop Window Manager) features to visually + integrate the window content to the window frame and to make the window + translucent and blurred. + + The example applies a different look based on whether composition is enabled + or not. When composition is enabled, the window is made translucent and + the window frame is extended to the client area to make the window content + integrate seamlessly to the window frame as shown above. + + \snippet quickplayer/qml/main.qml dwm + + When composition is disabled, the colorization color is used as a background + color for the window. + + \snippet quickplayer/qml/main.qml color + + The following screenshot illustrates how the Quick Player example looks when + composition is disabled. + + \image qtwinextras-quickplayer-non-composited.png Screenshot of the Quick Player example + + \section1 Taskbar Overlay and Progress + + The example uses Windows Taskbar for two things; it sets an overlay icon + that represents the current music playback state, and it indicates the + playback progress in the taskbar button. + + \image qtwinextras-quickplayer-taskbar.png Screenshot of the Quick Player taskbar + + The following snippet shows how the taskbar button is prepared. The taskbar progress + indicator and the overlay icon are bound to the music playback, and will automatically + change whenever the state or attributes of the music playback change. + + \snippet quickplayer/qml/main.qml taskbar + + \section1 Thumbnail Toolbar + + \image qtwinextras-quickplayer-thumbnail.png Screenshot of the Quick Player thumbnail + + The Windows Thumbnail Toolbar is used for providing basic music playback + controls. These controls can be used to control the application without + having to activate the application. The thumbnail toolbar buttons are bound + to the music playback, and will automatically change whenever the state or + attributes of the music playback changes. + + \snippet quickplayer/qml/main.qml thumbbar +*/ diff --git a/examples/winextras/quickplayer/images/media-pause-16.png b/examples/winextras/quickplayer/images/media-pause-16.png Binary files differnew file mode 100644 index 0000000..6cb1fd7 --- /dev/null +++ b/examples/winextras/quickplayer/images/media-pause-16.png diff --git a/examples/winextras/quickplayer/images/media-pause-32.png b/examples/winextras/quickplayer/images/media-pause-32.png Binary files differnew file mode 100644 index 0000000..3f172a0 --- /dev/null +++ b/examples/winextras/quickplayer/images/media-pause-32.png diff --git a/examples/winextras/quickplayer/images/media-play-16.png b/examples/winextras/quickplayer/images/media-play-16.png Binary files differnew file mode 100644 index 0000000..d7ee3cc --- /dev/null +++ b/examples/winextras/quickplayer/images/media-play-16.png diff --git a/examples/winextras/quickplayer/images/media-play-32.png b/examples/winextras/quickplayer/images/media-play-32.png Binary files differnew file mode 100644 index 0000000..af8d2f7 --- /dev/null +++ b/examples/winextras/quickplayer/images/media-play-32.png diff --git a/examples/winextras/quickplayer/images/media-seek-backward-32.png b/examples/winextras/quickplayer/images/media-seek-backward-32.png Binary files differnew file mode 100644 index 0000000..a21d137 --- /dev/null +++ b/examples/winextras/quickplayer/images/media-seek-backward-32.png diff --git a/examples/winextras/quickplayer/images/media-seek-forward-32.png b/examples/winextras/quickplayer/images/media-seek-forward-32.png Binary files differnew file mode 100644 index 0000000..4f8d370 --- /dev/null +++ b/examples/winextras/quickplayer/images/media-seek-forward-32.png diff --git a/examples/winextras/quickplayer/images/media-stop-32.png b/examples/winextras/quickplayer/images/media-stop-32.png Binary files differnew file mode 100644 index 0000000..aae24ba --- /dev/null +++ b/examples/winextras/quickplayer/images/media-stop-32.png diff --git a/examples/winextras/quickplayer/images/quickplayer.ico b/examples/winextras/quickplayer/images/quickplayer.ico Binary files differnew file mode 100644 index 0000000..fef1dee --- /dev/null +++ b/examples/winextras/quickplayer/images/quickplayer.ico diff --git a/examples/winextras/quickplayer/images/quickplayer.png b/examples/winextras/quickplayer/images/quickplayer.png Binary files differnew file mode 100644 index 0000000..7d3e97e --- /dev/null +++ b/examples/winextras/quickplayer/images/quickplayer.png diff --git a/examples/winextras/quickplayer/main.cpp b/examples/winextras/quickplayer/main.cpp new file mode 100644 index 0000000..39656a7 --- /dev/null +++ b/examples/winextras/quickplayer/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QQmlApplicationEngine> +#include <QGuiApplication> +#include <QWindow> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + app.setApplicationName("QuickPlayer"); + app.setOrganizationName("QtWinExtras"); + app.setOrganizationDomain("qt-project.org"); + app.setApplicationDisplayName("QtWinExtras Quick Player"); + + QQmlApplicationEngine engine(QUrl("qrc:/main.qml")); + QObject* root = engine.rootObjects().value(0); + if (QWindow *window = qobject_cast<QWindow *>(root)) + window->show(); + return app.exec(); +} diff --git a/examples/winextras/quickplayer/qml/main.qml b/examples/winextras/quickplayer/qml/main.qml new file mode 100644 index 0000000..b58b49a --- /dev/null +++ b/examples/winextras/quickplayer/qml/main.qml @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Window 2.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 +import QtQuick.Dialogs 1.0 +import QtMultimedia 5.0 +import QtWinExtras 1.0 as Win + +Window { + id: window + + title: qsTr("QtWinExtras Quick Player") + + width: 300 + height: 60 + minimumWidth: row.implicitWidth + 18 + minimumHeight: column.implicitHeight + 18 + + //! [color] + color: dwm.compositionEnabled ? "transparent" : dwm.realColorizationColor + //! [color] + + //! [dwm] + Win.DwmFeatures { + id: dwm + + topGlassMargin: -1 + leftGlassMargin: -1 + rightGlassMargin: -1 + bottomGlassMargin: -1 + } + //! [dwm] + + //! [taskbar] + Win.TaskbarButton { + id: taskbar + + progress.value: mediaPlayer.position + progress.maximum: mediaPlayer.duration + progress.visible: mediaPlayer.hasAudio + progress.paused: mediaPlayer.playbackState === MediaPlayer.PausedState + + overlay.iconSource: mediaPlayer.playbackState === MediaPlayer.PlayingState ? "qrc:/play-32.png" : + mediaPlayer.playbackState === MediaPlayer.PausedState ? "qrc:/pause-32.png" : "qrc:/stop-32.png" + } + //! [taskbar] + + //! [thumbbar] + Win.ThumbnailToolBar { + id: thumbbar + + Win.ThumbnailToolButton { + tooltip: qsTr("Rewind") + iconSource: "qrc:/backward-32.png" + + enabled: mediaPlayer.position > 0 + onClicked: mediaPlayer.seek(mediaPlayer.position - mediaPlayer.duration / 10) + } + + Win.ThumbnailToolButton { + tooltip: mediaPlayer.playbackState === MediaPlayer.PlayingState ? qsTr("Pause") : qsTr("Play") + iconSource: mediaPlayer.playbackState === MediaPlayer.PlayingState ? "qrc:/pause-32.png" : "qrc:/play-32.png" + + enabled: mediaPlayer.hasAudio + onClicked: mediaPlayer.playbackState === MediaPlayer.PlayingState ? mediaPlayer.pause() : mediaPlayer.play() + } + + Win.ThumbnailToolButton { + tooltip: qsTr("Fast forward") + iconSource: "qrc:/forward-32.png" + + enabled: mediaPlayer.position < mediaPlayer.duration + onClicked: mediaPlayer.seek(mediaPlayer.position + mediaPlayer.duration / 10) + } + } + //! [thumbbar] + + MediaPlayer { + id: mediaPlayer + autoPlay: true + readonly property string title: !!metaData.author && !!metaData.title + ? qsTr("%1 - %2").arg(metaData.author).arg(metaData.title) + : metaData.author || metaData.title || source + } + + ColumnLayout { + id: column + + anchors.margins: 9 + anchors.fill: parent + + Label { + id: infoLabel + + elide: Qt.ElideLeft + verticalAlignment: Qt.AlignVCenter + text: mediaPlayer.errorString || mediaPlayer.title + Layout.minimumHeight: infoLabel.implicitHeight + Layout.fillWidth: true + Layout.fillHeight: true + } + + RowLayout { + id: row + + Button { + id: openButton + + text: qsTr("...") + Layout.preferredWidth: openButton.implicitHeight + onClicked: fileDialog.open() + + FileDialog { + id: fileDialog + + title: qsTr("Open file") + nameFilters: [qsTr("MP3 files (*.mp3)"), qsTr("All files (*.*)")] + onAccepted: mediaPlayer.source = fileDialog.fileUrl + } + } + + Button { + id: playButton + + enabled: mediaPlayer.hasAudio + Layout.preferredWidth: playButton.implicitHeight + iconSource: mediaPlayer.playbackState === MediaPlayer.PlayingState ? "qrc:/pause-16.png" : "qrc:/play-16.png" + onClicked: mediaPlayer.playbackState === MediaPlayer.PlayingState ? mediaPlayer.pause() : mediaPlayer.play() + } + + Slider { + id: positionSlider + + Layout.fillWidth: true + maximumValue: mediaPlayer.duration + + property bool sync: false + + onValueChanged: { + if (!sync) + mediaPlayer.seek(value) + } + + Connections { + target: mediaPlayer + onPositionChanged: { + positionSlider.sync = true + positionSlider.value = mediaPlayer.position + positionSlider.sync = false + } + } + } + + Label { + id: positionLabel + + readonly property int minutes: Math.floor(mediaPlayer.position / 60000) + readonly property int seconds: Math.round((mediaPlayer.position % 60000) / 1000) + + text: Qt.formatTime(new Date(0, 0, 0, 0, minutes, seconds), qsTr("mm:ss")) + } + } + } +} diff --git a/examples/winextras/quickplayer/quickplayer.pro b/examples/winextras/quickplayer/quickplayer.pro new file mode 100644 index 0000000..f7474f7 --- /dev/null +++ b/examples/winextras/quickplayer/quickplayer.pro @@ -0,0 +1,18 @@ +TEMPLATE = app +TARGET = quickplayer + +QT += quick + +SOURCES = \ + main.cpp + +OTHER_FILES += \ + qml/main.qml + +RESOURCES += \ + quickplayer.qrc + +RC_ICONS = images/quickplayer.ico + +target.path = $$[QT_INSTALL_EXAMPLES]/winextras/quickplayer +INSTALLS += target diff --git a/examples/winextras/quickplayer/quickplayer.qrc b/examples/winextras/quickplayer/quickplayer.qrc new file mode 100644 index 0000000..7515bd2 --- /dev/null +++ b/examples/winextras/quickplayer/quickplayer.qrc @@ -0,0 +1,13 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file alias="main.qml">qml/main.qml</file> + <file alias="pause-16.png">images/media-pause-16.png</file> + <file alias="pause-32.png">images/media-pause-32.png</file> + <file alias="play-16.png">images/media-play-16.png</file> + <file alias="play-32.png">images/media-play-32.png</file> + <file alias="backward-32.png">images/media-seek-backward-32.png</file> + <file alias="forward-32.png">images/media-seek-forward-32.png</file> + <file alias="stop-32.png">images/media-stop-32.png</file> + <file alias="quickplayer.png">images/quickplayer.png</file> +</qresource> +</RCC> diff --git a/examples/winextras/quickplayer/quickplayer.rc b/examples/winextras/quickplayer/quickplayer.rc new file mode 100644 index 0000000..00a51ee --- /dev/null +++ b/examples/winextras/quickplayer/quickplayer.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "images\\musicplayer.ico" diff --git a/examples/winextras/winextras.pro b/examples/winextras/winextras.pro index 8cb2148..467d53b 100644 --- a/examples/winextras/winextras.pro +++ b/examples/winextras/winextras.pro @@ -3,4 +3,5 @@ win32 { SUBDIRS += \ iconextractor qtHaveModule(widgets):qtHaveModule(multimedia): SUBDIRS += musicplayer + qtHaveModule(quick):qtHaveModule(multimedia): SUBDIRS += quickplayer } |