[B][U]SelectFile.cpp[/U][/B]
void SelectFile::init()
{
connect(btn_SelectFile,SIGNAL(clicked()),this,SLOT(chooseMovie()));
}
void SelectFile::chooseMovie()
{
EnterMovies();
if(movieWindow==NULL)
Window *movieWindow = new Window(0);
connect(this,
SIGNAL(movieChosen
(QString)),movieWindow,
SLOT(OpenMovie
(QString)));
emit movieChosen(TmpStr);
movieWindow->exec();
ExitMovies();
}
[B][U]window.cpp[/U][/B]
{
setupUi(this);
movieWidget = new MovieWidget(this);
connect(this,
SIGNAL(movieChoose
(QString)),movieWidget,
SLOT(loadMovie
(QString)));
connect(movieWidget, SIGNAL(optimalSizeChange()),this, SLOT(updateSizes()));
connect(movieWidget, SIGNAL(NoPreview()),this, SIGNAL(NoPreviewAvailable()));
connect(btn_close, SIGNAL(clicked()), this, SLOT(Close()));
layout()->addWidget(movieWidget);
}
Window::~Window()
{
}
void Window::Close()
{
connect(this, SIGNAL(DisposeCurrentMovie()),movieWidget,SLOT(dispose()));
close();
}
void Window
:: OpenMovie(QString bMovieName
) {
emit movieChoose(bMovieName);
}
void Window::updateSizes()
{
adjustSize();
}
[B][U]moviewidget.cpp
[/U][/B]
#include "moviewidget.h"
#include <QtGui/QLayout>
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
MovieWidget
::MovieWidget(QWidget *parent
){
HIViewRef movieView;
HIObjectCreate(kHIMovieViewClassID, 0, reinterpret_cast<HIObjectRef*>(&movieView));
HIMovieViewChangeAttributes(movieView,
kHIMovieViewAutoIdlingAttribute | kHIMovieViewControllerVisibleAttribute, 0);
create(WId(movieView));
}
MovieWidget::~MovieWidget()
{
if (currentMovie)
DisposeMovie(currentMovie);
}
void MovieWidget::dispose()
{
if (currentMovie)
DisposeMovie(currentMovie);
}
void MovieWidget
::loadMovie(const QString &fileName
) {
QTVisualContextRef visualContext = 0;
Boolean active = true;
DataReferenceRecord dataRef;
Movie oldMovie = 0;
// create an array of properties for NewMovieFromProperties
// these properties describe how to create the new movie
// see Movies.h for the full list of available properties
QTNewMoviePropertyElement newMovieProperties[] = {
{kQTPropertyClass_DataLocation, kQTDataLocationPropertyID_DataReference, sizeof(dataRef), &dataRef, 0},
{kQTPropertyClass_NewMovieProperty, kQTNewMoviePropertyID_Active, sizeof(active), &active, 0},
{kQTPropertyClass_Context, kQTContextPropertyID_VisualContext, sizeof(visualContext), &visualContext, 0},
};
CFStringRef cfString = CFStringCreateWithCharacters(0,
reinterpret_cast<const UniChar *>(fileName.unicode()),
fileName.length());
QTNewDataReferenceFromFullPathCFString(cfString, kQTPOSIXPathStyle, 0, &dataRef.dataRef, &dataRef.dataRefType);
CFRelease(cfString);
// if there's an old movie save it so we can dispose of it if
// we load up a new movie successfully
oldMovie = currentMovie;
currentMovie = 0;
// create a new movie using movie properties
// when calling this function, you supply a set of input properties that describe the information
// required to instantiate the movie (its data reference, audio context, visual context, and so on)
NewMovieFromProperties(sizeof(newMovieProperties) / sizeof(newMovieProperties[0]), // the number of properties in the array passed in inputProperties
newMovieProperties, // a pointer to a property array describing how to instantiate the movie
0, // number of properties in the array passed in outputProperties
0, // pointer to a property array to receive output parameters - 0 if you don’t want this information
¤tMovie); // pointer to a variable that receives the new movie
// make sure to dispose of the dataRef we no longer need it
DisposeHandle(dataRef.dataRef);
// set the HIMovieView's current movie
HIMovieViewSetMovie(HIViewRef(winId()), currentMovie);
if (oldMovie != 0)
DisposeMovie(oldMovie);
if(currentMovie == 0)
emit NoPreview();
// new movie has a new size, need to update.
updateGeometry();
emit optimalSizeChange();
}
QSize MovieWidget
::sizeHint() const {
EventRef event;
HIRect optimalBounds;
CreateEvent(0, kEventClassControl, kEventControlGetOptimalBounds,
GetCurrentEventTime(), kEventAttributeUserEvent, &event);
SendEventToEventTargetWithOptions(event,
HIObjectGetEventTarget(HIObjectRef(winId())),
kEventTargetDontPropagate);
GetEventParameter(event, kEventParamControlOptimalBounds, typeHIRect,
0, sizeof(HIRect), 0, &optimalBounds);
ReleaseEvent(event);
return QSize(optimalBounds.
size.
width, optimalBounds.
size.
height);
}
bool MovieWidget::nativeControlsVisible() const
{
OptionBits currentBits = HIMovieViewGetAttributes(HIViewRef(winId()));
return currentBits & kHIMovieViewControllerVisibleAttribute;
}
void MovieWidget::setNativeControlsVisible(bool visible)
{
if (visible != nativeControlsVisible()) {
HIMovieViewChangeAttributes(HIViewRef(winId()),
visible ? kHIMovieViewControllerVisibleAttribute : 0,
!visible ? kHIMovieViewControllerVisibleAttribute : 0);
updateGeometry();
emit optimalSizeChange();
}
}
[B][U]SelectFile.cpp[/U][/B]
void SelectFile::init()
{
connect(btn_SelectFile,SIGNAL(clicked()),this,SLOT(chooseMovie()));
}
void SelectFile::chooseMovie()
{
QString TmpStr = QFileDialog::getOpenFileName(this);
EnterMovies();
if(movieWindow==NULL)
Window *movieWindow = new Window(0);
connect(this,SIGNAL(movieChosen(QString)),movieWindow,SLOT(OpenMovie(QString)));
emit movieChosen(TmpStr);
movieWindow->exec();
ExitMovies();
}
[B][U]window.cpp[/U][/B]
Window::Window(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
movieWidget = new MovieWidget(this);
connect(this, SIGNAL(movieChoose(QString)),movieWidget,SLOT(loadMovie (QString)));
connect(movieWidget, SIGNAL(optimalSizeChange()),this, SLOT(updateSizes()));
connect(movieWidget, SIGNAL(NoPreview()),this, SIGNAL(NoPreviewAvailable()));
connect(btn_close, SIGNAL(clicked()), this, SLOT(Close()));
layout()->addWidget(movieWidget);
}
Window::~Window()
{
}
void Window::Close()
{
connect(this, SIGNAL(DisposeCurrentMovie()),movieWidget,SLOT(dispose()));
close();
}
void Window :: OpenMovie(QString bMovieName)
{
emit movieChoose(bMovieName);
}
void Window::updateSizes()
{
adjustSize();
}
[B][U]moviewidget.cpp
[/U][/B]
#include "moviewidget.h"
#include <QtGui/QLayout>
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
MovieWidget::MovieWidget(QWidget *parent)
: QWidget(parent), currentMovie(0)
{
HIViewRef movieView;
HIObjectCreate(kHIMovieViewClassID, 0, reinterpret_cast<HIObjectRef*>(&movieView));
HIMovieViewChangeAttributes(movieView,
kHIMovieViewAutoIdlingAttribute | kHIMovieViewControllerVisibleAttribute, 0);
create(WId(movieView));
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}
MovieWidget::~MovieWidget()
{
if (currentMovie)
DisposeMovie(currentMovie);
}
void MovieWidget::dispose()
{
if (currentMovie)
DisposeMovie(currentMovie);
}
void MovieWidget::loadMovie(const QString &fileName)
{
QTVisualContextRef visualContext = 0;
Boolean active = true;
DataReferenceRecord dataRef;
Movie oldMovie = 0;
// create an array of properties for NewMovieFromProperties
// these properties describe how to create the new movie
// see Movies.h for the full list of available properties
QTNewMoviePropertyElement newMovieProperties[] = {
{kQTPropertyClass_DataLocation, kQTDataLocationPropertyID_DataReference, sizeof(dataRef), &dataRef, 0},
{kQTPropertyClass_NewMovieProperty, kQTNewMoviePropertyID_Active, sizeof(active), &active, 0},
{kQTPropertyClass_Context, kQTContextPropertyID_VisualContext, sizeof(visualContext), &visualContext, 0},
};
CFStringRef cfString = CFStringCreateWithCharacters(0,
reinterpret_cast<const UniChar *>(fileName.unicode()),
fileName.length());
QTNewDataReferenceFromFullPathCFString(cfString, kQTPOSIXPathStyle, 0, &dataRef.dataRef, &dataRef.dataRefType);
CFRelease(cfString);
// if there's an old movie save it so we can dispose of it if
// we load up a new movie successfully
oldMovie = currentMovie;
currentMovie = 0;
// create a new movie using movie properties
// when calling this function, you supply a set of input properties that describe the information
// required to instantiate the movie (its data reference, audio context, visual context, and so on)
NewMovieFromProperties(sizeof(newMovieProperties) / sizeof(newMovieProperties[0]), // the number of properties in the array passed in inputProperties
newMovieProperties, // a pointer to a property array describing how to instantiate the movie
0, // number of properties in the array passed in outputProperties
0, // pointer to a property array to receive output parameters - 0 if you don’t want this information
¤tMovie); // pointer to a variable that receives the new movie
// make sure to dispose of the dataRef we no longer need it
DisposeHandle(dataRef.dataRef);
// set the HIMovieView's current movie
HIMovieViewSetMovie(HIViewRef(winId()), currentMovie);
if (oldMovie != 0)
DisposeMovie(oldMovie);
if(currentMovie == 0)
emit NoPreview();
// new movie has a new size, need to update.
updateGeometry();
emit optimalSizeChange();
}
QSize MovieWidget::sizeHint() const
{
EventRef event;
HIRect optimalBounds;
CreateEvent(0, kEventClassControl, kEventControlGetOptimalBounds,
GetCurrentEventTime(), kEventAttributeUserEvent, &event);
SendEventToEventTargetWithOptions(event,
HIObjectGetEventTarget(HIObjectRef(winId())),
kEventTargetDontPropagate);
GetEventParameter(event, kEventParamControlOptimalBounds, typeHIRect,
0, sizeof(HIRect), 0, &optimalBounds);
ReleaseEvent(event);
return QSize(optimalBounds.size.width, optimalBounds.size.height);
}
bool MovieWidget::nativeControlsVisible() const
{
OptionBits currentBits = HIMovieViewGetAttributes(HIViewRef(winId()));
return currentBits & kHIMovieViewControllerVisibleAttribute;
}
void MovieWidget::setNativeControlsVisible(bool visible)
{
if (visible != nativeControlsVisible()) {
HIMovieViewChangeAttributes(HIViewRef(winId()),
visible ? kHIMovieViewControllerVisibleAttribute : 0,
!visible ? kHIMovieViewControllerVisibleAttribute : 0);
updateGeometry();
emit optimalSizeChange();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks