QFrameBuffer Class Reference

This class serves as a frame buffer and event handler of a QLabel widget for displaying video frames.

It manages a QImage object as a frame buffer whose pixels may be set using the setPixel() method. For painting the frame buffer's contents into the QLabel widget's pixmap, a customEvent() handler is implemented.

Although this class is an extension of QWidget, it is not intended to be used as a replacement of the QLabel instance actually displaying the video frames. Actually, a QFrameBuffer widget will never become visible. . More...

#include <QFrameBuffer.hpp>

Inheritance diagram for QFrameBuffer:

VideoFrameBuffer List of all members.

Public Member Functions

 QFrameBuffer (QLabel *qlabel, int depth, int numColors=0, bool gray=true, QEvent::Type eventType=QEvent::User)
 Constructor.
virtual ~QFrameBuffer ()
 Destructor.
void setPixel (int x, int y, uint index_or_rgb)
 Set a pixel in the frame buffer.
void postPaintEvent ()
 Post a custom event for this object to display the frame buffer on the QLabel widget.

Protected Member Functions

virtual void customEvent (QCustomEvent *event)
 Event handler for displaying the QImage buffer's contents in the associated QLabel widget.

Detailed Description

This class serves as a frame buffer and event handler of a QLabel widget for displaying video frames.

It manages a QImage object as a frame buffer whose pixels may be set using the setPixel() method. For painting the frame buffer's contents into the QLabel widget's pixmap, a customEvent() handler is implemented.

Although this class is an extension of QWidget, it is not intended to be used as a replacement of the QLabel instance actually displaying the video frames. Actually, a QFrameBuffer widget will never become visible. .

Author:
Mario Taschwer
Version:
Id
QFrameBuffer.hpp,v 1.5 2005/02/22 18:26:11 mkropfbe Exp

Definition at line 75 of file QFrameBuffer.hpp.


Constructor & Destructor Documentation

QFrameBuffer::QFrameBuffer QLabel *  qlabel,
int  depth,
int  numColors = 0,
bool  gray = true,
QEvent::Type  eventType = QEvent::User
 

Constructor.

Parameters:
qlabel the QLabel widget where to display the video frames. This object will become an invisible child of qlabel in the widget hierarchy. The frame buffer will be initialized to the width and height of qlabel.
depth the color depth of the frame buffer (8, 24, 32).
numColors the color table size of the frame buffer (if depth == 8).
gray if true and numColors > 0, set the color table entries to all gray values.
eventType the custom event type used by postPaintEvent() to request displaying the frame buffer on the qlabel widget. The value of this parameter should be in the range [QEvent::User, QEvent::MaxUser].
See also:
QImage::QImage(int, int, int, int, QImage::Endian)
Definition at line 59 of file QFrameBuffer.cpp.
00061 : QWidget(qlabel), VideoFrameBuffer(gray) { 00062 00063 this->qlabel = qlabel; 00064 this->eventType = eventType; 00065 int real_depth = (depth == 24) ? 32 : depth; 00066 image = new QImage(qlabel->width(), qlabel->height(), real_depth, numColors); 00067 if (depth == 24) 00068 image->setAlphaBuffer(false); 00069 if (numColors > 0 && gray) { 00070 // initialize the color table to gray values 00071 int i; 00072 QRgb *ct = image->colorTable(); 00073 for (i=0; i < numColors; i++) 00074 ct[i] = qRgb(i, i, i); 00075 } 00076 hide(); // this widget should never be visible! 00077 }


Member Function Documentation

void QFrameBuffer::postPaintEvent  )  [virtual]
 

Post a custom event for this object to display the frame buffer on the QLabel widget.

This is thread-safe and will cause the GUI thread to invoke customEvent(). We need to use custom events, as hidden widgets will not receive paint events.

Implements VideoFrameBuffer.

Definition at line 87 of file QFrameBuffer.cpp.

00088 { 00089 /* request repainting of qlabel without erasing it before */ 00090 QApplication::postEvent(this, new QCustomEvent(eventType)); 00091 }

void QFrameBuffer::setPixel int  x,
int  y,
uint  index_or_rgb
[inline, virtual]
 

Set a pixel in the frame buffer.

If this method is called from a thread other than the Qt GUI thread, the frame buffer should be locked before by calling the lock() method.

See also:
QImage::setPixel(int, int, uint)

Reimplemented from VideoFrameBuffer.

Definition at line 108 of file QFrameBuffer.hpp.

00108 { 00109 image->setPixel(x, y, index_or_rgb); 00110 }


The documentation for this class was generated from the following files: