qtmobility/plugins/multimedia/qt7/qt7movieviewoutput.mm
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 
       
    52 QTM_USE_NAMESPACE
       
    53 
       
    54 #define VIDEO_TRANSPARENT(m) -(void)m:(NSEvent *)e{[[self superview] m:e];}
       
    55 
       
    56 @interface TransparentQTMovieView : QTMovieView
       
    57 {
       
    58 @private
       
    59     QRect *m_drawRect;
       
    60     qreal m_brightness, m_contrast, m_saturation, m_hue;
       
    61 }
       
    62 
       
    63 - (TransparentQTMovieView *) init;
       
    64 - (void) setDrawRect:(QRect &)rect;
       
    65 - (void) setContrast:(qreal) contrast;
       
    66 @end
       
    67 
       
    68 @implementation TransparentQTMovieView
       
    69 
       
    70 - (TransparentQTMovieView *) init
       
    71 {
       
    72     self = [super initWithFrame:NSZeroRect];
       
    73     if (self) {
       
    74         [self setControllerVisible:NO];
       
    75         [self setContrast:1.0];
       
    76         [self setDelegate:self];
       
    77     }
       
    78     return self;
       
    79 }
       
    80 
       
    81 - (void) dealloc
       
    82 {
       
    83     [super dealloc];
       
    84 }
       
    85 
       
    86 - (void) setContrast:(qreal) contrast
       
    87 {
       
    88     m_hue = 0.0;
       
    89     m_brightness = 0.0;
       
    90     m_contrast = contrast;
       
    91     m_saturation = 1.0;
       
    92 }
       
    93 
       
    94 
       
    95 - (void) setDrawRect:(QRect &)rect
       
    96 {
       
    97     *m_drawRect = rect;
       
    98 
       
    99     NSRect nsrect;
       
   100     nsrect.origin.x = m_drawRect->x();
       
   101     nsrect.origin.y = m_drawRect->y();
       
   102     nsrect.size.width = m_drawRect->width();
       
   103     nsrect.size.height = m_drawRect->height();
       
   104     [self setFrame:nsrect];
       
   105 }
       
   106 
       
   107 - (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img
       
   108 {
       
   109     // This method is called from QTMovieView just
       
   110     // before the image will be drawn.
       
   111     Q_UNUSED(view);
       
   112 
       
   113     if ( !qFuzzyCompare(m_brightness, 0.0) ||
       
   114          !qFuzzyCompare(m_contrast, 1.0) ||
       
   115          !qFuzzyCompare(m_saturation, 1.0)){
       
   116         CIFilter *colorFilter = [CIFilter filterWithName:@"CIColorControls"];
       
   117         [colorFilter setValue:[NSNumber numberWithFloat:m_brightness] forKey:@"inputBrightness"];
       
   118         [colorFilter setValue:[NSNumber numberWithFloat:(m_contrast < 1) ? m_contrast : 1 + ((m_contrast-1)*3)] forKey:@"inputContrast"];
       
   119         [colorFilter setValue:[NSNumber numberWithFloat:m_saturation] forKey:@"inputSaturation"];
       
   120         [colorFilter setValue:img forKey:@"inputImage"];
       
   121         img = [colorFilter valueForKey:@"outputImage"];
       
   122     }
       
   123 
       
   124     /*if (m_hue){
       
   125         CIFilter *colorFilter = [CIFilter filterWithName:@"CIHueAdjust"];
       
   126         [colorFilter setValue:[NSNumber numberWithFloat:(m_hue * 3.14)] forKey:@"inputAngle"];
       
   127         [colorFilter setValue:img forKey:@"inputImage"];
       
   128         img = [colorFilter valueForKey:@"outputImage"];
       
   129     }*/
       
   130 
       
   131     return img;
       
   132 }
       
   133 
       
   134 
       
   135 VIDEO_TRANSPARENT(mouseDown);
       
   136 VIDEO_TRANSPARENT(mouseDragged);
       
   137 VIDEO_TRANSPARENT(mouseUp);
       
   138 VIDEO_TRANSPARENT(mouseMoved);
       
   139 VIDEO_TRANSPARENT(mouseEntered);
       
   140 VIDEO_TRANSPARENT(mouseExited);
       
   141 VIDEO_TRANSPARENT(rightMouseDown);
       
   142 VIDEO_TRANSPARENT(rightMouseDragged);
       
   143 VIDEO_TRANSPARENT(rightMouseUp);
       
   144 VIDEO_TRANSPARENT(otherMouseDown);
       
   145 VIDEO_TRANSPARENT(otherMouseDragged);
       
   146 VIDEO_TRANSPARENT(otherMouseUp);
       
   147 VIDEO_TRANSPARENT(keyDown);
       
   148 VIDEO_TRANSPARENT(keyUp);
       
   149 VIDEO_TRANSPARENT(scrollWheel)
       
   150 
       
   151 @end
       
   152 
       
   153 
       
   154 QT7MovieViewOutput::QT7MovieViewOutput(QObject *parent)
       
   155    :QT7VideoWindowControl(parent),
       
   156     m_movie(0),
       
   157     m_movieView(0),
       
   158     m_winId(0),
       
   159     m_fullscreen(false),
       
   160     m_aspectRatioMode(QVideoWidget::KeepAspectRatio),
       
   161     m_brightness(0),
       
   162     m_contrast(0),
       
   163     m_hue(0),
       
   164     m_saturation(0)
       
   165 {    
       
   166 }
       
   167 
       
   168 QT7MovieViewOutput::~QT7MovieViewOutput()
       
   169 {
       
   170 }
       
   171 
       
   172 void QT7MovieViewOutput::setupVideoOutput()
       
   173 {
       
   174     AutoReleasePool pool;
       
   175 
       
   176     //qDebug() << "QT7MovieViewOutput::setupVideoOutput" << m_movie << m_winId;
       
   177     if (m_movie == 0 || m_winId <= 0)
       
   178         return;
       
   179 
       
   180     NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieCurrentSizeAttribute"] sizeValue];
       
   181     m_nativeSize = QSize(size.width, size.height);
       
   182 
       
   183     if (!m_movieView)
       
   184         m_movieView = [[TransparentQTMovieView alloc] init];
       
   185 
       
   186     [(QTMovieView*)m_movieView setControllerVisible:NO];
       
   187     [(QTMovieView*)m_movieView setMovie:(QTMovie*)m_movie];
       
   188 
       
   189     [(NSView *)m_winId addSubview:(QTMovieView*)m_movieView];
       
   190 
       
   191     setDisplayRect(m_displayRect);
       
   192 }
       
   193 
       
   194 void QT7MovieViewOutput::setEnabled(bool)
       
   195 {
       
   196 }
       
   197 
       
   198 void QT7MovieViewOutput::setMovie(void *movie)
       
   199 {
       
   200     m_movie = movie;
       
   201     setupVideoOutput();
       
   202 }
       
   203 
       
   204 WId QT7MovieViewOutput::winId() const
       
   205 {
       
   206     return m_winId;
       
   207 }
       
   208 
       
   209 void QT7MovieViewOutput::setWinId(WId id)
       
   210 {
       
   211     m_winId = id;
       
   212     setupVideoOutput();
       
   213 }
       
   214 
       
   215 QRect QT7MovieViewOutput::displayRect() const
       
   216 {
       
   217     return m_displayRect;
       
   218 }
       
   219 
       
   220 void QT7MovieViewOutput::setDisplayRect(const QRect &rect)
       
   221 {
       
   222     m_displayRect = rect;
       
   223 
       
   224     if (m_movieView) {
       
   225         AutoReleasePool pool;
       
   226         [(QTMovieView*)m_movieView setPreservesAspectRatio:(m_aspectRatioMode == QVideoWidget::KeepAspectRatio ? YES : NO)];
       
   227         [(QTMovieView*)m_movieView setFrame:NSMakeRect(m_displayRect.x(),
       
   228                                                        m_displayRect.y(),
       
   229                                                        m_displayRect.width(),
       
   230                                                        m_displayRect.height())];
       
   231      }
       
   232 
       
   233 }
       
   234 
       
   235 bool QT7MovieViewOutput::isFullScreen() const
       
   236 {
       
   237     return m_fullscreen;
       
   238 }
       
   239 
       
   240 void QT7MovieViewOutput::setFullScreen(bool fullScreen)
       
   241 {
       
   242     m_fullscreen = fullScreen;
       
   243     setDisplayRect(m_displayRect);
       
   244 }
       
   245 
       
   246 void QT7MovieViewOutput::repaint()
       
   247 {
       
   248 }
       
   249 
       
   250 QSize QT7MovieViewOutput::nativeSize() const
       
   251 {
       
   252     return m_nativeSize;
       
   253 }
       
   254 
       
   255 QVideoWidget::AspectRatioMode QT7MovieViewOutput::aspectRatioMode() const
       
   256 {
       
   257     return m_aspectRatioMode;
       
   258 }
       
   259 
       
   260 void QT7MovieViewOutput::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
       
   261 {
       
   262     m_aspectRatioMode = mode;
       
   263     setDisplayRect(m_displayRect);
       
   264 }
       
   265 
       
   266 int QT7MovieViewOutput::brightness() const
       
   267 {
       
   268     return m_brightness;
       
   269 }
       
   270 
       
   271 void QT7MovieViewOutput::setBrightness(int brightness)
       
   272 {
       
   273     m_brightness = brightness;
       
   274 }
       
   275 
       
   276 int QT7MovieViewOutput::contrast() const
       
   277 {
       
   278     return m_contrast;
       
   279 }
       
   280 
       
   281 void QT7MovieViewOutput::setContrast(int contrast)
       
   282 {
       
   283     m_contrast = contrast;
       
   284     [(TransparentQTMovieView*)m_movieView setContrast:(contrast/100.0+1.0)];
       
   285 }
       
   286 
       
   287 int QT7MovieViewOutput::hue() const
       
   288 {
       
   289     return m_hue;
       
   290 }
       
   291 
       
   292 void QT7MovieViewOutput::setHue(int hue)
       
   293 {
       
   294     m_hue = hue;
       
   295 }
       
   296 
       
   297 int QT7MovieViewOutput::saturation() const
       
   298 {
       
   299     return m_saturation;
       
   300 }
       
   301 
       
   302 void QT7MovieViewOutput::setSaturation(int saturation)
       
   303 {
       
   304     m_saturation = saturation;
       
   305 }
       
   306