summaryrefslogtreecommitdiffstats
path: root/examples/movies
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/movies
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/movies')
-rw-r--r--examples/movies/fire.mngbin0 -> 44430 bytes
-rw-r--r--examples/movies/main.cpp291
-rw-r--r--examples/movies/movies.doc19
-rw-r--r--examples/movies/movies.pro10
-rw-r--r--examples/movies/trolltech.gifbin0 -> 42629 bytes
5 files changed, 320 insertions, 0 deletions
diff --git a/examples/movies/fire.mng b/examples/movies/fire.mng
new file mode 100644
index 000000000..c6695c836
--- /dev/null
+++ b/examples/movies/fire.mng
Binary files differ
diff --git a/examples/movies/main.cpp b/examples/movies/main.cpp
new file mode 100644
index 000000000..5aaea565f
--- /dev/null
+++ b/examples/movies/main.cpp
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qfiledialog.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qpainter.h>
+#include <qmessagebox.h>
+#include <qmovie.h>
+#include <qvbox.h>
+
+
+class MovieScreen : public TQFrame {
+ Q_OBJECT
+ TQMovie movie;
+ TQString filename;
+ TQSize sh;
+
+public:
+ MovieScreen(const char* fname, TQMovie m, TQWidget* p=0, const char* name=0, WFlags f=0) :
+ TQFrame(p, name, f),
+ sh(100,100)
+ {
+ setCaption(fname);
+ filename = fname;
+ movie = m;
+
+ // Set a frame around the movie.
+ setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
+
+ // No background needed, since we draw on the whole widget.
+ movie.setBackgroundColor(backgroundColor());
+ setBackgroundMode(NoBackground);
+
+ // Get the movie to tell use when interesting things happen.
+ movie.connectUpdate(this, SLOT(movieUpdated(const TQRect&)));
+ movie.connectResize(this, SLOT(movieResized(const TQSize&)));
+ movie.connectStatus(this, SLOT(movieStatus(int)));
+
+ setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Expanding));
+ }
+
+ TQSize sizeHint() const
+ {
+ return sh;
+ }
+
+protected:
+
+ // Draw the contents of the TQFrame - the movie and on-screen-display
+ void drawContents(TQPainter* p)
+ {
+ // Get the current movie frame.
+ TQPixmap pm = movie.framePixmap();
+
+ // Get the area we have to draw in.
+ TQRect r = contentsRect();
+
+ if ( !pm.isNull() ) {
+ // Only rescale is we need to - it can take CPU!
+ if ( r.size() != pm.size() ) {
+ TQWMatrix m;
+ m.scale((double)r.width()/pm.width(),
+ (double)r.height()/pm.height());
+ pm = pm.xForm(m);
+ }
+
+ // Draw the [possibly scaled] frame. movieUpdated() below calls
+ // repaint with only the changed area, so clipping will ensure we
+ // only do the minimum amount of rendering.
+ //
+ p->drawPixmap(r.x(), r.y(), pm);
+ }
+
+
+ // The on-screen display
+
+ const char* message = 0;
+
+ if (movie.paused()) {
+ message = "PAUSED";
+ } else if (movie.finished()) {
+ message = "THE END";
+ } else if (movie.steps() > 0) {
+ message = "FF >>";
+ }
+
+ if (message) {
+ // Find a good font size...
+ p->setFont(TQFont("Helvetica", 24));
+
+ TQFontMetrics fm = p->fontMetrics();
+ if ( fm.width(message) > r.width()-10 )
+ p->setFont(TQFont("Helvetica", 18));
+
+ fm = p->fontMetrics();
+ if ( fm.width(message) > r.width()-10 )
+ p->setFont(TQFont("Helvetica", 14));
+
+ fm = p->fontMetrics();
+ if ( fm.width(message) > r.width()-10 )
+ p->setFont(TQFont("Helvetica", 12));
+
+ fm = p->fontMetrics();
+ if ( fm.width(message) > r.width()-10 )
+ p->setFont(TQFont("Helvetica", 10));
+
+ // "Shadow" effect.
+ p->setPen(black);
+ p->drawText(1, 1, width()-1, height()-1, AlignCenter, message);
+ p->setPen(white);
+ p->drawText(0, 0, width()-1, height()-1, AlignCenter, message);
+ }
+ }
+
+public slots:
+ void restart()
+ {
+ movie.restart();
+ repaint();
+ }
+
+ void togglePause()
+ {
+ if ( movie.paused() )
+ movie.unpause();
+ else
+ movie.pause();
+ repaint();
+ }
+
+ void step()
+ {
+ movie.step();
+ repaint();
+ }
+
+ void step10()
+ {
+ movie.step(10);
+ repaint();
+ }
+
+private slots:
+ void movieUpdated(const TQRect& area)
+ {
+ if (!isVisible())
+ show();
+
+ // The given area of the movie has changed.
+
+ TQRect r = contentsRect();
+
+ if ( r.size() != movie.framePixmap().size() ) {
+ // Need to scale - redraw whole frame.
+ repaint( r );
+ } else {
+ // Only redraw the changed area of the frame
+ repaint( area.x()+r.x(), area.y()+r.x(),
+ area.width(), area.height() );
+ }
+ }
+
+ void movieResized(const TQSize& size)
+ {
+ // The movie changed size, probably from its initial zero size.
+
+ int fw = frameWidth();
+ sh = TQSize( size.width() + fw*2, size.height() + fw*2 );
+ updateGeometry();
+ if ( parentWidget() && parentWidget()->isHidden() )
+ parentWidget()->show();
+ }
+
+ void movieStatus(int status)
+ {
+ // The movie has sent us a status message.
+
+ if (status < 0) {
+ TQString msg;
+ msg.sprintf("Could not play movie \"%s\"", (const char*)filename);
+ TQMessageBox::warning(this, "movies", msg);
+ parentWidget()->close();
+ } else if (status == TQMovie::Paused || status == TQMovie::EndOfMovie) {
+ repaint(); // Ensure status text is displayed
+ }
+ }
+};
+
+class MoviePlayer : public TQVBox {
+ MovieScreen* movie;
+public:
+ MoviePlayer(const char* fname, TQMovie m, TQWidget* p=0, const char* name=0, WFlags f=0) :
+ TQVBox(p,name,f)
+ {
+ movie = new MovieScreen(fname, m, this);
+ TQHBox* hb = new TQHBox(this);
+ TQPushButton* btn;
+ btn = new TQPushButton("<<", hb);
+ connect(btn, SIGNAL(clicked()), movie, SLOT(restart()));
+ btn = new TQPushButton("||", hb);
+ connect(btn, SIGNAL(clicked()), movie, SLOT(togglePause()));
+ btn = new TQPushButton(">|", hb);
+ connect(btn, SIGNAL(clicked()), movie, SLOT(step()));
+ btn = new TQPushButton(">>|", hb);
+ connect(btn, SIGNAL(clicked()), movie, SLOT(step10()));
+ }
+};
+
+
+// A TQFileDialog that chooses movies.
+//
+class MovieStarter: public TQFileDialog {
+ Q_OBJECT
+public:
+ MovieStarter(const char *dir);
+
+public slots:
+ void startMovie(const TQString& filename);
+ // TQDialog's method - normally closes the file dialog.
+ // We want it left open, and we want Cancel to tquit everything.
+ void done( int r );
+};
+
+
+MovieStarter::MovieStarter(const char *dir)
+ : TQFileDialog(dir, "*.gif *.mng")
+{
+ //behave as in getOpenFilename
+ setMode( ExistingFile );
+ // When a file is selected, show it as a movie.
+ connect(this, SIGNAL(fileSelected(const TQString&)),
+ this, SLOT(startMovie(const TQString&)));
+}
+
+
+void MovieStarter::startMovie(const TQString& filename)
+{
+ if ( filename ) // Start a new movie - have it delete when closed.
+ (new MoviePlayer( filename, TQMovie(filename), 0, 0,
+ WDestructiveClose))->show();
+}
+
+void MovieStarter::done( int r )
+{
+ if (r != Accepted)
+ qApp->tquit(); // end on Cancel
+ setResult( r );
+
+ // And don't hide.
+}
+
+
+int main(int argc, char **argv)
+{
+ TQApplication a(argc, argv);
+
+ if (argc > 1) {
+ // Commandline mode - show movies given on the command line
+ //
+ bool gui=TRUE;
+ for (int arg=1; arg<argc; arg++) {
+ if ( TQString(argv[arg]) == "-i" )
+ gui = !gui;
+ else if ( gui )
+ (void)new MoviePlayer(argv[arg], TQMovie(argv[arg]), 0, 0,
+ TQt::WDestructiveClose);
+ else
+ (void)new MovieScreen(argv[arg], TQMovie(argv[arg]), 0, 0,
+ TQt::WDestructiveClose);
+ }
+ TQObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(tquit()));
+ } else {
+ // "GUI" mode - open a chooser for movies
+ //
+ MovieStarter* fd = new MovieStarter(".");
+ fd->show();
+ }
+
+ // Go!
+ return a.exec();
+}
+
+#include "main.moc"
diff --git a/examples/movies/movies.doc b/examples/movies/movies.doc
new file mode 100644
index 000000000..d2b6b9bae
--- /dev/null
+++ b/examples/movies/movies.doc
@@ -0,0 +1,19 @@
+/*
+*/
+/*! \page movies-example.html
+
+ \ingroup examples
+ \title Movies or the Story of the Animated GIF file
+
+ The Movies example displays MNG and animated GIF files using the QMovie and
+ QLabel classes.
+
+ The movies will only read an animated GIF if GIF reading was enabled when Qt was built.
+
+ <hr>
+
+ Main:
+
+ \include movies/main.cpp
+*/
+
diff --git a/examples/movies/movies.pro b/examples/movies/movies.pro
new file mode 100644
index 000000000..39c017f5e
--- /dev/null
+++ b/examples/movies/movies.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = movies
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp
diff --git a/examples/movies/trolltech.gif b/examples/movies/trolltech.gif
new file mode 100644
index 000000000..f674369ef
--- /dev/null
+++ b/examples/movies/trolltech.gif
Binary files differ