File: bubbles.cpp

package info (click to toggle)
kaquarium 1.0-beta-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,900 kB
  • ctags: 325
  • sloc: sh: 19,057; perl: 2,724; cpp: 1,340; makefile: 100
file content (132 lines) | stat: -rw-r--r-- 3,164 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

#include <stdlib.h>

#include <qtimer.h>
#include <kstandarddirs.h>
#include <kdebug.h>

#include "main.h"
#include "pref.h"
#include "misc.h"

#include "bubbles.h"

kfishBubble::kfishBubble( QCanvas *c, QCanvasPixmapArray *pa )
              : QObject( c )
              , QCanvasSprite( pa, c )
{
    // set the pixmap sequence
    setSequence( pa );

    setZ( 0 );
    // at first i set false, becouse i don't have width and height
    setAnimated( true );     // allow animation

    subdiv = 1;

    init();

    show();
    
}

void kfishBubble::slotAdvance()
{
    posy--;
    if ( posy < -4 )
    {
        // if the bubble is over the top of the widget, i start the positions again
        init();
    }
}

void kfishBubble::slotResized()
{
    subdiv = kfishPref::prefs() -> getPanelHeight() / 4;
    init();
    setAnimated( true );
}

void kfishBubble::advance( int phase )
{
    // change the bubble position and maybe the kind of bubble itself
    if (phase != 0)
        move(posx, posy, (int) posy / subdiv);
}

void kfishBubble::init()
{
    posx = rand() % kfishPref::prefs() -> getPanelWidth();
    posy = kfishPref::prefs() -> getPanelHeight() + rand() % kfishPref::prefs() -> getPanelHeight();
}

        
kfishBubbleManager::kfishBubbleManager( QCanvas *canvas, QObject *parent, const char *name )
              : QObject( parent , name )
                , m_canvas( canvas )
{
    m_bubbles = new QCanvasPixmapArray();
    getAnimationFromFile( *m_bubbles, locate("data", "kaquarium/pics/bubbles.png"), 6, 7, 4, Vertical, 0, 0);

	m_timer = new QTimer( this, "Bubble Manager Timer" );	
   
    // set the number of bubble we will have
    m_numOfBubbles = kfishPref::prefs() -> getBubblesNumber();
	    
    for (int i = 0; i < m_numOfBubbles; i++)
        addBubble();

    m_timer -> start(20);
		    
	connect(m_canvas, SIGNAL( resized() ), SIGNAL( signalResized() ));
	connect(kfishApp, SIGNAL( signalSettingsChanged() ), SLOT( slotSettingsChanged() ));
}

kfishBubbleManager::~kfishBubbleManager()
{
    m_timer -> stop();
    delete m_timer;
}

void kfishBubbleManager::slotChangeNumberOfBubbles( int newnum )
{
    // get the number of bubbles
    int bubcount = int ( m_listBubble .count() );

    if ( newnum == bubcount )
        return;
    m_numOfBubbles = newnum;
    
    if ( newnum > bubcount )
    {
        for (int i=0; i < newnum - bubcount; i++)
            addBubble();
    }
    else
    {
        for (int i=0; i < bubcount - newnum; i++)
            delBubble();
    }
}

void kfishBubbleManager::slotSettingsChanged()
{
//    kdDebug(1210) << "void kfishBubbleManager::slotSettingsChanged()" << endl;
    slotChangeNumberOfBubbles( kfishPref::prefs() -> getBubblesNumber() );
}

bool kfishBubbleManager::addBubble()
{
    kfishBubble *newbub = new kfishBubble( m_canvas, m_bubbles );
    connect( m_timer, SIGNAL( timeout() ), newbub, SLOT( slotAdvance() ));
    connect( this, SIGNAL( signalResized() ), newbub, SLOT( slotResized() ));
   
    m_listBubble .append( newbub );
    return true;
}

bool kfishBubbleManager::delBubble()
{
    delete m_listBubble .first();
    return m_listBubble .removeFirst( );
}