1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/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: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\example musicplayer
\title Music Player
\ingroup examples-qtwinextras
\brief Demonstrates managing Windows DWM features, jump lists,
taskbar button overlay, and thumbnail toolbar.
\image qtwinextras-musicplayer-composited.png Screenshot of the Music Player example
The Music Player example demonstrates how to use the various features
provided by the QtWinExtras module.
\note The example uses QMediaPlayer from the QtMultimedia module to play
the music, but this article focuses on the parts where QtWinExtras features
are used.
\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 main window
and the volume popup translucent and blurred.
The example applies a different look based on whether composition is enabled
or not. When composition is enabled, the main 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. When composition
is disabled, the colorization color is used as a background color. The
following screenshot illustrates how the Music Player example looks when
composition is disabled.
\image qtwinextras-musicplayer-non-composited.png Screenshot of the Music Player example
The respective code is a combination of extending or resetting the system
frame, adjusting the necessary QWidget attributes, and setting an appropriate
style sheet to achieve the desired look.
\snippet musicplayer/musicplayer.cpp 1
The volume popup does not have a window frame so it is enough to make the
popup blurred when composition is enabled. Additionally, a style sheet is
applied to get a border that follows the colorization color. Just like for
the main window, when composition is disabled, the colorization color is
used as a background color.
\snippet musicplayer/volumebutton.cpp 0
The example application respects the user's composition settings, reacts
to dynamic composition changes, and looks solid regardless of whether
composition is enabled or not. It accomplishes this by catching
QWinEvent::CompositionChange and QWinEvent::ColorizationChange events
and adjusting its looks accordingly.
\snippet musicplayer/musicplayer.cpp 0
\section1 Jump List
The example creates a custom jump list to provide the user with fast
access to recently played music files.
\snippet musicplayer/musicplayer.cpp 4
To enable the application jump list to show the desired recent files,
the corresponding file types are registered using the following helper
function.
\snippet musicplayer/main.cpp 0
\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-musicplayer-taskbar.png Screenshot of the Music Player taskbar
The following snippets show how the taskbar button is prepared.
For the taskbar and the thumbnail toolbar to work, a native window handle
must be set by passing an instance of \c QWindow to
\c QWinTaskbarButton::setWindow() or \c QWinThumbnailToolBar::setWindow(),
respectively. This instance is created in the process of \c QWidget::show()
and can be retrieved by calling \c QWidget::windowHandle() afterwards.
We override \c QWidget::showEvent() for this purpose:
\snippet musicplayer/musicplayer.cpp 7
The playback progress is wired directly to the taskbar progress indicator
by using signals and slots.
\snippet musicplayer/musicplayer.cpp 5
The overlay icon and the progress indicator are updated whenever the state
of the music playback changes.
\snippet musicplayer/musicplayer.cpp 2
\section1 Thumbnail Toolbar
\image qtwinextras-musicplayer-thumbnail.png Screenshot of the Music 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.
\snippet musicplayer/musicplayer.cpp 6
The buttons in the thumbnail toolbar are updated accordingly whenever the state
of the music playback changes.
\snippet musicplayer/musicplayer.cpp 3
*/
|