graphframe.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file graphframe.h
00013 ** \version $Id: graphframe.h 2980 2008-08-17 04:14:25Z edmanm $
00014 ** \brief Graphs a series of send and receive data points
00015 */
00016 
00017 #ifndef _GRAPHFRAME_H
00018 #define _GRAPHFRAME_H
00019 
00020 #include <QApplication>
00021 #include <QDesktopWidget>
00022 #include <QFrame>
00023 #include <QPainter>
00024 #include <QPen>
00025 #include <QList>
00026 
00027 #define HOR_SPC       2   /** Space between data points */
00028 #define MIN_SCALE     10  /** 10 kB/s is the minimum scale */
00029 #define SCROLL_STEP   4   /** Horizontal change on graph update */
00030 
00031 #define BACK_COLOR    Qt::black
00032 #define SCALE_COLOR   Qt::green
00033 #define GRID_COLOR    Qt::darkGreen
00034 #define RECV_COLOR    Qt::cyan
00035 #define SEND_COLOR    Qt::yellow
00036 
00037 #define FONT_SIZE     11
00038 
00039 
00040 class GraphFrame : public QFrame
00041 {
00042   Q_OBJECT
00043 
00044 public:
00045   /** Bandwidth graph style. */
00046   enum GraphStyle {
00047     SolidLine = 0,  /**< Plot bandwidth as solid lines. */
00048     AreaGraph       /**< Plot bandwidth as alpha blended area graphs. */
00049   };
00050   
00051   /** Default Constructor */
00052   GraphFrame(QWidget *parent = 0);
00053   /** Default Destructor */
00054   ~GraphFrame();
00055 
00056   /** Add data points. */
00057   void addPoints(qreal recv, qreal send);
00058   /** Clears the graph. */
00059   void resetGraph();
00060   /** Toggles display of data counters. */
00061   void setShowCounters(bool showRecv, bool showSend);
00062   /** Sets the graph style used to display bandwidth data. */
00063   void setGraphStyle(GraphStyle style) { _graphStyle = style; }
00064 
00065 protected:
00066   /** Overloaded QWidget::paintEvent() */
00067   void paintEvent(QPaintEvent *event);
00068 
00069 private:
00070   /** Returns the width in pixels of <b>label</b> using the current painter's
00071    * font. */
00072   int labelWidth(const QString &label);
00073   /** Gets the width of the desktop, the max # of points. */
00074   int getNumPoints();
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   /** Returns a list of points on the bandwidth graph based on the supplied set
00085    * of send or receive values. */
00086   QVector<QPointF> pointsFromData(QList<qreal>* list);
00087   /** Paints a line with the data in <b>points</b>. */
00088   void paintLine(QVector<QPointF> points, QColor color, 
00089                  Qt::PenStyle lineStyle = Qt::SolidLine);
00090   /** Paints an integral using the supplied data. */
00091   void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0);
00092 
00093   /** Style with which the bandwidth data will be graphed. */
00094   GraphStyle _graphStyle;
00095   /** A QPainter object that handles drawing the various graph elements. */
00096   QPainter* _painter;
00097   /** Holds the received data points. */
00098   QList<qreal> *_recvData;
00099   /** Holds the sent data points. */
00100   QList<qreal> *_sendData;
00101   /** The current dimensions of the graph. */
00102   QRect _rec;
00103   /** The maximum data value plotted. */
00104   qreal _maxValue;
00105   /** The maximum number of points to store. */
00106   int _maxPoints;
00107   /** The total data sent/recv. */
00108   qreal _totalSend;
00109   qreal _totalRecv;
00110   /** Show the respective lines and counters. */
00111   bool _showRecv;
00112   bool _showSend;
00113   /** Width (in pixels) of the scale marker area on the left side of the
00114    * graph. */
00115   int _scaleWidth;
00116 };
00117 
00118 #endif

Generated on Wed Dec 23 21:06:55 2009 for Vidalia by  doxygen 1.6.1