summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/graphwindow.cpp
Side-by-side diff
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
_dirty = new bool[_channels];
for ( int i = 0; i < channels; ++i )
{ _values[i] = 0;
_dirty[i] = true;
}
- // we draw everything alone
+ // we draw everything on our own
setBackgroundMode( QWidget::NoBackground );
}
+void MFrequencySpectrum::drawTopLine( QPainter* p, int x, int y, int width, const QColor& c )
+{
+ p->setPen( c.light() );
+ p->drawLine( x, y, x+width-1, y );
+}
+
+
+void MFrequencySpectrum::drawBottomLine( QPainter* p, int x, int y, int width, const QColor& c )
+{
+ p->setPen( c.dark() );
+ p->drawLine( x, y, x+width-1, y );
+}
+
+
void MFrequencySpectrum::drawLine( QPainter* p, int x, int y, int width, const QColor& c )
{
p->setPen( c.light() );
p->drawPoint( x++, y );
p->setPen( c );
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
QColor c( 120, 60, 200 );
for ( int i = 0; i < height; ++i )
{
int h = (h2-h1)*i/maxheight + h1;
int s = (s2-s1)*i/maxheight + s1;
int v = (v2-v1)*i/maxheight + v1;
- drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
+ if ( i == 0 )
+ drawBottomLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
+ else if ( i == height-1 )
+ drawTopLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
+ else
+ drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) );
}
-
- /*for ( int i = height; i < maxheight; ++i )
- drawLine( p, x, y-i, width, QColor( 47, 68, 76 ) );*/
-
}
void MFrequencySpectrum::paintEvent( QPaintEvent* e )
{
QPixmap pm( size() );
@@ -95,12 +110,28 @@ void MFrequencySpectrum::paintEvent( QPaintEvent* e )
p.end();
bitBlt( this, 0, 0, &pm );
}
+void MFrequencySpectrum::mousePressEvent( QMouseEvent* e )
+{
+ int xmargin = 5;
+ int ymargin = 2;
+ int y = size().height() - 2 * ymargin;
+ int x = 0;
+ int width = ( size().width() - 2 * xmargin ) / _channels;
+
+ QPoint pos = e->pos();
+ int channel = ( pos.x()-xmargin ) / width;
+ int height = 100 - ( pos.y()-ymargin )*100/y;
+ if ( channel < 15 ) _values[channel] = height;
+
+}
+
+
Legende::Legende( int channels, QWidget* parent, const char* name, WFlags f )
:QFrame( parent, name, f ), _channels( channels )
{
setLineWidth( 2 );
setFrameStyle( Panel + Sunken );
setFixedHeight( 16 );
@@ -122,16 +153,13 @@ void Legende::drawContents( QPainter* p )
MGraphWindow::MGraphWindow( QWidget* parent, const char* name, WFlags f )
:QVBox( parent, name, f )
{
spectrum = new MFrequencySpectrum( 14, this );
legende = new Legende( 14, this );
- startTimer( 50 ); //FIXME: tweak
-
- //testGraph();
-
+ startTimer( 50 );
};
void MGraphWindow::testGraph()
{
static int i = 0;
@@ -143,13 +171,13 @@ void MGraphWindow::testGraph()
void MGraphWindow::timerEvent( QTimerEvent* e )
{
for ( int i = 0; i < 14; i++ )
{
- spectrum->decrease( i, 1 ); //TODO: make this customizable?
+ spectrum->decrease( i, 1 );
}
spectrum->repaint();
}
void MGraphWindow::traffic( int channel, int signal )