| 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 <QtGui/QAction> |
| 31 |
#define IFACES4 VideoWidgetInterface44 |
| 32 |
#define IFACES0 VideoWidgetInterface, IFACES4 |
| 33 |
#define PHONON_INTERFACENAME IFACES0 |
| 34 |
|
| 35 |
QT_BEGIN_NAMESPACE |
| 36 |
|
| 37 |
#ifndef QT_NO_PHONON_VIDEO |
| 38 |
|
| 39 |
namespace Phonon |
| 40 |
{ |
| 41 |
|
| 42 |
VideoWidget::VideoWidget(QWidget *parent) |
| 43 |
: QWidget(parent) |
| 44 |
, Phonon::AbstractVideoOutput(*new VideoWidgetPrivate(this)) |
| 45 |
{ |
| 46 |
K_D(VideoWidget); |
| 47 |
d->init(); |
| 48 |
d->createBackendObject(); |
| 49 |
setMouseTracking(true); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
VideoWidget::VideoWidget(VideoWidgetPrivate &dd, QWidget *parent) |
| 55 |
: QWidget(parent), |
| 56 |
Phonon::AbstractVideoOutput(dd) |
| 57 |
{ |
| 58 |
K_D(VideoWidget); |
| 59 |
d->init(); |
| 60 |
} |
| 61 |
|
| 62 |
void VideoWidgetPrivate::init() |
| 63 |
{ |
| 64 |
Q_Q(VideoWidget); |
| 65 |
changeFlags = q->windowFlags() & (Qt::SubWindow | Qt::Window); |
| 66 |
} |
| 67 |
|
| 68 |
void VideoWidget::mouseMoveEvent(QMouseEvent *e) |
| 69 |
{ |
| 70 |
QWidget::mouseMoveEvent(e); |
| 71 |
} |
| 72 |
|
| 73 |
void VideoWidgetPrivate::createBackendObject() |
| 74 |
{ |
| 75 |
if (m_backendObject) |
| 76 |
return; |
| 77 |
Q_Q(VideoWidget); |
| 78 |
m_backendObject = Factory::createVideoWidget(q); |
| 79 |
if (m_backendObject) { |
| 80 |
setupBackendObject(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
#define PHONON_CLASSNAME VideoWidget |
| 85 |
|
| 86 |
PHONON_INTERFACE_GETTER(Phonon::VideoWidget::AspectRatio, aspectRatio, d->aspectRatio) |
| 87 |
PHONON_INTERFACE_SETTER(setAspectRatio, aspectRatio, Phonon::VideoWidget::AspectRatio) |
| 88 |
|
| 89 |
PHONON_INTERFACE_GETTER(Phonon::VideoWidget::ScaleMode, scaleMode, d->scaleMode) |
| 90 |
PHONON_INTERFACE_SETTER(setScaleMode, scaleMode, Phonon::VideoWidget::ScaleMode) |
| 91 |
|
| 92 |
PHONON_INTERFACE_GETTER(qreal, brightness, d->brightness) |
| 93 |
PHONON_INTERFACE_SETTER(setBrightness, brightness, qreal) |
| 94 |
|
| 95 |
PHONON_INTERFACE_GETTER(qreal, contrast, d->contrast) |
| 96 |
PHONON_INTERFACE_SETTER(setContrast, contrast, qreal) |
| 97 |
|
| 98 |
PHONON_INTERFACE_GETTER(qreal, hue, d->hue) |
| 99 |
PHONON_INTERFACE_SETTER(setHue, hue, qreal) |
| 100 |
|
| 101 |
PHONON_INTERFACE_GETTER(qreal, saturation, d->saturation) |
| 102 |
PHONON_INTERFACE_SETTER(setSaturation, saturation, qreal) |
| 103 |
|
| 104 |
|
| 105 |
QImage VideoWidget::snapshot() const { |
| 106 |
K_D(const VideoWidget); |
| 107 |
ConstIface<IFACES4> iface(d); |
| 108 |
if(iface) return iface->snapshot(); |
| 109 |
return QImage(); // TODO not implemented in VideoInterface |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
void VideoWidget::setFullScreen(bool newFullScreen) |
| 114 |
{ |
| 115 |
pDebug() << Q_FUNC_INFO << newFullScreen; |
| 116 |
K_D(VideoWidget); |
| 117 |
// TODO: disable screensaver? or should we leave that responsibility to the |
| 118 |
// application? |
| 119 |
Qt::WindowFlags flags = windowFlags(); |
| 120 |
if (newFullScreen) { |
| 121 |
if (!isFullScreen()) { |
| 122 |
//we only update that value if it is not already fullscreen |
| 123 |
d->changeFlags = flags & (Qt::Window | Qt::SubWindow); |
| 124 |
flags |= Qt::Window; |
| 125 |
flags ^= Qt::SubWindow; |
| 126 |
setWindowFlags(flags); |
| 127 |
#ifdef Q_WS_X11 |
| 128 |
// This works around a bug with Compiz |
| 129 |
// as the window must be visible before we can set the state |
| 130 |
show(); |
| 131 |
raise(); |
| 132 |
setWindowState( windowState() | Qt::WindowFullScreen ); // set |
| 133 |
#else |
| 134 |
setWindowState( windowState() | Qt::WindowFullScreen ); // set |
| 135 |
show(); |
| 136 |
#endif |
| 137 |
} |
| 138 |
} else if (isFullScreen()) { |
| 139 |
flags ^= (Qt::Window | Qt::SubWindow); //clear the flags... |
| 140 |
flags |= d->changeFlags; //then we reset the flags (window and subwindow) |
| 141 |
setWindowFlags(flags); |
| 142 |
setWindowState( windowState() ^ Qt::WindowFullScreen ); // reset |
| 143 |
show(); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
void VideoWidget::exitFullScreen() |
| 148 |
{ |
| 149 |
setFullScreen(false); |
| 150 |
} |
| 151 |
|
| 152 |
void VideoWidget::enterFullScreen() |
| 153 |
{ |
| 154 |
setFullScreen(true); |
| 155 |
} |
| 156 |
|
| 157 |
bool VideoWidgetPrivate::aboutToDeleteBackendObject() |
| 158 |
{ |
| 159 |
aspectRatio = pINTERFACE_CALL(aspectRatio()); |
| 160 |
scaleMode = pINTERFACE_CALL(scaleMode()); |
| 161 |
return AbstractVideoOutputPrivate::aboutToDeleteBackendObject(); |
| 162 |
} |
| 163 |
|
| 164 |
void VideoWidgetPrivate::setupBackendObject() |
| 165 |
{ |
| 166 |
Q_Q(VideoWidget); |
| 167 |
Q_ASSERT(m_backendObject); |
| 168 |
//AbstractVideoOutputPrivate::setupBackendObject(); |
| 169 |
pDebug() << "calling setAspectRatio on the backend " << aspectRatio; |
| 170 |
pINTERFACE_CALL(setAspectRatio(aspectRatio)); |
| 171 |
pINTERFACE_CALL(setScaleMode(scaleMode)); |
| 172 |
|
| 173 |
QWidget *w = pINTERFACE_CALL(widget()); |
| 174 |
if (w) { |
| 175 |
layout.addWidget(w); |
| 176 |
q->setSizePolicy(w->sizePolicy()); |
| 177 |
w->setMouseTracking(true); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
bool VideoWidget::event(QEvent *e) |
| 182 |
{ |
| 183 |
return QWidget::event(e); |
| 184 |
} |
| 185 |
|
| 186 |
} //namespace Phonon |
| 187 |
|
| 188 |
#endif //QT_NO_PHONON_VIDEO |
| 189 |
|
| 190 |
QT_END_NAMESPACE |
| 191 |
|
| 192 |
#include "moc_videowidget.cpp" |
| 193 |
|
| 194 |
#undef PHONON_CLASSNAME |
| 195 |
// vim: sw=4 ts=4 tw=80 |