PDA

View Full Version : jpeg viewer



chap19150
5th June 2006, 17:05
i have a layout with 3 qlabels a horizontal slidebar and a start button
what I want to happen is when the start button is pressed a sequence
of images(3 different sets of images) is shown in the 3 labels. I would also like to
control the animation sequence with the slide bar. Does anybody have any
idea on how I should takle this. I hope I explained this well enough.

I am using QT 4.1.3 on a linux machine.

TIA

jacek
5th June 2006, 17:17
Just create a custom widget derived from QLabel, that implements play(), stop(), nextFrame(), jumpToFrame() and other slots. You can connect QTimer to nextFrame() and control that timer using play() and stop(). Then just connect a QSlider to jumpToFrame() and you're done.

Of course instead of creating a custom widget, you can create a normal object (derived from QObject) that only controls what is displayed in a given QLabel.

chap19150
5th June 2006, 18:19
Thanks for replying...


Just create a custom widget derived from QLabel, that implements play(), stop(), nextFrame(), jumpToFrame() and other slots.

ok. I understand this, but as far as getting the images together, what
should I use. e.g. an array of filenames etc.


You can connect QTimer to nextFrame() and control that timer using play() and stop(). Then just connect a QSlider to jumpToFrame() and you're done.

I understand QSlider and jumpToFrame(), but can you explain "connect QTimer to
nextFrame()" to me


Of course instead of creating a custom widget, you can create a normal object (derived from QObject) that only controls what is displayed in a given QLabel.

i'm sorry but can you dumb this down for me?

jacek
5th June 2006, 19:29
what should I use. e.g. an array of filenames etc.
It depends. If those files are selected by the user, it will be easier for you if you could pass a list of file names to that class, but if images will be generated (or corrected) on the fly it will be easier to operate on QPixmaps. You can even consider splitting the implementation into two classes --- one that manages the slideshow and one that provides the data (actually you can have many providers that share a common interface).


can you explain "connect QTimer to nextFrame()" to me
You can make QTimer instance emit a timeout() signal with a given frequency and use this signal to advance to the next frame.


can you dumb this down for me?
You can do this:
class SlideShowWidget : public QWidget
{
Q_OBJECT
public:
...
public slots:
void start();
void stop();
...
};or this:
class SlideShow : public QObject
{
Q_OBJECT
public:
...
void setLabel( QLabel * label );

public slots:
void start();
void stop();
...
};
SlideShowWidget is a widget that displays a slideshow, while SlideShow can display a slideshow on a given QLabel. There's not much difference between them, but it's up to you to decide which one will suit you better.

chap19150
5th June 2006, 19:50
Thanks, I think I understand now, but I have just a couple of more questions.

The file are not going to be selected by the user. I have three sets of files
in three different directories to be viewed. I know how to get QPixmap to
view one file, but how do I get it to show the sequence? I have the images
numbered folder1/pic1.jpg... folder1/pic50.jpg.

also,



SlideShowWidget is a widget that displays a slideshow, while SlideShow can display a slideshow on a given QLabel. There's not much difference between them, but it's up to you to decide which one will suit you better.

Are you sure it make no difference even though i have 3 labels that have to iterate in unison?
For example if I create a normal object, how is that implemented? Do I have to call
setLabel() for each QLabel?

jacek
5th June 2006, 20:09
I know how to get QPixmap to view one file, but how do I get it to show the sequence?
QPixmap holds only a single image, so you will have to create a pixmap for every file (the question is: when?).


Are you sure it make no difference even though i have 3 labels that have to iterate in unison?
You will have either one object that shows n slide shows or n objects (each showing a single slide show). IMO it will be easier to have many objects. There shouldn't be any problems with synchronization, because you can connect the same signal to many slots.

wysota
6th June 2006, 01:12
I don't see it mentioned anywhere, so what the heck... You could use QMovie which already implements much of the functionality you desire. It could be needed to subclass it though, to handle a sequence of jpegs (but you should verify that first).

jacek
6th June 2006, 11:12
It could be needed to subclass it though, to handle a sequence of jpegs
The problem is that you can't subclass QMovie, because it has no virtual methods.

wysota
6th June 2006, 11:24
The problem is that you can't subclass QMovie, because it has no virtual methods.

Why not? You don't have to cast it to QMovie* to use it... Correct me if I'm wrong but I recall that virtual methods are only required if you want to call the subclass reimplementation from the superclass interface...


QMovie *m = new MyMovie();
m->start(); // will always call from QMovie

MyMovie *m = new MyMovie();
m->start(); // will call from MyMovie

jacek
6th June 2006, 11:57
Why not? You don't have to cast it to QMovie* to use it...
But you will have to implement every method, so there is no benefit in using QMovie.

#include <iostream>

class A
{
public:
void foo() { bar(); }
void bar() { std::cerr << "A::bar()" << std::endl; }
};

class B : public A
{
public:
void bar() { std::cerr << "B::bar()" << std::endl; }
};

int main()
{
B b;
b.foo();
b.bar();
return 0;
}