Diffstat (limited to 'noncore/applets/wirelessapplet/mgraph.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/wirelessapplet/mgraph.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/noncore/applets/wirelessapplet/mgraph.cpp b/noncore/applets/wirelessapplet/mgraph.cpp new file mode 100644 index 0000000..b4b86b0 --- a/dev/null +++ b/noncore/applets/wirelessapplet/mgraph.cpp | |||
@@ -0,0 +1,71 @@ | |||
1 | /********************************************************************** | ||
2 | ** MGraph | ||
3 | ** | ||
4 | ** A reusable graph widget. | ||
5 | ** | ||
6 | ** Copyright (C) 2002, Michael Lauer | ||
7 | ** mickey@tm.informatik.uni-frankfurt.de | ||
8 | ** http://www.Vanille.de | ||
9 | ** | ||
10 | ** This file may be distributed and/or modified under the terms of the | ||
11 | ** GNU General Public License version 2 as published by the Free Software | ||
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
13 | ** packaging of this file. | ||
14 | ** | ||
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | ** | ||
18 | **********************************************************************/ | ||
19 | |||
20 | #include "mgraph.h" | ||
21 | #include "graphbackground.xpm" | ||
22 | #include <qpainter.h> | ||
23 | #include <qpixmap.h> | ||
24 | |||
25 | //--------------------------------------------------------------------------- | ||
26 | |||
27 | MGraph::MGraph( QWidget *parent, const char *name, WFlags f ) | ||
28 | : QFrame( parent, name, f ), min( 0 ), max( 0), values( 0 ) | ||
29 | { | ||
30 | background = new QPixmap( (const char** ) graphbackground_xpm ); | ||
31 | values = new ValueList(); | ||
32 | } | ||
33 | |||
34 | void MGraph::setFrameStyle( int style ) | ||
35 | { | ||
36 | QFrame::setFrameStyle( style ); | ||
37 | setFixedSize( background->width() + frameWidth()*2, background->height() + frameWidth()*2 ); | ||
38 | } | ||
39 | |||
40 | void MGraph::addValue( int value, bool followMax ) | ||
41 | { | ||
42 | values->append( value ); | ||
43 | if ( followMax && (value > max) ) | ||
44 | setMax( value ); | ||
45 | if ( values->count() == background->width()-2 ) // compensate for graph display element border | ||
46 | values->remove( values->begin() ); | ||
47 | repaint( false ); | ||
48 | } | ||
49 | |||
50 | void MGraph::drawContents( QPainter* p ) | ||
51 | { | ||
52 | p->drawPixmap( frameWidth(), frameWidth(), (const QPixmap&) *background ); | ||
53 | p->setPen( QColor( 40, 235, 40 ) ); | ||
54 | |||
55 | int x = frameWidth() + 2; // compensate for graph display element border | ||
56 | int y = 0; | ||
57 | |||
58 | ValueList::ConstIterator it; | ||
59 | for ( it = values->begin(); it != values->end(); ++it ) | ||
60 | { | ||
61 | y = frameWidth() + background->height() -3 - ( ( *(it)*(background->height()-4 ) /max ) ); | ||
62 | p->drawPoint( x++, y ); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | MGraph::~MGraph() | ||
67 | { | ||
68 | delete background; | ||
69 | delete values; | ||
70 | } | ||
71 | |||