Source Code (Use browser search to find items of interest.)

Class Index

kdelibs'KAnimWidget (./kdelibs/kdeui/kanimwidget.h:56)

class KAnimWidget : public QFrame
{
  Q_OBJECT
public:	
  /**
   * This is the most common constructor.  Pass along your list of
   * icons to use for the animation and an optional size to load and
   * you're set.  If you omit the size, the default size will be used.
   *
   * @param icons  The icons to use for the animation
   * @param size   The size to load
   *         You don't have to set it if the parent is a KToolBar; in this case
   *         it will use the toolbar's size.
   * @param parent The standard parent
   * @param name   The standard internal name
   */
  KAnimWidget( const QStringList& icons,
               int size = 0,
               QWidget *parent = 0L, const char *name = 0L );

  /**
   * Default constructor.  This will not do anything until you use
   * @ref setIcons later.
   *
   * @param parent The standard parent
   * @param name   The standard internal name
   */
  KAnimWidget( QWidget *parent = 0L, const char *name = 0L );

  /**
   * Destructor
   */
  virtual ~KAnimWidget();

  /**
   * Start the animation from frame 1
   */
  void start();

  /**
   * Stop the animation.  This will also reset the widget to frame 1.
   */
  void stop();

  /**
   * Set the size of the icons.
   *
   * @param size The size of the icons
   */
  void setSize( int size );

  /**
   * Set the list of icons to use for the animation.  They will all be
   * loaded using the BarIcon() function so make sure that they are
   * toolbar icons... or at least loadable using BarIcon()
   *
   * @param icons The icons to use for the animation
   */
  void setIcons( const QStringList& icons );

signals:
  void clicked();

protected:
  virtual void drawContents( QPainter *p );
  virtual void leaveEvent( QEvent *e );
  virtual void enterEvent( QEvent *e );
  virtual void mousePressEvent( QMouseEvent *e );

protected slots:
  void slotTimerUpdate();
  void updateIcons();

private:
  class KAnimWidgetPrivate;
  KAnimWidgetPrivate *d;
};

kdelibs'KAnimWidget::KAnimWidget() (./kdelibs/kdeui/kanimwidget.cpp:43)

KAnimWidget::KAnimWidget( const QStringList& icons, int size,
                          QWidget *parent, const char *name )
  : QFrame( parent, name ),
    d(new KAnimWidgetPrivate)
{
  connect( &d->timer, SIGNAL(timeout()), this, SLOT(slotTimerUpdate()));

  if (parent->inherits( "KToolBar" ))
    connect(parent, SIGNAL(modechange()), this, SLOT(updateIcons()));

  d->size = size;
  setIcons( icons );
//  setFrameStyle( WinPanel | Raised );
  setFrameStyle( NoFrame );
}


kdelibs'KAnimWidget::~KAnimWidget() (./kdelibs/kdeui/kanimwidget.cpp:59)

KAnimWidget::~KAnimWidget()
{
  d->timer.stop();

  delete d; d = 0;
}


kdelibs'KAnimWidget::start() (./kdelibs/kdeui/kanimwidget.cpp:66)

void KAnimWidget::start()
{
  d->iter   = d->pixmaps.begin();
  d->pixmap = *d->iter;
  d->timer.start( 50 );
}


kdelibs'KAnimWidget::stop() (./kdelibs/kdeui/kanimwidget.cpp:73)

void KAnimWidget::stop()
{
  d->iter   = d->pixmaps.begin();
  d->pixmap = *d->iter;
  d->timer.stop();
  repaint();
}


kdelibs'KAnimWidget::setSize() (./kdelibs/kdeui/kanimwidget.cpp:81)

void KAnimWidget::setSize( int size )
{
  if ( d->size == size )
    return;

  d->size = size;
  updateIcons();
}


kdelibs'KAnimWidget::setIcons() (./kdelibs/kdeui/kanimwidget.cpp:90)

void KAnimWidget::setIcons( const QStringList& icons )
{
  if ( d->icons == icons )
    return;

  d->icons = icons;
  updateIcons();
}


kdelibs'KAnimWidget::enterEvent() (./kdelibs/kdeui/kanimwidget.cpp:99)

void KAnimWidget::enterEvent( QEvent *e )
{
  setFrameStyle( WinPanel | Raised );

  QFrame::enterEvent( e );
}


kdelibs'KAnimWidget::leaveEvent() (./kdelibs/kdeui/kanimwidget.cpp:106)

void KAnimWidget::leaveEvent( QEvent *e )
{
  setFrameStyle( NoFrame );

  QFrame::enterEvent( e );
}


kdelibs'KAnimWidget::mousePressEvent() (./kdelibs/kdeui/kanimwidget.cpp:113)

void KAnimWidget::mousePressEvent( QMouseEvent *e )
{
  emit clicked();

  QFrame::mousePressEvent( e );
}


kdelibs'KAnimWidget::slotTimerUpdate() (./kdelibs/kdeui/kanimwidget.cpp:120)

void KAnimWidget::slotTimerUpdate()
{
  if ( d->iter == d->pixmaps.end() )
    d->iter = d->pixmaps.begin();

  d->pixmap = *d->iter;

  ++d->iter;

  repaint(false);
}


kdelibs'KAnimWidget::drawContents() (./kdelibs/kdeui/kanimwidget.cpp:132)

void KAnimWidget::drawContents( QPainter *p )
{
  if ( d->pixmap.isNull() )
    return;

  QPixmap pm(QSize(this->width(), this->height()));
  QPainter p2 (&pm);
  int x, y;
    
  pm.fill (p->backgroundColor());
  
  if ( d->pixmap.width() != width() || d->pixmap.height() != height() )
  {
    x = (width()  - d->pixmap.width()) / 2;
    y = (height() - d->pixmap.height()) / 2;
  }
  else
  {
  
    x = 0;
    y = 0;
  }  
  
  p2.drawPixmap (x, y, d->pixmap);
  p->drawPixmap( 0, 0, pm);
}


kdelibs'KAnimWidget::updateIcons() (./kdelibs/kdeui/kanimwidget.cpp:159)

void KAnimWidget::updateIcons()
{
  if (parent()->inherits( "KToolBar" ))
  {
    if ( d->size == 0 )
      d->size = ((KToolBar*)parent())->iconSize();
  }

  d->pixmaps.clear();

  QStringList::Iterator it = d->icons.begin();
  for( ; it != d->icons.end(); ++it)
  {
    d->pixmaps.append( MainBarIcon( *it, d->size ) );
  }

  d->iter   = d->pixmaps.begin();
  d->pixmap = *d->iter;
  if ( d->pixmap.width() != width() || d->pixmap.height() != height() )
    resize(d->pixmap.width(), d->pixmap.height());
}