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.cpp50
1 files changed, 39 insertions, 11 deletions
diff --git a/noncore/net/wellenreiter/gui/graphwindow.cpp b/noncore/net/wellenreiter/gui/graphwindow.cpp
index 7e1f378..b116b91 100644
--- a/noncore/net/wellenreiter/gui/graphwindow.cpp
+++ b/noncore/net/wellenreiter/gui/graphwindow.cpp
@@ -26,17 +26,31 @@ MFrequencySpectrum::MFrequencySpectrum( int channels, QWidget* parent, const cha
26 _dirty = new bool[_channels]; 26 _dirty = new bool[_channels];
27 for ( int i = 0; i < channels; ++i ) 27 for ( int i = 0; i < channels; ++i )
28 { _values[i] = 0; 28 { _values[i] = 0;
29 _dirty[i] = true; 29 _dirty[i] = true;
30 } 30 }
31 31
32 // we draw everything alone 32 // we draw everything on our own
33 setBackgroundMode( QWidget::NoBackground ); 33 setBackgroundMode( QWidget::NoBackground );
34} 34}
35 35
36 36
37void MFrequencySpectrum::drawTopLine( QPainter* p, int x, int y, int width, const QColor& c )
38{
39 p->setPen( c.light() );
40 p->drawLine( x, y, x+width-1, y );
41}
42
43
44void MFrequencySpectrum::drawBottomLine( QPainter* p, int x, int y, int width, const QColor& c )
45{
46 p->setPen( c.dark() );
47 p->drawLine( x, y, x+width-1, y );
48}
49
50
37void MFrequencySpectrum::drawLine( QPainter* p, int x, int y, int width, const QColor& c ) 51void MFrequencySpectrum::drawLine( QPainter* p, int x, int y, int width, const QColor& c )
38{ 52{
39 p->setPen( c.light() ); 53 p->setPen( c.light() );
40 p->drawPoint( x++, y ); 54 p->drawPoint( x++, y );
41 p->setPen( c ); 55 p->setPen( c );
42 p->drawLine( x, y, x+width-2, y ); 56 p->drawLine( x, y, x+width-2, y );
@@ -58,18 +72,19 @@ void MFrequencySpectrum::drawBar( QPainter* p, int x, int y, int width, int heig
58 QColor c( 120, 60, 200 ); 72 QColor c( 120, 60, 200 );
59 for ( int i = 0; i < height; ++i ) 73 for ( int i = 0; i < height; ++i )
60 { 74 {
61 int h = (h2-h1)*i/maxheight + h1; 75 int h = (h2-h1)*i/maxheight + h1;
62 int s = (s2-s1)*i/maxheight + s1; 76 int s = (s2-s1)*i/maxheight + s1;
63 int v = (v2-v1)*i/maxheight + v1; 77 int v = (v2-v1)*i/maxheight + v1;
64 drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) ); 78 if ( i == 0 )
79 drawBottomLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
80 else if ( i == height-1 )
81 drawTopLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
82 else
83 drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
65 } 84 }
66
67 /*for ( int i = height; i < maxheight; ++i )
68 drawLine( p, x, y-i, width, QColor( 47, 68, 76 ) );*/
69
70} 85}
71 86
72 87
73void MFrequencySpectrum::paintEvent( QPaintEvent* e ) 88void MFrequencySpectrum::paintEvent( QPaintEvent* e )
74{ 89{
75 QPixmap pm( size() ); 90 QPixmap pm( size() );
@@ -95,12 +110,28 @@ void MFrequencySpectrum::paintEvent( QPaintEvent* e )
95 110
96 p.end(); 111 p.end();
97 bitBlt( this, 0, 0, &pm ); 112 bitBlt( this, 0, 0, &pm );
98} 113}
99 114
100 115
116void MFrequencySpectrum::mousePressEvent( QMouseEvent* e )
117{
118 int xmargin = 5;
119 int ymargin = 2;
120 int y = size().height() - 2 * ymargin;
121 int x = 0;
122 int width = ( size().width() - 2 * xmargin ) / _channels;
123
124 QPoint pos = e->pos();
125 int channel = ( pos.x()-xmargin ) / width;
126 int height = 100 - ( pos.y()-ymargin )*100/y;
127 if ( channel < 15 ) _values[channel] = height;
128
129}
130
131
101Legende::Legende( int channels, QWidget* parent, const char* name, WFlags f ) 132Legende::Legende( int channels, QWidget* parent, const char* name, WFlags f )
102 :QFrame( parent, name, f ), _channels( channels ) 133 :QFrame( parent, name, f ), _channels( channels )
103{ 134{
104 setLineWidth( 2 ); 135 setLineWidth( 2 );
105 setFrameStyle( Panel + Sunken ); 136 setFrameStyle( Panel + Sunken );
106 setFixedHeight( 16 ); 137 setFixedHeight( 16 );
@@ -122,16 +153,13 @@ void Legende::drawContents( QPainter* p )
122 153
123MGraphWindow::MGraphWindow( QWidget* parent, const char* name, WFlags f ) 154MGraphWindow::MGraphWindow( QWidget* parent, const char* name, WFlags f )
124 :QVBox( parent, name, f ) 155 :QVBox( parent, name, f )
125{ 156{
126 spectrum = new MFrequencySpectrum( 14, this ); 157 spectrum = new MFrequencySpectrum( 14, this );
127 legende = new Legende( 14, this ); 158 legende = new Legende( 14, this );
128 startTimer( 50 ); //FIXME: tweak 159 startTimer( 50 );
129
130 //testGraph();
131
132}; 160};
133 161
134 162
135void MGraphWindow::testGraph() 163void MGraphWindow::testGraph()
136{ 164{
137 static int i = 0; 165 static int i = 0;
@@ -143,13 +171,13 @@ void MGraphWindow::testGraph()
143 171
144 172
145void MGraphWindow::timerEvent( QTimerEvent* e ) 173void MGraphWindow::timerEvent( QTimerEvent* e )
146{ 174{
147 for ( int i = 0; i < 14; i++ ) 175 for ( int i = 0; i < 14; i++ )
148 { 176 {
149 spectrum->decrease( i, 1 ); //TODO: make this customizable? 177 spectrum->decrease( i, 1 );
150 } 178 }
151 spectrum->repaint(); 179 spectrum->repaint();
152} 180}
153 181
154 182
155void MGraphWindow::traffic( int channel, int signal ) 183void MGraphWindow::traffic( int channel, int signal )