plugins/multimedia/qt7/qt7movieviewoutput.mm
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #import <QTKit/QTkit.h>
       
    43 
       
    44 #include "qt7backend.h"
       
    45 
       
    46 #include "qt7playercontrol.h"
       
    47 #include "qt7movieviewoutput.h"
       
    48 #include "qt7playersession.h"
       
    49 #include <QtCore/qdebug.h>
       
    50 
       
    51 #include <QuartzCore/CIFilter.h>
       
    52 #include <QuartzCore/CIVector.h>
       
    53 
       
    54 QT_USE_NAMESPACE
       
    55 
       
    56 #define VIDEO_TRANSPARENT(m) -(void)m:(NSEvent *)e{[[self superview] m:e];}
       
    57 
       
    58 @interface TransparentQTMovieView : QTMovieView
       
    59 {
       
    60 @private
       
    61     QRect *m_drawRect;
       
    62     qreal m_brightness, m_contrast, m_saturation, m_hue;
       
    63 }
       
    64 
       
    65 - (TransparentQTMovieView *) init;
       
    66 - (void) setDrawRect:(QRect &)rect;
       
    67 - (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img;
       
    68 - (void) setContrast:(qreal) contrast;
       
    69 @end
       
    70 
       
    71 @implementation TransparentQTMovieView
       
    72 
       
    73 - (TransparentQTMovieView *) init
       
    74 {
       
    75     self = [super initWithFrame:NSZeroRect];
       
    76     if (self) {
       
    77         [self setControllerVisible:NO];
       
    78         [self setContrast:1.0];
       
    79         [self setDelegate:self];
       
    80     }
       
    81     return self;
       
    82 }
       
    83 
       
    84 - (void) dealloc
       
    85 {
       
    86     [super dealloc];
       
    87 }
       
    88 
       
    89 - (void) setContrast:(qreal) contrast
       
    90 {
       
    91     m_hue = 0.0;
       
    92     m_brightness = 0.0;
       
    93     m_contrast = contrast;
       
    94     m_saturation = 1.0;
       
    95 }
       
    96 
       
    97 
       
    98 - (void) setDrawRect:(QRect &)rect
       
    99 {
       
   100     *m_drawRect = rect;
       
   101 
       
   102     NSRect nsrect;
       
   103     nsrect.origin.x = m_drawRect->x();
       
   104     nsrect.origin.y = m_drawRect->y();
       
   105     nsrect.size.width = m_drawRect->width();
       
   106     nsrect.size.height = m_drawRect->height();
       
   107     [self setFrame:nsrect];
       
   108 }
       
   109 
       
   110 - (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img
       
   111 {
       
   112     // This method is called from QTMovieView just
       
   113     // before the image will be drawn.
       
   114     Q_UNUSED(view);
       
   115 
       
   116     if ( !qFuzzyCompare(m_brightness, 0.0) ||
       
   117          !qFuzzyCompare(m_contrast, 1.0) ||
       
   118          !qFuzzyCompare(m_saturation, 1.0)){
       
   119         CIFilter *colorFilter = [CIFilter filterWithName:@"CIColorControls"];
       
   120         [colorFilter setValue:[NSNumber numberWithFloat:m_brightness] forKey:@"inputBrightness"];
       
   121         [colorFilter setValue:[NSNumber numberWithFloat:(m_contrast < 1) ? m_contrast : 1 + ((m_contrast-1)*3)] forKey:@"inputContrast"];
       
   122         [colorFilter setValue:[NSNumber numberWithFloat:m_saturation] forKey:@"inputSaturation"];
       
   123         [colorFilter setValue:img forKey:@"inputImage"];
       
   124         img = [colorFilter valueForKey:@"outputImage"];
       
   125     }
       
   126 
       
   127     /*if (m_hue){
       
   128         CIFilter *colorFilter = [CIFilter filterWithName:@"CIHueAdjust"];
       
   129         [colorFilter setValue:[NSNumber numberWithFloat:(m_hue * 3.14)] forKey:@"inputAngle"];
       
   130         [colorFilter setValue:img forKey:@"inputImage"];
       
   131         img = [colorFilter valueForKey:@"outputImage"];
       
   132     }*/
       
   133 
       
   134     return img;
       
   135 }
       
   136 
       
   137 
       
   138 VIDEO_TRANSPARENT(mouseDown);
       
   139 VIDEO_TRANSPARENT(mouseDragged);
       
   140 VIDEO_TRANSPARENT(mouseUp);
       
   141 VIDEO_TRANSPARENT(mouseMoved);
       
   142 VIDEO_TRANSPARENT(mouseEntered);
       
   143 VIDEO_TRANSPARENT(mouseExited);
       
   144 VIDEO_TRANSPARENT(rightMouseDown);
       
   145 VIDEO_TRANSPARENT(rightMouseDragged);
       
   146 VIDEO_TRANSPARENT(rightMouseUp);
       
   147 VIDEO_TRANSPARENT(otherMouseDown);
       
   148 VIDEO_TRANSPARENT(otherMouseDragged);
       
   149 VIDEO_TRANSPARENT(otherMouseUp);
       
   150 VIDEO_TRANSPARENT(keyDown);
       
   151 VIDEO_TRANSPARENT(keyUp);
       
   152 VIDEO_TRANSPARENT(scrollWheel)
       
   153 
       
   154 @end
       
   155 
       
   156 
       
   157 QT7MovieViewOutput::QT7MovieViewOutput(QObject *parent)
       
   158    :QT7VideoWindowControl(parent),
       
   159     m_movie(0),
       
   160     m_movieView(0),
       
   161     m_layouted(false),
       
   162     m_winId(0),
       
   163     m_fullscreen(false),
       
   164     m_aspectRatioMode(Qt::KeepAspectRatio),
       
   165     m_brightness(0),
       
   166     m_contrast(0),
       
   167     m_hue(0),
       
   168     m_saturation(0)
       
   169 {    
       
   170 }
       
   171 
       
   172 QT7MovieViewOutput::~QT7MovieViewOutput()
       
   173 {
       
   174     [(QTMovieView*)m_movieView release];
       
   175     [(QTMovie*)m_movie release];
       
   176 }
       
   177 
       
   178 void QT7MovieViewOutput::setupVideoOutput()
       
   179 {
       
   180     AutoReleasePool pool;
       
   181 
       
   182 #ifdef QT_DEBUG_QT7
       
   183     qDebug() << "QT7MovieViewOutput::setupVideoOutput" << m_movie << m_winId;
       
   184 #endif
       
   185     if (m_movie == 0 || m_winId <= 0)
       
   186         return;
       
   187 
       
   188     NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue];
       
   189     m_nativeSize = QSize(size.width, size.height);
       
   190 
       
   191     if (!m_movieView)
       
   192         m_movieView = [[TransparentQTMovieView alloc] init];
       
   193 
       
   194     [(QTMovieView*)m_movieView setControllerVisible:NO];
       
   195     [(QTMovieView*)m_movieView setMovie:(QTMovie*)m_movie];
       
   196 
       
   197     [(NSView *)m_winId addSubview:(QTMovieView*)m_movieView];
       
   198     m_layouted = true;
       
   199 
       
   200     setDisplayRect(m_displayRect);
       
   201 }
       
   202 
       
   203 void QT7MovieViewOutput::setMovie(void *movie)
       
   204 {
       
   205     if (m_movie != movie) {
       
   206         if (m_movie) {
       
   207             if (m_movieView)
       
   208                 [(QTMovieView*)m_movieView setMovie:nil];
       
   209 
       
   210             [(QTMovie*)m_movie release];
       
   211         }
       
   212 
       
   213         m_movie = movie;
       
   214 
       
   215         if (m_movie)
       
   216             [(QTMovie*)m_movie retain];
       
   217 
       
   218         setupVideoOutput();
       
   219     }
       
   220 }
       
   221 
       
   222 void QT7MovieViewOutput::updateNaturalSize(const QSize &newSize)
       
   223 {
       
   224     if (m_nativeSize != newSize) {
       
   225         m_nativeSize = newSize;
       
   226         emit nativeSizeChanged();
       
   227     }
       
   228 }
       
   229 
       
   230 WId QT7MovieViewOutput::winId() const
       
   231 {
       
   232     return m_winId;
       
   233 }
       
   234 
       
   235 void QT7MovieViewOutput::setWinId(WId id)
       
   236 {
       
   237     if (m_winId != id) {
       
   238         if (m_movieView && m_layouted) {
       
   239             [(QTMovieView*)m_movieView removeFromSuperview];
       
   240             m_layouted = false;
       
   241         }
       
   242 
       
   243         m_winId = id;
       
   244         setupVideoOutput();
       
   245     }
       
   246 }
       
   247 
       
   248 QRect QT7MovieViewOutput::displayRect() const
       
   249 {
       
   250     return m_displayRect;
       
   251 }
       
   252 
       
   253 void QT7MovieViewOutput::setDisplayRect(const QRect &rect)
       
   254 {
       
   255     m_displayRect = rect;
       
   256 
       
   257     if (m_movieView) {
       
   258         AutoReleasePool pool;
       
   259         [(QTMovieView*)m_movieView setPreservesAspectRatio:(m_aspectRatioMode == Qt::KeepAspectRatio ? YES : NO)];
       
   260         [(QTMovieView*)m_movieView setFrame:NSMakeRect(m_displayRect.x(),
       
   261                                                        m_displayRect.y(),
       
   262                                                        m_displayRect.width(),
       
   263                                                        m_displayRect.height())];
       
   264      }
       
   265 
       
   266 }
       
   267 
       
   268 bool QT7MovieViewOutput::isFullScreen() const
       
   269 {
       
   270     return m_fullscreen;
       
   271 }
       
   272 
       
   273 void QT7MovieViewOutput::setFullScreen(bool fullScreen)
       
   274 {
       
   275     m_fullscreen = fullScreen;
       
   276     setDisplayRect(m_displayRect);
       
   277 }
       
   278 
       
   279 void QT7MovieViewOutput::repaint()
       
   280 {
       
   281 }
       
   282 
       
   283 QSize QT7MovieViewOutput::nativeSize() const
       
   284 {
       
   285     return m_nativeSize;
       
   286 }
       
   287 
       
   288 Qt::AspectRatioMode QT7MovieViewOutput::aspectRatioMode() const
       
   289 {
       
   290     return m_aspectRatioMode;
       
   291 }
       
   292 
       
   293 void QT7MovieViewOutput::setAspectRatioMode(Qt::AspectRatioMode mode)
       
   294 {
       
   295     m_aspectRatioMode = mode;
       
   296     setDisplayRect(m_displayRect);
       
   297 }
       
   298 
       
   299 int QT7MovieViewOutput::brightness() const
       
   300 {
       
   301     return m_brightness;
       
   302 }
       
   303 
       
   304 void QT7MovieViewOutput::setBrightness(int brightness)
       
   305 {
       
   306     m_brightness = brightness;
       
   307 }
       
   308 
       
   309 int QT7MovieViewOutput::contrast() const
       
   310 {
       
   311     return m_contrast;
       
   312 }
       
   313 
       
   314 void QT7MovieViewOutput::setContrast(int contrast)
       
   315 {
       
   316     m_contrast = contrast;
       
   317     [(TransparentQTMovieView*)m_movieView setContrast:(contrast/100.0+1.0)];
       
   318 }
       
   319 
       
   320 int QT7MovieViewOutput::hue() const
       
   321 {
       
   322     return m_hue;
       
   323 }
       
   324 
       
   325 void QT7MovieViewOutput::setHue(int hue)
       
   326 {
       
   327     m_hue = hue;
       
   328 }
       
   329 
       
   330 int QT7MovieViewOutput::saturation() const
       
   331 {
       
   332     return m_saturation;
       
   333 }
       
   334 
       
   335 void QT7MovieViewOutput::setSaturation(int saturation)
       
   336 {
       
   337     m_saturation = saturation;
       
   338 }
       
   339