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 2362 2008-02-29 04:30:11Z 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 SCALE_WIDTH 75 /** Width of the scale */ 00029 #define MIN_SCALE 10 /** 10 kB/s is the minimum scale */ 00030 #define SCROLL_STEP 4 /** Horizontal change on graph update */ 00031 00032 #define BACK_COLOR Qt::black 00033 #define SCALE_COLOR Qt::green 00034 #define GRID_COLOR Qt::darkGreen 00035 #define RECV_COLOR Qt::cyan 00036 #define SEND_COLOR Qt::yellow 00037 00038 #define FONT_SIZE 11 00039 00040 00041 class GraphFrame : public QFrame 00042 { 00043 Q_OBJECT 00044 00045 public: 00046 /** Bandwidth graph style. */ 00047 enum GraphStyle { 00048 SolidLine = 0, /**< Plot bandwidth as solid lines. */ 00049 AreaGraph /**< Plot bandwidth as alpha blended area graphs. */ 00050 }; 00051 00052 /** Default Constructor */ 00053 GraphFrame(QWidget *parent = 0); 00054 /** Default Destructor */ 00055 ~GraphFrame(); 00056 00057 /** Add data points. */ 00058 void addPoints(qreal recv, qreal send); 00059 /** Clears the graph. */ 00060 void resetGraph(); 00061 /** Toggles display of data counters. */ 00062 void setShowCounters(bool showRecv, bool showSend); 00063 /** Sets the graph style used to display bandwidth data. */ 00064 void setGraphStyle(GraphStyle style) { _graphStyle = style; } 00065 00066 protected: 00067 /** Overloaded QWidget::paintEvent() */ 00068 void paintEvent(QPaintEvent *event); 00069 00070 private: 00071 /** Gets the width of the desktop, the max # of points. */ 00072 int getNumPoints(); 00073 00074 /** Paints an integral and an outline of that integral for each data set 00075 * (send and/or receive) that is to be displayed. */ 00076 void paintData(); 00077 /** Paints the send/receive totals. */ 00078 void paintTotals(); 00079 /** Paints the scale in the graph. */ 00080 void paintScale(); 00081 /** Returns a formatted string representation of total. */ 00082 QString totalToStr(qreal total); 00083 /** Returns a list of points on the bandwidth graph based on the supplied set 00084 * of send or receive values. */ 00085 QVector<QPointF> pointsFromData(QList<qreal>* list); 00086 /** Paints a line with the data in <b>points</b>. */ 00087 void paintLine(QVector<QPointF> points, QColor color, 00088 Qt::PenStyle lineStyle = Qt::SolidLine); 00089 /** Paints an integral using the supplied data. */ 00090 void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0); 00091 00092 /** Style with which the bandwidth data will be graphed. */ 00093 GraphStyle _graphStyle; 00094 /** A QPainter object that handles drawing the various graph elements. */ 00095 QPainter* _painter; 00096 /** Holds the received data points. */ 00097 QList<qreal> *_recvData; 00098 /** Holds the sent data points. */ 00099 QList<qreal> *_sendData; 00100 /** The current dimensions of the graph. */ 00101 QRect _rec; 00102 /** The maximum data value plotted. */ 00103 qreal _maxValue; 00104 /** The maximum number of points to store. */ 00105 int _maxPoints; 00106 /** The total data sent/recv. */ 00107 qreal _totalSend; 00108 qreal _totalRecv; 00109 /** Show the respective lines and counters. */ 00110 bool _showRecv; 00111 bool _showSend; 00112 }; 00113 00114 #endif