Fairly large overhaul of the JuK codebase to beat out a lot of the Qt 3 stuff.
[kdemultimedia.git] / kmid / rhythmview.cpp
blobb8cdddba198ad933155167cf5af1850371a24a31
1 /**************************************************************************
3 rhythmview.cpp - The RhythmView widget
4 Copyright (C) 1998 Antonio Larrosa Jimenez
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 Send comments and bug fixes to larrosa@kde.org
21 or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
23 ***************************************************************************/
24 #include "rhythmview.h"
25 //Added by qt3to4:
26 #include <QResizeEvent>
28 RhythmView::RhythmView (QWidget *parent, const char *name) : QWidget(parent)
30 setObjectName(name);
31 lamps=NULL;
32 setRhythm(4,4);
35 RhythmView::~RhythmView()
37 if (lamps!=NULL)
39 for (int i=0;i<num;i++) delete lamps[i];
40 delete [] lamps;
41 lamps=NULL;
45 void RhythmView::setRhythm(int numerator,int denominator)
47 int i;
48 if (lamps!=NULL)
50 for (i=0;i<num;i++) delete lamps[i];
51 delete [] lamps;
52 lamps=NULL;
54 num=numerator;
55 den=denominator;
57 lamps=new KLed *[num];
58 int w=width()/num;
59 int x=0;
61 for (i=0;i<num;i++)
63 lamps[i]=new KLed(Qt::yellow, KLed::Off, KLed::Sunken, KLed::Rectangular, this);
64 // lamps[i]->setState(KLed::Off);
65 lamps[i]->setGeometry(x+2,0,w-4,height());
66 lamps[i]->show();
67 x+=w;
69 // lamps[0]->setState(KLed::On);
73 void RhythmView::Beat(int j)
75 if (j>num) setRhythm(j,4); // This is a preventive case
77 for (int i=0;i<num;i++)
79 lamps[i]->off();
81 lamps[j-1]->on();
84 void RhythmView::Beat(void)
89 void RhythmView::resizeEvent(QResizeEvent *)
91 int w=width()/num;
92 int x=0;
94 for (int i=0;i<num;i++)
96 lamps[i]->setGeometry(x+2,0,w-4,height());
97 x+=w;
101 QSize RhythmView::sizeHint() const
103 return QSize(10,10);
106 QSizePolicy RhythmView::sizePolicy()
108 // return QWidget::sizePolicy();
109 return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);