[429088]: kwave / multistateimage.cpp Maximize Restore History

Download this file

multistateimage.cpp    100 lines (90 with data), 2.5 kB

 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
//provides methods of multistateWidget a Class that switches the image it
// displays on clicking, used for the channel enable/disable lamps...
#include <stdio.h>
#include <qaccel.h>
#include <qpntarry.h>
#include <qdir.h>
#include "multistateimage.h"
#include <kapp.h>
QList<QPixmap> *pixmaps=0;
QStrList *pixnames=0;
extern KApplication *app;
//**********************************************************
MultiStateWidget::MultiStateWidget (QWidget *parent,int num,int count): QWidget (parent)
{
this->number=num;
this->states=new int[count];
for (int i=0;i<count;i++) states[i]=0;
this->count=count;
this->act=0;
if (pixmaps==0) pixmaps=new QList<QPixmap>();
if (pixnames==0) pixnames=new QStrList(true);
resize (20,20);
}
//**********************************************************
int MultiStateWidget::addPixmap (char *name)
{
int result=pixnames->find(name);
if (result==-1)
{
QPixmap *newpix=new QPixmap();
QString dirname=app->kde_datadir ();
QDir dir (dirname.data());
dir.cd ("kwave");
dir.cd ("pics");
QImage *img=new QImage(dir.filePath(name).data());
if (newpix&&img)
{
newpix->convertFromImage(*img);
pixmaps->append (newpix);
pixnames->append (name);
return pixmaps->at();
}
}
else
return result;
return -1;
}
//**********************************************************
void MultiStateWidget::setStates (int *newstates)
{
for (int i=0;i<count;i++) states[i]=newstates[i];
}
//**********************************************************
void MultiStateWidget::setState (int newstate)
{
act=newstate;
if (act>=count) act=count;
if (act<0) act=0;
repaint ();
}
//**********************************************************
void MultiStateWidget::nextState ()
{
act++;
if (act>=count) act=0;
repaint ();
}
//**********************************************************
void MultiStateWidget::mouseReleaseEvent( QMouseEvent *e)
{
if (e->button()==LeftButton)
{
nextState ();
emit clicked (number);
}
}
//**********************************************************
MultiStateWidget::~MultiStateWidget ()
{
if (states) delete states;
}
//**********************************************************
void MultiStateWidget::paintEvent (QPaintEvent *)
{
QPixmap *img;
img=pixmaps->at(states[act]);
if (img)
bitBlt (this,0,0,
img,0,0,img->width(),img->height(),CopyROP);
}