DisplayWidget Class Reference

#include <displaywidget.h>

Inheritance diagram for DisplayWidget:

Inheritance graph
[legend]
Collaboration diagram for DisplayWidget:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 32 of file displaywidget.h.

Signals

void actionRequested (const QString &name)
void displayEmpty ()
void categoryRequested (const QString &name)
void documentationRequested (const QString &name)
void exampleRequested (const QString &name)
void launchRequested (const QString &name)

Public Member Functions

 DisplayWidget (QWidget *parent=0)
QSize minimumSizeHint () const
DisplayShapeshape (int index) const
int shapesCount () const
void appendShape (DisplayShape *shape)
void enableUpdates ()
void insertShape (int position, DisplayShape *shape)
void reset ()

Protected Member Functions

void mouseMoveEvent (QMouseEvent *event)
void mousePressEvent (QMouseEvent *event)
void paintEvent (QPaintEvent *event)
void timerEvent (QTimerEvent *event)

Private Attributes

bool empty
bool emptying
bool updatesEnabled
QList< DisplayShape * > shapes
QBasicTimer timer


Constructor & Destructor Documentation

DisplayWidget::DisplayWidget ( QWidget parent = 0  ) 

Definition at line 34 of file displaywidget.cpp.

References QPalette::Base, empty, emptying, enableUpdates(), QWidget::setBackgroundRole(), and QWidget::setMouseTracking().

00035     : QWidget(parent)
00036 {
00037 #if defined(Q_WS_X11)
00038     frameTime = 0;
00039     avgRate = 0;
00040     numFrames = 0;
00041     testDrawSpeed = true;
00042 #endif
00043     empty = true;
00044     emptying = false;
00045 
00046     enableUpdates();
00047 
00048     setBackgroundRole(QPalette::Base);
00049     setMouseTracking(true);
00050 }

Here is the call graph for this function:


Member Function Documentation

QSize DisplayWidget::minimumSizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 66 of file displaywidget.cpp.

00067 {
00068     return QSize(800, 600);
00069 }

DisplayShape * DisplayWidget::shape ( int  index  )  const

Definition at line 194 of file displaywidget.cpp.

References shapes, and QList< T >::value().

Referenced by appendShape(), Launcher::enableLaunching(), Launcher::fadeShapes(), insertShape(), mouseMoveEvent(), mousePressEvent(), paintEvent(), reset(), and timerEvent().

00195 {
00196     return shapes.value(index);
00197 }

Here is the call graph for this function:

int DisplayWidget::shapesCount (  )  const

Definition at line 199 of file displaywidget.cpp.

References shapes, and QList< T >::size().

Referenced by Launcher::enableLaunching(), and Launcher::fadeShapes().

00200 {
00201     return shapes.size();
00202 }

Here is the call graph for this function:

void DisplayWidget::appendShape ( DisplayShape shape  ) 

Definition at line 52 of file displaywidget.cpp.

References QList< T >::append(), empty, enableUpdates(), shape(), and shapes.

Referenced by Launcher::addTitle(), Launcher::addVersionAndCopyright(), Launcher::showCategories(), Launcher::showExamples(), Launcher::showExampleSummary(), and Launcher::updateExampleSummary().

00053 {
00054     shapes.append(shape);
00055     empty = false;
00056     enableUpdates();
00057 }

Here is the call graph for this function:

void DisplayWidget::enableUpdates (  ) 

Definition at line 204 of file displaywidget.cpp.

References QBasicTimer::isActive(), QBasicTimer::start(), and timer.

Referenced by appendShape(), DisplayWidget(), Launcher::enableLaunching(), insertShape(), mouseMoveEvent(), mousePressEvent(), and reset().

00205 {
00206     if (!timer.isActive())
00207         timer.start(25, this);
00208 }

Here is the call graph for this function:

void DisplayWidget::insertShape ( int  position,
DisplayShape shape 
)

Definition at line 59 of file displaywidget.cpp.

References empty, enableUpdates(), QList< T >::insert(), shape(), and shapes.

Referenced by Launcher::addTitleBackground(), Launcher::showCategories(), Launcher::showExamples(), and Launcher::showExampleSummary().

00060 {
00061     shapes.insert(position, shape);
00062     empty = false;
00063     enableUpdates();
00064 }

Here is the call graph for this function:

void DisplayWidget::reset (  ) 

Definition at line 174 of file displaywidget.cpp.

References displayEmpty(), emit, empty, emptying, enableUpdates(), DisplayShape::setMetaData(), shape(), shapes, QList< T >::size(), QBasicTimer::stop(), and timer.

Referenced by Launcher::executeAction(), and Launcher::toggleFullScreen().

00175 {
00176     if (emptying)
00177         return;
00178 
00179     if (shapes.size() == 0) {
00180         empty = true;
00181         timer.stop();
00182         emit displayEmpty();    // Note: synchronous signal
00183     } else {
00184         enableUpdates();
00185         emptying = true;
00186         empty = false;
00187         foreach (DisplayShape *shape, shapes) {
00188             shape->setMetaData("fade", -15);
00189             shape->setMetaData("fade minimum", 0);
00190         }
00191     }
00192 }

Here is the call graph for this function:

void DisplayWidget::mouseMoveEvent ( QMouseEvent event  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

See also:
setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 71 of file displaywidget.cpp.

References QRectF::contains(), DisplayShape::contains(), emptying, enableUpdates(), QWidget::event(), DisplayShape::isInteractive(), DisplayShape::metaData(), DisplayShape::rect(), DisplayShape::setMetaData(), shape(), shapes, and QVariant::toBool().

00072 {
00073     if (emptying)
00074         return;
00075 
00076     bool updated = false;
00077 
00078     foreach (DisplayShape *shape, shapes) {
00079         if (shape->rect().contains(event->pos())) {
00080             if (shape->isInteractive() && !shape->contains("fade")
00081                 && !shape->contains("highlight")) {
00082                 shape->setMetaData("highlight", true);
00083                 updated = true;
00084             }
00085         } else if (shape->isInteractive() && shape->contains("highlight")
00086                    && shape->metaData("highlight").toBool()) {
00087             shape->setMetaData("highlight", false);
00088             updated = true;
00089         }
00090     }
00091 
00092     if (updated)
00093         enableUpdates();
00094 }

Here is the call graph for this function:

void DisplayWidget::mousePressEvent ( QMouseEvent event  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

See also:
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 96 of file displaywidget.cpp.

References actionRequested(), categoryRequested(), QRectF::contains(), DisplayShape::contains(), documentationRequested(), emit, emptying, enableUpdates(), QWidget::event(), exampleRequested(), launchRequested(), Qt::LeftButton, DisplayShape::metaData(), DisplayShape::rect(), DisplayShape::setMetaData(), shape(), shapes, and QVariant::toString().

00097 {
00098     if (event->button() != Qt::LeftButton)
00099         return;
00100 
00101     if (emptying)
00102         return;
00103 
00104     foreach (DisplayShape *shape, shapes) {
00105         if (shape->rect().contains(event->pos()) && !shape->contains("fade")) {
00106             if (shape->contains("action"))
00107                 emit actionRequested(shape->metaData("action").toString());
00108             else if (shape->contains("category"))
00109                 emit categoryRequested(shape->metaData("category").toString());
00110             else if (shape->contains("example"))
00111                 emit exampleRequested(shape->metaData("example").toString());
00112             else if (shape->contains("documentation")) {
00113                 emit documentationRequested(
00114                     shape->metaData("documentation").toString());
00115                 shape->setMetaData("highlight", false);
00116                 enableUpdates();
00117             } else if (shape->contains("launch")) {
00118                 emit launchRequested(shape->metaData("launch").toString());
00119                 shape->setMetaData("fade", -5);
00120                 enableUpdates();
00121             }
00122         }
00123     }
00124 }

Here is the call graph for this function:

void DisplayWidget::paintEvent ( QPaintEvent event  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole() and setPalette().

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

See also:
event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, {Analog Clock Example}

Reimplemented from QWidget.

Definition at line 126 of file displaywidget.cpp.

References QPainter::begin(), QTime::elapsed(), QPainter::end(), QWidget::event(), QPainter::fillRect(), QRectF::intersects(), DisplayShape::paint(), DisplayShape::rect(), QTime::restart(), shape(), shapes, QTimer::singleShot(), SLOT, Qt::white, and X11.

00127 {
00128 #if defined(Q_WS_X11)
00129     QTime renderTime;
00130     if (testDrawSpeed)
00131         renderTime.restart();
00132 #endif
00133 
00134     QPainter painter;
00135     painter.begin(this);
00136     painter.fillRect(event->rect(), Qt::white);
00137     foreach (DisplayShape *shape, shapes) {
00138         if (shape->rect().intersects(event->rect()))
00139             shape->paint(&painter);
00140     }
00141     painter.end();
00142 
00143 #if defined(Q_WS_X11)
00144     if (testDrawSpeed) {
00145         numFrames++;
00146         frameTime += renderTime.elapsed();
00147         avgRate = frameTime/numFrames;
00148         if (numFrames > 20) {
00149             testDrawSpeed = false;
00150             if (avgRate > 50 && X11->use_xrender)
00151                 QTimer::singleShot(0, this, SLOT(toggleXRender()));
00152         }
00153     }
00154 #endif
00155 }

Here is the call graph for this function:

void DisplayWidget::timerEvent ( QTimerEvent event  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also:
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 210 of file displaywidget.cpp.

References QRect::adjusted(), DisplayShape::animate(), DisplayShape::contains(), displayEmpty(), emit, empty, emptying, QWidget::event(), DisplayShape::rect(), QList< T >::removeAll(), shape(), shapes, QList< T >::size(), QBasicTimer::stop(), timer, QObject::timerEvent(), QBasicTimer::timerId(), QRectF::toRect(), and QWidget::update().

00211 {
00212     if (event->timerId() == timer.timerId()) {
00213         QVector<DisplayShape*> discard;
00214 
00215         int updated = 0;
00216 
00217         foreach (DisplayShape *shape, shapes) {
00218             QRect oldRect = shape->rect().toRect().adjusted(-1,-1,1,1);
00219             if (shape->animate()) {
00220 
00221                 update(oldRect);
00222                 QRect newRect = shape->rect().toRect().adjusted(-1,-1,1,1);
00223                 ++updated;
00224 
00225                 if (shape->contains("destroy")) {
00226                     discard.append(shape);
00227                 } else {
00228                     update(newRect);
00229                 }
00230             }
00231         }
00232 
00233         if (updated == 0)
00234             timer.stop();
00235 
00236         foreach (DisplayShape *shape, discard) {
00237             shapes.removeAll(shape);
00238             delete shape;
00239         }
00240 
00241         if (shapes.size() == 0 && !empty) {
00242             empty = true;
00243             emptying = false;
00244             timer.stop();
00245             emit displayEmpty();    // Note: synchronous signal
00246         }
00247     } else {
00248   QWidget::timerEvent(event);
00249     }
00250 }

Here is the call graph for this function:

void DisplayWidget::actionRequested ( const QString name  )  [signal]

Referenced by mousePressEvent().

void DisplayWidget::displayEmpty (  )  [signal]

Referenced by reset(), and timerEvent().

void DisplayWidget::categoryRequested ( const QString name  )  [signal]

Referenced by mousePressEvent().

void DisplayWidget::documentationRequested ( const QString name  )  [signal]

Referenced by mousePressEvent().

void DisplayWidget::exampleRequested ( const QString name  )  [signal]

Referenced by mousePressEvent().

void DisplayWidget::launchRequested ( const QString name  )  [signal]

Referenced by mousePressEvent().


Member Data Documentation

bool DisplayWidget::empty [private]

Definition at line 61 of file displaywidget.h.

Referenced by appendShape(), DisplayWidget(), insertShape(), reset(), and timerEvent().

bool DisplayWidget::emptying [private]

Definition at line 62 of file displaywidget.h.

Referenced by DisplayWidget(), mouseMoveEvent(), mousePressEvent(), reset(), and timerEvent().

bool DisplayWidget::updatesEnabled [private]

Definition at line 63 of file displaywidget.h.

QList<DisplayShape*> DisplayWidget::shapes [private]

Definition at line 64 of file displaywidget.h.

Referenced by appendShape(), insertShape(), mouseMoveEvent(), mousePressEvent(), paintEvent(), reset(), shape(), shapesCount(), and timerEvent().

QBasicTimer DisplayWidget::timer [private]

Definition at line 65 of file displaywidget.h.

Referenced by enableUpdates(), reset(), and timerEvent().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 14:52:37 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1