summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/graphwindow.cpp
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/gui/graphwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/graphwindow.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/gui/graphwindow.cpp b/noncore/net/wellenreiter/gui/graphwindow.cpp
new file mode 100644
index 0000000..c620fe2
--- a/dev/null
+++ b/noncore/net/wellenreiter/gui/graphwindow.cpp
@@ -0,0 +1,159 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3**
4** This file is part of Opie Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#include "graphwindow.h"
17
18#include <qpainter.h>
19#include <qpixmap.h>
20#include <qtimer.h>
21
22MFrequencySpectrum::MFrequencySpectrum( int channels, QWidget* parent, const char* name, WFlags f)
23 :QWidget( parent, name,f ), _channels( channels )
24{
25 _values = new int[_channels];
26 _dirty = new bool[_channels];
27 for ( int i = 0; i < channels; ++i )
28 { _values[i] = 0;
29 _dirty[i] = true;
30 }
31
32 // we draw everything alone
33 setBackgroundMode( QWidget::NoBackground );
34}
35
36
37void MFrequencySpectrum::drawLine( QPainter* p, int x, int y, int width, const QColor& c )
38{
39 p->setPen( c.light() );
40 p->drawPoint( x++, y );
41 p->setPen( c );
42 p->drawLine( x, y, x+width-2, y );
43 p->setPen( c.dark() );
44 p->drawPoint( x+width-1, y );
45}
46
47
48void MFrequencySpectrum::drawBar( QPainter* p, int x, int y, int width, int height, int maxheight )
49{
50/* int h1 = 133; int h2 = 0;
51 int s1 = 200; int s2 = 255;
52 int v1 = 140; int v2 = 255; */
53
54 int h1 = 196; int h2 = 194;
55 int s1 = 85; int s2 = 15;
56 int v1 = 95; int v2 = 237;
57
58 QColor c( 120, 60, 200 );
59 for ( int i = 0; i < height; ++i )
60 {
61 int h = (h2-h1)*i/maxheight + h1;
62 int s = (s2-s1)*i/maxheight + s1;
63 int v = (v2-v1)*i/maxheight + v1;
64 drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
65 }
66
67 /*for ( int i = height; i < maxheight; ++i )
68 drawLine( p, x, y-i, width, QColor( 47, 68, 76 ) );*/
69
70}
71
72
73void MFrequencySpectrum::paintEvent( QPaintEvent* e )
74{
75 QPixmap pm( size() );
76 QPainter p;
77 p.begin( &pm );
78 p.drawTiledPixmap( 0, 0, size().width(), size().height(), QPixmap( (const char**) &background ) );
79
80 int xmargin = 5;
81 int ymargin = 2;
82 int y = size().height() - 2 * ymargin;
83 int x = 0;
84 int width = ( size().width() - 2 * xmargin ) / _channels;
85
86 for ( int i = 0; i < _channels; ++i )
87 {
88 if ( _dirty[i] )
89 {
90 drawBar( &p, xmargin + x, y - ymargin, width-3, _values[i]*y/100, y );
91 _dirty[i] = false;
92 }
93 x+= width;
94 }
95
96 p.end();
97 bitBlt( this, 0, 0, &pm );
98}
99
100
101Legende::Legende( int channels, QWidget* parent, const char* name, WFlags f )
102 :QFrame( parent, name, f ), _channels( channels )
103{
104 setLineWidth( 2 );
105 setFrameStyle( Panel + Sunken );
106 setFixedHeight( 16 );
107
108}
109
110
111void Legende::drawContents( QPainter* p )
112{
113 int xmargin = 5;
114 int ymargin = 2;
115 int x = 0;
116 int width = ( contentsRect().width() - 2 * xmargin ) / _channels;
117
118 for ( int i = 0; i < _channels; ++i )
119 p->drawText( xmargin + (width*i), 12, QString().sprintf( "%02d", i+1 ) );
120}
121
122
123MGraphWindow::MGraphWindow( QWidget* parent, const char* name, WFlags f )
124 :QVBox( parent, name, f )
125{
126 spectrum = new MFrequencySpectrum( 14, this );
127 legende = new Legende( 14, this );
128 startTimer( 50 );
129
130 //testGraph();
131
132};
133
134
135void MGraphWindow::testGraph()
136{
137 static int i = 0;
138 spectrum->setValue( i++, 100 );
139 if ( i == 14 ) i = 0;
140 QTimer::singleShot( 2000, this, SLOT( testGraph() ) );
141
142}
143
144
145void MGraphWindow::timerEvent( QTimerEvent* e )
146{
147 for ( int i = 0; i < 14; i++ )
148 {
149 spectrum->decrease( i, 4 );
150 }
151 spectrum->repaint();
152}
153
154
155void MGraphWindow::traffic( int channel, int signal )
156{
157 spectrum->setValue( channel-1, signal );
158}
159