2008-04-24 12:49:12 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
CMovieBox.cpp
|
|
|
|
|
2009-08-17 10:41:51 +00:00
|
|
|
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
|
2008-04-24 12:49:12 +00:00
|
|
|
|
|
|
|
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
|
2009-08-17 10:41:51 +00:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2008-04-24 12:49:12 +00:00
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __CMOVIEBOX_CPP
|
|
|
|
|
|
|
|
#include "gambas.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include <qmovie.h>
|
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
#include "CWidget.h"
|
|
|
|
#include "CMovieBox.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void free_movie(void *_object)
|
|
|
|
{
|
|
|
|
if (!THIS->movie)
|
|
|
|
return;
|
|
|
|
|
|
|
|
delete THIS->movie;
|
|
|
|
THIS->movie = 0;
|
2008-04-29 13:40:55 +00:00
|
|
|
THIS->ba->clear();
|
2008-04-24 12:49:12 +00:00
|
|
|
delete THIS->ba;
|
|
|
|
|
2008-12-28 22:41:55 +00:00
|
|
|
GB.ReleaseFile(THIS->addr, THIS->len);
|
2008-04-24 12:49:12 +00:00
|
|
|
|
|
|
|
GB.StoreString(NULL, &THIS->path);
|
2010-01-20 00:52:50 +00:00
|
|
|
|
|
|
|
if (WIDGET)
|
|
|
|
WIDGET->setText("");
|
2008-04-24 12:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool load_movie(void *_object, char *path, int len)
|
|
|
|
{
|
|
|
|
free_movie(THIS);
|
|
|
|
|
2010-01-20 00:52:50 +00:00
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
//qDebug("load_movie: %.*s", (int)len, path);
|
|
|
|
if (GB.LoadFile(path, len, &THIS->addr, &THIS->len))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
THIS->ba = new QByteArray();
|
|
|
|
THIS->ba->fromRawData((const char *)THIS->addr, THIS->len);
|
|
|
|
THIS->movie = new QMovie(*(THIS->ba));
|
|
|
|
|
|
|
|
GB.NewString(&THIS->path, path, len);
|
|
|
|
|
|
|
|
//qDebug("setMovie");
|
|
|
|
WIDGET->setMovie(THIS->movie);
|
|
|
|
}
|
2008-04-24 12:49:12 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD(CMOVIEBOX_new, GB_OBJECT parent)
|
|
|
|
|
|
|
|
QLabel *wid = new QLabel(QCONTAINER(VARG(parent)));
|
|
|
|
|
|
|
|
CWIDGET_new(wid, _object);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CMOVIEBOX_free)
|
|
|
|
|
|
|
|
free_movie(THIS);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CMOVIEBOX_path)
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
|
|
|
GB.ReturnString(THIS->path);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool playing = false;
|
|
|
|
|
|
|
|
if (THIS->movie)
|
2008-04-29 13:40:55 +00:00
|
|
|
playing = THIS->movie->state() == QMovie::Running;
|
2008-04-24 12:49:12 +00:00
|
|
|
else
|
|
|
|
playing = FALSE;
|
|
|
|
|
|
|
|
if (load_movie(THIS, PSTRING(), PLENGTH()))
|
|
|
|
return;
|
|
|
|
|
2010-01-20 00:52:50 +00:00
|
|
|
if (!playing && THIS->movie)
|
2008-04-29 13:40:55 +00:00
|
|
|
THIS->movie->setPaused(true);
|
2008-04-24 12:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CMOVIEBOX_playing)
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
2008-04-29 13:40:55 +00:00
|
|
|
GB.ReturnBoolean(THIS->movie ? THIS->movie->state() == QMovie::Running : FALSE);
|
2008-04-24 12:49:12 +00:00
|
|
|
else if (THIS->movie)
|
|
|
|
{
|
|
|
|
if (VPROP(GB_BOOLEAN))
|
2008-04-29 13:40:55 +00:00
|
|
|
THIS->movie->setPaused(false);
|
2008-04-24 12:49:12 +00:00
|
|
|
else
|
2008-04-29 13:40:55 +00:00
|
|
|
THIS->movie->setPaused(true);
|
2008-04-24 12:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CMOVIEBOX_rewind)
|
|
|
|
|
|
|
|
if (!THIS->movie)
|
|
|
|
return;
|
|
|
|
|
2008-04-29 13:40:55 +00:00
|
|
|
THIS->movie->stop();
|
|
|
|
THIS->movie->start();
|
2008-04-24 12:49:12 +00:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
GB_DESC CMovieBoxDesc[] =
|
|
|
|
{
|
|
|
|
GB_DECLARE("MovieBox", sizeof(CMOVIEBOX)), GB_INHERITS("Control"),
|
|
|
|
|
|
|
|
GB_METHOD("_new", NULL, CMOVIEBOX_new, "(Parent)Container;"),
|
|
|
|
GB_METHOD("_free", NULL, CMOVIEBOX_free, NULL),
|
|
|
|
|
|
|
|
GB_PROPERTY("Path", "s", CMOVIEBOX_path),
|
|
|
|
GB_PROPERTY("Playing", "b", CMOVIEBOX_playing),
|
|
|
|
//GB_PROPERTY("Alignment", "i<Align>", CMOVIEBOX_alignment),
|
|
|
|
GB_PROPERTY("Border", "i", CWIDGET_border_full),
|
|
|
|
|
|
|
|
GB_METHOD("Rewind", NULL, CMOVIEBOX_rewind, NULL),
|
|
|
|
|
|
|
|
MOVIEBOX_DESCRIPTION,
|
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
|
|
|
|