| 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 | |
| 37 | namespace Phonon |
| 38 | { |
| 39 | |
| 40 | VideoWidget::VideoWidget(QWidget *parent) |
| 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 | |
| 52 | VideoWidget::VideoWidget(VideoWidgetPrivate &dd, QWidget *parent) |
| 53 | : QWidget(parent), |
| 54 | Phonon::AbstractVideoOutput(dd) |
| 55 | { |
| 56 | P_D(VideoWidget); |
| 57 | d->init(); |
| 58 | } |
| 59 | |
| 60 | void VideoWidgetPrivate::init() |
| 61 | { |
| 62 | P_Q(VideoWidget); |
| 63 | changeFlags = q->windowFlags() & (Qt::SubWindow | Qt::Window); |
| 64 | } |
| 65 | |
| 66 | void VideoWidget::mouseMoveEvent(QMouseEvent *e) |
| 67 | { |
| 68 | QWidget::mouseMoveEvent(event: e); |
| 69 | } |
| 70 | |
| 71 | void VideoWidgetPrivate::createBackendObject() |
| 72 | { |
| 73 | if (m_backendObject) |
| 74 | return; |
| 75 | P_Q(VideoWidget); |
| 76 | m_backendObject = Factory::createVideoWidget(parent: q); |
| 77 | if (m_backendObject) { |
| 78 | setupBackendObject(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | #define PHONON_CLASSNAME VideoWidget |
| 83 | |
| 84 | PHONON_INTERFACE_GETTER(Phonon::VideoWidget::AspectRatio, aspectRatio, d->aspectRatio) |
| 85 | PHONON_INTERFACE_SETTER(setAspectRatio, aspectRatio, Phonon::VideoWidget::AspectRatio) |
| 86 | |
| 87 | PHONON_INTERFACE_GETTER(Phonon::VideoWidget::ScaleMode, scaleMode, d->scaleMode) |
| 88 | PHONON_INTERFACE_SETTER(setScaleMode, scaleMode, Phonon::VideoWidget::ScaleMode) |
| 89 | |
| 90 | PHONON_INTERFACE_GETTER(qreal, brightness, d->brightness) |
| 91 | PHONON_INTERFACE_SETTER(setBrightness, brightness, qreal) |
| 92 | |
| 93 | PHONON_INTERFACE_GETTER(qreal, contrast, d->contrast) |
| 94 | PHONON_INTERFACE_SETTER(setContrast, contrast, qreal) |
| 95 | |
| 96 | PHONON_INTERFACE_GETTER(qreal, hue, d->hue) |
| 97 | PHONON_INTERFACE_SETTER(setHue, hue, qreal) |
| 98 | |
| 99 | PHONON_INTERFACE_GETTER(qreal, saturation, d->saturation) |
| 100 | PHONON_INTERFACE_SETTER(setSaturation, saturation, qreal) |
| 101 | |
| 102 | |
| 103 | QImage 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 | |
| 111 | void 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? |
| 117 | Qt::WindowFlags flags = windowFlags(); |
| 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(); |
| 130 | setWindowState( windowState() | Qt::WindowFullScreen ); // set |
| 131 | #else |
| 132 | setWindowState( windowState() | Qt::WindowFullScreen ); // set |
| 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); |
| 140 | setWindowState( windowState() ^ Qt::WindowFullScreen ); // reset |
| 141 | show(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void VideoWidget::exitFullScreen() |
| 146 | { |
| 147 | setFullScreen(false); |
| 148 | } |
| 149 | |
| 150 | void VideoWidget::enterFullScreen() |
| 151 | { |
| 152 | setFullScreen(true); |
| 153 | } |
| 154 | |
| 155 | bool VideoWidgetPrivate::aboutToDeleteBackendObject() |
| 156 | { |
| 157 | aspectRatio = pINTERFACE_CALL(aspectRatio()); |
| 158 | scaleMode = pINTERFACE_CALL(scaleMode()); |
| 159 | return AbstractVideoOutputPrivate::aboutToDeleteBackendObject(); |
| 160 | } |
| 161 | |
| 162 | void 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 | |
| 179 | bool VideoWidget::event(QEvent *e) |
| 180 | { |
| 181 | return QWidget::event(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 |
| 192 | |