• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

digikam

animwidget.cpp

Go to the documentation of this file.
00001 /* ============================================================
00002  *
00003  * This file is a part of digiKam project
00004  * http://www.digikam.org
00005  *
00006  * Date        : 2004-09-21
00007  * Description : an animated busy widget 
00008  * 
00009  * Copyright (C) 2004-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
00010  * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com> 
00011  *
00012  * This program is free software; you can redistribute it
00013  * and/or modify it under the terms of the GNU General
00014  * Public License as published by the Free Software Foundation;
00015  * either version 2, or (at your option)
00016  * any later version.
00017  * 
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  * 
00023  * ============================================================ */
00024 
00025 // Qt includes.
00026 
00027 #include <QPainter>
00028 #include <QPixmap>
00029 #include <QPalette>
00030 #include <QColor>
00031 #include <QTimer>
00032 
00033 // Local includes.
00034 
00035 #include "animwidget.h"
00036 #include "animwidget.moc"
00037 
00038 namespace Digikam
00039 {
00040 
00041 class AnimWidgetPriv
00042 {
00043 public:
00044 
00045     AnimWidgetPriv()
00046     {
00047         timer = 0;
00048         pix   = 0;
00049         pos   = 0;
00050     }
00051 
00052     int      pos;
00053     int      size;
00054     
00055     QTimer  *timer;
00056     
00057     QPixmap *pix;    
00058 };
00059 
00060 AnimWidget::AnimWidget(QWidget* parent, int size)
00061           : QWidget(parent)
00062 {
00063     d = new AnimWidgetPriv;
00064     d->size = size; 
00065 
00066     setAttribute(Qt::WA_DeleteOnClose);
00067     setFixedSize(d->size, d->size);
00068 
00069     d->pix   = new QPixmap(d->size, d->size);
00070     d->timer = new QTimer();
00071     
00072     connect(d->timer, SIGNAL(timeout()),
00073             this, SLOT(slotTimeout()));
00074 }
00075 
00076 AnimWidget::~AnimWidget()
00077 {
00078     delete d;
00079 }
00080 
00081 void AnimWidget::start()
00082 {
00083     d->pos = 0;
00084     d->timer->start(100);
00085 }
00086 
00087 void AnimWidget::stop()
00088 {
00089     d->pos = 0;
00090     d->timer->stop();
00091     repaint();
00092 }
00093 
00094 void AnimWidget::paintEvent(QPaintEvent*)
00095 {
00096     d->pix->fill(palette().background().color());
00097     QPainter p(d->pix);
00098 
00099     p.translate(d->size/2, d->size/2);
00100 
00101     if (d->timer->isActive())
00102     {
00103         p.setPen(QPen(palette().color(QPalette::Text)));
00104         p.rotate( d->pos );
00105     }
00106     else
00107     {
00108         p.setPen(QPen(palette().color(QPalette::Dark)));
00109     }
00110             
00111     for ( int i=0 ; i<12 ; i++ )
00112     {
00113         p.drawLine(d->size/2-4, 0, d->size/2-2, 0);
00114         p.rotate(30);
00115     }
00116     
00117     p.end();
00118 
00119     QPainter p2(this);
00120     p2.drawPixmap(0, 0, *d->pix);
00121     p2.end();
00122 }
00123 
00124 void AnimWidget::slotTimeout()
00125 {
00126     d->pos = (d->pos + 10) % 360;
00127     repaint();    
00128 }
00129 
00130 bool AnimWidget::running() const
00131 {
00132     return d->timer->isActive();    
00133 }
00134 
00135 }  // namespace Digikam

digikam

Skip menu "digikam"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • digikam
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal