graphframe.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file graphframe.h
00024  * \version $Id: graphframe.h 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief Graphs a series of send and receive data points
00026  */
00027 
00028 #ifndef _GRAPHFRAME_H
00029 #define _GRAPHFRAME_H
00030 
00031 #include <QApplication>
00032 #include <QDesktopWidget>
00033 #include <QFrame>
00034 #include <QPainter>
00035 #include <QPen>
00036 #include <QList>
00037 
00038 #define HOR_SPC       2   /** Space between data points */
00039 #define SCALE_WIDTH   75  /** Width of the scale */
00040 #define MIN_SCALE     10  /** 10 kB/s is the minimum scale */  
00041 #define SCROLL_STEP   4   /** Horizontal change on graph update */
00042 
00043 #define BACK_COLOR    Qt::black
00044 #define SCALE_COLOR   Qt::green
00045 #define GRID_COLOR    Qt::darkGreen
00046 #define RECV_COLOR    Qt::cyan
00047 #define SEND_COLOR    Qt::yellow
00048 
00049 #define FONT_SIZE     11
00050 
00051 class GraphFrame : public QFrame
00052 {
00053   Q_OBJECT
00054 
00055 public:
00056   /** Default Constructor */
00057   GraphFrame(QWidget *parent = 0);
00058   /** Default Destructor */
00059   ~GraphFrame();
00060   /** Add data points. */
00061   void addPoints(qreal recv, qreal send);
00062   /** Clears the graph. */
00063   void resetGraph();
00064   /** Toggles display of data counters. */
00065   void setShowCounters(bool showRecv, bool showSend);
00066 
00067 protected:
00068   /** Overloaded QWidget::paintEvent() */
00069   void paintEvent(QPaintEvent *event);
00070 
00071 private:
00072   /** Gets the width of the desktop, the max # of points. */
00073   int getNumPoints();
00074   
00075   /** Paints an integral and an outline of that integral for each data set
00076    * (send and/or receive) that is to be displayed. */
00077   void paintData();
00078   /** Paints the send/receive totals. */
00079   void paintTotals();
00080   /** Paints the scale in the graph. */
00081   void paintScale();
00082   /** Returns a formatted string representation of total. */
00083   QString totalToStr(qreal total);
00084   /** Paints a line with the data in list. */
00085   void paintLine(QList<qreal>* list, QColor color, 
00086                  Qt::PenStyle lineStyle = Qt::SolidLine);
00087   /** Paints an integral using the supplied data. */
00088   void paintIntegral(QList<qreal>* list, QColor color, qreal alpha = 1.0);
00089 
00090   /** A QPainter object that handles drawing the various graph elements. */
00091   QPainter* _painter;
00092   /** Holds the received data points. */
00093   QList<qreal> *_recvData;
00094   /** Holds the sent data points. */
00095   QList<qreal> *_sendData;
00096   /** The current dimensions of the graph. */
00097   QRect _rec;
00098   /** The maximum data value plotted. */
00099   qreal _maxValue;
00100   /** The maximum number of points to store. */
00101   int _maxPoints;
00102   /** The total data sent/recv. */
00103   qreal _totalSend;
00104   qreal _totalRecv;
00105   /** Show the respective lines and counters. */
00106   bool _showRecv;
00107   bool _showSend;
00108 };
00109 
00110 #endif

Generated on Mon Oct 23 20:08:16 2006 for Vidalia by  doxygen 1.5.0