File indexing completed on 2024-04-21 04:43:20

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2005-2007 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 */
0022 
0023 #include "videowidget.h"
0024 #include "videowidget_p.h"
0025 #include "videowidgetinterface.h"
0026 #include "factory_p.h"
0027 #include "phonondefs_p.h"
0028 #include "phononnamespace_p.h"
0029 
0030 #include <QAction>
0031 #define IFACES4 VideoWidgetInterface44
0032 #define IFACES0 VideoWidgetInterface, IFACES4
0033 #define PHONON_INTERFACENAME IFACES0
0034 
0035 #ifndef QT_NO_PHONON_VIDEO
0036 
0037 namespace Phonon
0038 {
0039 
0040 VideoWidget::VideoWidget(QWidget *parent)
0041     : QWidget(parent)
0042     , Phonon::AbstractVideoOutput(*new VideoWidgetPrivate(this))
0043 {
0044     P_D(VideoWidget);
0045     d->init();
0046     d->createBackendObject();
0047     setMouseTracking(true);
0048 }
0049 
0050 
0051 
0052 VideoWidget::VideoWidget(VideoWidgetPrivate &dd, QWidget *parent)
0053     : QWidget(parent),
0054     Phonon::AbstractVideoOutput(dd)
0055 {
0056     P_D(VideoWidget);
0057     d->init();
0058 }
0059 
0060 void VideoWidgetPrivate::init()
0061 {
0062     P_Q(VideoWidget);
0063     changeFlags = q->windowFlags() & (Qt::SubWindow | Qt::Window);
0064 }
0065 
0066 void VideoWidget::mouseMoveEvent(QMouseEvent *e)
0067 {
0068     QWidget::mouseMoveEvent(e);
0069 }
0070 
0071 void VideoWidgetPrivate::createBackendObject()
0072 {
0073     if (m_backendObject)
0074         return;
0075     P_Q(VideoWidget);
0076     m_backendObject = Factory::createVideoWidget(q);
0077     if (m_backendObject) {
0078         setupBackendObject();
0079     }
0080 }
0081 
0082 #define PHONON_CLASSNAME VideoWidget
0083 
0084 PHONON_INTERFACE_GETTER(Phonon::VideoWidget::AspectRatio, aspectRatio, d->aspectRatio)
0085 PHONON_INTERFACE_SETTER(setAspectRatio, aspectRatio, Phonon::VideoWidget::AspectRatio)
0086 
0087 PHONON_INTERFACE_GETTER(Phonon::VideoWidget::ScaleMode, scaleMode, d->scaleMode)
0088 PHONON_INTERFACE_SETTER(setScaleMode, scaleMode, Phonon::VideoWidget::ScaleMode)
0089 
0090 PHONON_INTERFACE_GETTER(qreal, brightness, d->brightness)
0091 PHONON_INTERFACE_SETTER(setBrightness, brightness, qreal)
0092 
0093 PHONON_INTERFACE_GETTER(qreal, contrast, d->contrast)
0094 PHONON_INTERFACE_SETTER(setContrast, contrast, qreal)
0095 
0096 PHONON_INTERFACE_GETTER(qreal, hue, d->hue)
0097 PHONON_INTERFACE_SETTER(setHue, hue, qreal)
0098 
0099 PHONON_INTERFACE_GETTER(qreal, saturation, d->saturation)
0100 PHONON_INTERFACE_SETTER(setSaturation, saturation, qreal)
0101 
0102 
0103 QImage VideoWidget::snapshot() const {
0104     P_D(const VideoWidget);
0105     ConstIface<IFACES4> iface(d);
0106     if(iface) return iface->snapshot();
0107     return QImage(); // TODO not implemented in VideoInterface
0108 }
0109 
0110 
0111 void VideoWidget::setFullScreen(bool newFullScreen)
0112 {
0113     pDebug() << Q_FUNC_INFO << newFullScreen;
0114     P_D(VideoWidget);
0115     // TODO: disable screensaver? or should we leave that responsibility to the
0116     // application?
0117     Qt::WindowFlags flags = windowFlags();
0118     if (newFullScreen) {
0119         if (!isFullScreen()) {
0120             //we only update that value if it is not already fullscreen
0121             d->changeFlags = flags & (Qt::Window | Qt::SubWindow);
0122             flags |= Qt::Window;
0123             flags ^= Qt::SubWindow;
0124             setWindowFlags(flags);
0125 #ifdef Q_WS_X11
0126             // This works around a bug with Compiz
0127             // as the window must be visible before we can set the state
0128             show();
0129             raise();
0130             setWindowState( windowState() | Qt::WindowFullScreen ); // set
0131 #else
0132             setWindowState( windowState() | Qt::WindowFullScreen ); // set
0133             show();
0134 #endif
0135         }
0136     } else if (isFullScreen()) {
0137         flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
0138         flags |= d->changeFlags; //then we reset the flags (window and subwindow)
0139         setWindowFlags(flags);
0140         setWindowState( windowState()  ^ Qt::WindowFullScreen ); // reset
0141         show();
0142     }
0143 }
0144 
0145 void VideoWidget::exitFullScreen()
0146 {
0147     setFullScreen(false);
0148 }
0149 
0150 void VideoWidget::enterFullScreen()
0151 {
0152     setFullScreen(true);
0153 }
0154 
0155 bool VideoWidgetPrivate::aboutToDeleteBackendObject()
0156 {
0157     aspectRatio = pINTERFACE_CALL(aspectRatio());
0158     scaleMode = pINTERFACE_CALL(scaleMode());
0159     return AbstractVideoOutputPrivate::aboutToDeleteBackendObject();
0160 }
0161 
0162 void VideoWidgetPrivate::setupBackendObject()
0163 {
0164     P_Q(VideoWidget);
0165     Q_ASSERT(m_backendObject);
0166     //AbstractVideoOutputPrivate::setupBackendObject();
0167     pDebug() << "calling setAspectRatio on the backend " << aspectRatio;
0168     pINTERFACE_CALL(setAspectRatio(aspectRatio));
0169     pINTERFACE_CALL(setScaleMode(scaleMode));
0170 
0171     QWidget *w = pINTERFACE_CALL(widget());
0172     if (w) {
0173         layout.addWidget(w);
0174         q->setSizePolicy(w->sizePolicy());
0175         w->setMouseTracking(true);
0176     }
0177 }
0178 
0179 bool VideoWidget::event(QEvent *e)
0180 {
0181     return QWidget::event(e);
0182 }
0183 
0184 } //namespace Phonon
0185 
0186 #endif //QT_NO_PHONON_VIDEO
0187 
0188 #include "moc_videowidget.cpp"
0189 
0190 #undef PHONON_CLASSNAME
0191 // vim: sw=4 ts=4 tw=80