Vidalia 0.2.12
|
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 ** \brief Graphs a series of send and receive data points 00014 */ 00015 00016 #ifndef _GRAPHFRAME_H 00017 #define _GRAPHFRAME_H 00018 00019 #include <QApplication> 00020 #include <QDesktopWidget> 00021 #include <QFrame> 00022 #include <QPainter> 00023 #include <QPen> 00024 #include <QList> 00025 00026 #define HOR_SPC 2 /** Space between data points */ 00027 #define MIN_SCALE 10 /** 10 kB/s is the minimum scale */ 00028 #define SCROLL_STEP 4 /** Horizontal change on graph update */ 00029 00030 #define BACK_COLOR Qt::black 00031 #define SCALE_COLOR Qt::green 00032 #define GRID_COLOR Qt::darkGreen 00033 #define RECV_COLOR Qt::cyan 00034 #define SEND_COLOR Qt::yellow 00035 00036 #define FONT_SIZE 11 00037 00038 00039 class GraphFrame : public QFrame 00040 { 00041 Q_OBJECT 00042 00043 public: 00044 /** Bandwidth graph style. */ 00045 enum GraphStyle { 00046 SolidLine = 0, /**< Plot bandwidth as solid lines. */ 00047 AreaGraph /**< Plot bandwidth as alpha blended area graphs. */ 00048 }; 00049 00050 /** Default Constructor */ 00051 GraphFrame(QWidget *parent = 0); 00052 /** Default Destructor */ 00053 ~GraphFrame(); 00054 00055 /** Add data points. */ 00056 void addPoints(qreal recv, qreal send); 00057 /** Clears the graph. */ 00058 void resetGraph(); 00059 /** Toggles display of data counters. */ 00060 void setShowCounters(bool showRecv, bool showSend); 00061 /** Sets the graph style used to display bandwidth data. */ 00062 void setGraphStyle(GraphStyle style) { _graphStyle = style; } 00063 00064 protected: 00065 /** Overloaded QWidget::paintEvent() */ 00066 void paintEvent(QPaintEvent *event); 00067 00068 private: 00069 /** Returns the width in pixels of <b>label</b> using the current painter's 00070 * font. */ 00071 int labelWidth(const QString &label); 00072 /** Gets the width of the desktop, the max # of points. */ 00073 int getNumPoints(); 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 /** Width (in pixels) of the scale marker area on the left side of the 00113 * graph. */ 00114 int _scaleWidth; 00115 }; 00116 00117 #endif