From e9850033b89c7ef5a24a9690d47584729b416eed Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 25 Mar 2011 18:29:26 +0530 Subject: [PATCH] RenderWidget: A clever implementation of video rendering widget --- src/Gui/preview/RenderWidget.h | 63 +++++++++++++++++++++ src/Gui/preview/RenderWidget.mm | 99 +++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 src/Gui/preview/RenderWidget.h create mode 100644 src/Gui/preview/RenderWidget.mm diff --git a/src/Gui/preview/RenderWidget.h b/src/Gui/preview/RenderWidget.h new file mode 100644 index 000000000..c14d55ba2 --- /dev/null +++ b/src/Gui/preview/RenderWidget.h @@ -0,0 +1,63 @@ +/***************************************************************************** + * RenderWidget: Vout render widget + ***************************************************************************** + * Copyright (C) 2008-2011 VideoLAN + * + * Authors: Rohit Yadav + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef RENDERWIDGET_H +#define RENDERWIDGET_H + +#include +#include + +#if defined( Q_WS_MAC ) && defined( QT_MAC_USE_COCOA ) +#include + +#ifdef __OBJC__ +#define ADD_COCOA_NATIVE_REF(CocoaClass) \ + @class CocoaClass; \ + typedef CocoaClass *Native##CocoaClass##Ref +#else +#define ADD_COCOA_NATIVE_REF(CocoaClass) typedef void *Native##CocoaClass##Ref +#endif + +ADD_COCOA_NATIVE_REF(NSView); +#endif + +class RenderWidget : public QWidget +{ + Q_OBJECT + +public: +#if defined( Q_WS_MAC ) && defined( QT_MAC_USE_COCOA ) + RenderWidget( QWidget* parent = NULL ); + NativeNSViewRef id() const; + void release(); + +private: + NativeNSViewRef m_video; + QMacCocoaViewContainer* m_container; +#else + RenderWidget( QWidget* parent = NULL ) + : QWidget (parent) {}; + WId id() const { return winId; }; +#endif +}; + +#endif // RENDERWIDGET_H diff --git a/src/Gui/preview/RenderWidget.mm b/src/Gui/preview/RenderWidget.mm new file mode 100644 index 000000000..23996d77f --- /dev/null +++ b/src/Gui/preview/RenderWidget.mm @@ -0,0 +1,99 @@ +/***************************************************************************** + * RenderWidget.mm: A NSView Vout render widget for Mac OS + ***************************************************************************** + * Copyright (C) 2008-2011 VideoLAN + * + * Authors: Rohit Yadav + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include +#if defined( Q_WS_MAC ) && defined( QT_MAC_USE_COCOA ) + +#include "RenderWidget.h" +#include +#include +#include + +#import +#import +#import + +@interface VLCNSView : NSView +BOOL stretchesVideo; +- ( void ) setStretchesVideo : ( BOOL ) value; +- ( BOOL ) stretchesVideo; +- ( void ) addVoutSubview:( NSView * ) aView; +- ( void ) removeVoutSubview:( NSView * ) aView; +@end + +@implementation VLCNSView +- ( id ) initWithFrame:( NSRect ) frameRect +{ + if ((self = [super initWithFrame:frameRect]) == nil){ return nil; } + return self; +} +- ( void ) dealloc +{ + [super dealloc]; +} +- ( void ) setStretchesVideo : ( BOOL ) value +{ + stretchesVideo = value; +} +- ( BOOL ) stretchesVideo +{ + return stretchesVideo; +} +- ( void ) addVoutSubview:( NSView * ) aView +{ + [aView setFrame:[self bounds]]; + [self addSubview:aView]; + [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; +} +- (void) removeVoutSubview:(NSView *)aView {} +@end + +RenderWidget::RenderWidget( QWidget *parent ) : + QWidget( parent ) +{ + m_video = [[VLCNSView alloc] init]; + m_container = new QMacCocoaViewContainer( m_video, this ); + m_container->setAutoFillBackground( true ); + + QPalette videoPalette = m_container->palette(); + videoPalette.setColor( QPalette::Window, QColor( Qt::black ) ); + m_container->setPalette( videoPalette ); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget( m_container ); + setLayout( layout ); +} + +/* winId should return pointer to the NSView, m_video */ +NativeNSViewRef +RenderWidget::id() const +{ + return m_video; +} + +void +RenderWidget::release() +{ + [m_video release]; +} + +#endif -- GitLab