~ubuntu-branches/ubuntu/breezy/psi/breezy

« back to all changes in this revision

Viewing changes to src/busywidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** busywidget.cpp - cool animating widget
3
 
** Copyright (C) 2001, 2002  Justin Karneges
4
 
**
5
 
** This program is free software; you can redistribute it and/or
6
 
** modify it under the terms of the GNU General Public License
7
 
** as published by the Free Software Foundation; either version 2
8
 
** of the License, or (at your option) any later version.
9
 
**
10
 
** This program is distributed in the hope that it will be useful,
11
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
** GNU General Public License for more details.
14
 
**
15
 
** You should have received a copy of the GNU General Public License
16
 
** along with this program; if not, write to the Free Software
17
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 
**
19
 
****************************************************************************/
20
 
 
21
 
#include"busywidget.h"
22
 
#include<qpainter.h>
23
 
 
24
 
BusyWidget::BusyWidget(QWidget *parent, const char *name)
25
 
:QWidget(parent, name)
26
 
{
27
 
        v_isActive = FALSE;
28
 
        frame = 0;
29
 
        at = 0;
30
 
 
31
 
        t = 0;
32
 
 
33
 
        setFixedWidth(80);
34
 
        setFixedHeight(17);
35
 
        setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
36
 
 
37
 
        renderPixmap();
38
 
}
39
 
 
40
 
void BusyWidget::start()
41
 
{
42
 
        if(v_isActive)
43
 
                return;
44
 
 
45
 
        v_isActive = TRUE;
46
 
        t = new QTimer(this);
47
 
        connect(t, SIGNAL(timeout()), SLOT(animate()));
48
 
        t->start(50);
49
 
}
50
 
 
51
 
void BusyWidget::stop()
52
 
{
53
 
        if(!v_isActive)
54
 
                return;
55
 
 
56
 
        v_isActive = FALSE;
57
 
        delete t;
58
 
        t = 0;
59
 
 
60
 
        renderPixmap();
61
 
        render();
62
 
}
63
 
 
64
 
void BusyWidget::animate()
65
 
{
66
 
        ++at;
67
 
        if(at == 12)
68
 
                at = 0;
69
 
 
70
 
        renderPixmap();
71
 
        render();
72
 
}
73
 
 
74
 
void BusyWidget::paintEvent(QPaintEvent *)
75
 
{
76
 
        render();
77
 
}
78
 
 
79
 
void BusyWidget::resizeEvent(QResizeEvent *)
80
 
{
81
 
        renderPixmap();
82
 
}
83
 
 
84
 
void BusyWidget::render()
85
 
{
86
 
        QPainter p(this);
87
 
        p.drawPixmap(0,0, pix);
88
 
}
89
 
 
90
 
void BusyWidget::renderPixmap()
91
 
{
92
 
        pix.resize(width(), height());
93
 
        pix.fill(Qt::white);
94
 
 
95
 
        QPainter p(&pix);
96
 
        p.setPen(v_isActive ? QColor("#FF00FF") : (Qt::gray));
97
 
        int y = height();
98
 
        int a = y / 2;
99
 
        int rep = width() / 12;
100
 
        for(int n = -1; n < rep+1; ++n) {
101
 
                int x = n * 12 + at;
102
 
                for(int n2 = 0; n2 < 4; ++n2) {
103
 
                        p.drawLine(x+n2, 0, x+n2 + 8, a);
104
 
                        p.drawLine(x+n2, y-1, x+n2 + 8, a);
105
 
                }
106
 
        }
107
 
 
108
 
        p.setPen(Qt::black);
109
 
        p.drawRect(0, 0, width(), height());
110
 
}
111