Phonon

videowidget.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2007 Matthias Kretz <kretz@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), Nokia Corporation
10 (or its successors, if any) and the KDE Free Qt Foundation, which shall
11 act as a proxy defined in Section 6 of version 3 of the license.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "videowidget.h"
24#include "videowidget_p.h"
25#include "videowidgetinterface.h"
26#include "factory_p.h"
27#include "phonondefs_p.h"
28#include "phononnamespace_p.h"
29
30#include <QAction>
31#define IFACES4 VideoWidgetInterface44
32#define IFACES0 VideoWidgetInterface, IFACES4
33#define PHONON_INTERFACENAME IFACES0
34
35#ifndef QT_NO_PHONON_VIDEO
36
37namespace Phonon
38{
39
41 : QWidget(parent)
42 , Phonon::AbstractVideoOutput(*new VideoWidgetPrivate(this))
43{
44 P_D(VideoWidget);
45 d->init();
46 d->createBackendObject();
47 setMouseTracking(true);
48}
49
50
51
52VideoWidget::VideoWidget(VideoWidgetPrivate &dd, QWidget *parent)
53 : QWidget(parent),
54 Phonon::AbstractVideoOutput(dd)
55{
56 P_D(VideoWidget);
57 d->init();
58}
59
60void VideoWidgetPrivate::init()
61{
62 P_Q(VideoWidget);
63 changeFlags = q->windowFlags() & (Qt::SubWindow | Qt::Window);
64}
65
66void VideoWidget::mouseMoveEvent(QMouseEvent *e)
67{
69}
70
71void VideoWidgetPrivate::createBackendObject()
72{
73 if (m_backendObject)
74 return;
75 P_Q(VideoWidget);
76 m_backendObject = Factory::createVideoWidget(q);
77 if (m_backendObject) {
78 setupBackendObject();
79 }
80}
81
82#define PHONON_CLASSNAME VideoWidget
83
84PHONON_INTERFACE_GETTER(Phonon::VideoWidget::AspectRatio, aspectRatio, d->aspectRatio)
85PHONON_INTERFACE_SETTER(setAspectRatio, aspectRatio, Phonon::VideoWidget::AspectRatio)
86
87PHONON_INTERFACE_GETTER(Phonon::VideoWidget::ScaleMode, scaleMode, d->scaleMode)
88PHONON_INTERFACE_SETTER(setScaleMode, scaleMode, Phonon::VideoWidget::ScaleMode)
89
90PHONON_INTERFACE_GETTER(qreal, brightness, d->brightness)
91PHONON_INTERFACE_SETTER(setBrightness, brightness, qreal)
92
93PHONON_INTERFACE_GETTER(qreal, contrast, d->contrast)
94PHONON_INTERFACE_SETTER(setContrast, contrast, qreal)
95
96PHONON_INTERFACE_GETTER(qreal, hue, d->hue)
97PHONON_INTERFACE_SETTER(setHue, hue, qreal)
98
99PHONON_INTERFACE_GETTER(qreal, saturation, d->saturation)
100PHONON_INTERFACE_SETTER(setSaturation, saturation, qreal)
101
102
103QImage VideoWidget::snapshot() const {
104 P_D(const VideoWidget);
105 ConstIface<IFACES4> iface(d);
106 if(iface) return iface->snapshot();
107 return QImage(); // TODO not implemented in VideoInterface
108}
109
110
111void VideoWidget::setFullScreen(bool newFullScreen)
112{
113 pDebug() << Q_FUNC_INFO << newFullScreen;
114 P_D(VideoWidget);
115 // TODO: disable screensaver? or should we leave that responsibility to the
116 // application?
118 if (newFullScreen) {
119 if (!isFullScreen()) {
120 //we only update that value if it is not already fullscreen
121 d->changeFlags = flags & (Qt::Window | Qt::SubWindow);
122 flags |= Qt::Window;
123 flags ^= Qt::SubWindow;
124 setWindowFlags(flags);
125#ifdef Q_WS_X11
126 // This works around a bug with Compiz
127 // as the window must be visible before we can set the state
128 show();
129 raise();
131#else
133 show();
134#endif
135 }
136 } else if (isFullScreen()) {
137 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
138 flags |= d->changeFlags; //then we reset the flags (window and subwindow)
139 setWindowFlags(flags);
141 show();
142 }
143}
144
146{
147 setFullScreen(false);
148}
149
151{
152 setFullScreen(true);
153}
154
155bool VideoWidgetPrivate::aboutToDeleteBackendObject()
156{
157 aspectRatio = pINTERFACE_CALL(aspectRatio());
158 scaleMode = pINTERFACE_CALL(scaleMode());
159 return AbstractVideoOutputPrivate::aboutToDeleteBackendObject();
160}
161
162void VideoWidgetPrivate::setupBackendObject()
163{
164 P_Q(VideoWidget);
165 Q_ASSERT(m_backendObject);
166 //AbstractVideoOutputPrivate::setupBackendObject();
167 pDebug() << "calling setAspectRatio on the backend " << aspectRatio;
168 pINTERFACE_CALL(setAspectRatio(aspectRatio));
169 pINTERFACE_CALL(setScaleMode(scaleMode));
170
171 QWidget *w = pINTERFACE_CALL(widget());
172 if (w) {
173 layout.addWidget(w);
174 q->setSizePolicy(w->sizePolicy());
175 w->setMouseTracking(true);
176 }
177}
178
179bool VideoWidget::event(QEvent *e)
180{
181 return QWidget::event(e);
182}
183
184} //namespace Phonon
185
186#endif //QT_NO_PHONON_VIDEO
187
188#include "moc_videowidget.cpp"
189
190#undef PHONON_CLASSNAME
191// vim: sw=4 ts=4 tw=80
Common base class for all video outputs.
Widget to display video.
Definition videowidget.h:55
void enterFullScreen()
Convenience slot, calling setFullScreen(true)
void exitFullScreen()
Convenience slot, calling setFullScreen(false)
VideoWidget(QWidget *parent=nullptr)
Constructs a new video widget with a parent.
AspectRatio
Defines the width:height to be used for the video.
WindowFullScreen
SubWindow
virtual bool event(QEvent *event) override
bool isFullScreen() const const
virtual void mouseMoveEvent(QMouseEvent *event)
void setMouseTracking(bool enable)
void raise()
void setWindowState(Qt::WindowStates windowState)
void show()
Qt::WindowStates windowState() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.