gambas-source-code/gb.qt4/src/CMovieBox.cpp
Benoît Minisini b3db598050 [DEVELOPMENT ENVIRONMENT]
* BUG: Breakpoints are correctly reset when opening a new project.

[INTERPRETER]
* BUG: The GB.NewString(), GB.NewZeroString() and GB.TempString() API 
  signature has changed. All components have been updated accordingly.
* OPT: Many optimizations to speed up the interpreter.

[GB.EVAL]
* NEW: During syntax highlighting, the first character of class names is
  automatically converted to uppercase.


git-svn-id: svn://localhost/gambas/trunk@2992 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-06-04 23:48:53 +00:00

161 lines
3.3 KiB
C++

/***************************************************************************
CMovieBox.cpp
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
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, 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., 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;
THIS->ba->clear();
delete THIS->ba;
GB.ReleaseFile(THIS->addr, THIS->len);
GB.StoreString(NULL, &THIS->path);
if (WIDGET)
WIDGET->setText("");
}
static bool load_movie(void *_object, char *path, int len)
{
free_movie(THIS);
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));
THIS->path = GB.NewString(path, len);
//qDebug("setMovie");
WIDGET->setMovie(THIS->movie);
}
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)
playing = THIS->movie->state() == QMovie::Running;
else
playing = FALSE;
if (load_movie(THIS, PSTRING(), PLENGTH()))
return;
if (!playing && THIS->movie)
THIS->movie->setPaused(true);
}
END_PROPERTY
BEGIN_PROPERTY(CMOVIEBOX_playing)
if (READ_PROPERTY)
GB.ReturnBoolean(THIS->movie ? THIS->movie->state() == QMovie::Running : FALSE);
else if (THIS->movie)
{
if (VPROP(GB_BOOLEAN))
THIS->movie->setPaused(false);
else
THIS->movie->setPaused(true);
}
END_PROPERTY
BEGIN_METHOD_VOID(CMOVIEBOX_rewind)
if (!THIS->movie)
return;
THIS->movie->stop();
THIS->movie->start();
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
};