Vidalia  0.3.1
GraphFrame.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file GraphFrame.h
13 ** \brief Graphs a series of send and receive data points
14 */
15 
16 #ifndef _GRAPHFRAME_H
17 #define _GRAPHFRAME_H
18 
19 #include <QApplication>
20 #include <QDesktopWidget>
21 #include <QFrame>
22 #include <QPainter>
23 #include <QPen>
24 #include <QList>
25 
26 #define HOR_SPC 2 /** Space between data points */
27 #define MIN_SCALE 10 /** 10 kB/s is the minimum scale */
28 #define SCROLL_STEP 4 /** Horizontal change on graph update */
29 
30 #define BACK_COLOR Qt::black
31 #define SCALE_COLOR Qt::green
32 #define GRID_COLOR Qt::darkGreen
33 #define RECV_COLOR Qt::cyan
34 #define SEND_COLOR Qt::yellow
35 
36 #define FONT_SIZE 11
37 
38 
39 class GraphFrame : public QFrame
40 {
41  Q_OBJECT
42 
43 public:
44  /** Bandwidth graph style. */
45  enum GraphStyle {
46  SolidLine = 0, /**< Plot bandwidth as solid lines. */
47  AreaGraph /**< Plot bandwidth as alpha blended area graphs. */
48  };
49 
50  /** Default Constructor */
51  GraphFrame(QWidget *parent = 0);
52  /** Default Destructor */
53  ~GraphFrame();
54 
55  /** Add data points. */
56  void addPoints(qreal recv, qreal send);
57  /** Clears the graph. */
58  void resetGraph();
59  /** Toggles display of data counters. */
60  void setShowCounters(bool showRecv, bool showSend);
61  /** Sets the graph style used to display bandwidth data. */
62  void setGraphStyle(GraphStyle style) { _graphStyle = style; }
63 
64 protected:
65  /** Overloaded QWidget::paintEvent() */
66  void paintEvent(QPaintEvent *event);
67 
68 private:
69  /** Returns the width in pixels of <b>label</b> using the current painter's
70  * font. */
71  int labelWidth(const QString &label);
72  /** Gets the width of the desktop, the max # of points. */
73  int getNumPoints();
74  /** Paints an integral and an outline of that integral for each data set
75  * (send and/or receive) that is to be displayed. */
76  void paintData();
77  /** Paints the send/receive totals. */
78  void paintTotals();
79  /** Paints the scale in the graph. */
80  void paintScale();
81  /** Returns a formatted string representation of total. */
82  QString totalToStr(qreal total);
83  /** Returns a list of points on the bandwidth graph based on the supplied set
84  * of send or receive values. */
85  QVector<QPointF> pointsFromData(QList<qreal>* list);
86  /** Paints a line with the data in <b>points</b>. */
87  void paintLine(QVector<QPointF> points, QColor color,
88  Qt::PenStyle lineStyle = Qt::SolidLine);
89  /** Paints an integral using the supplied data. */
90  void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0);
91 
92  void resizeEvent(QResizeEvent *ev);
93 
94  /** Style with which the bandwidth data will be graphed. */
96  /** A QPainter object that handles drawing the various graph elements. */
97  QPainter* _painter;
98  /** Holds the received data points. */
99  QList<qreal> *_recvData;
100  /** Holds the sent data points. */
101  QList<qreal> *_sendData;
102  /** The current dimensions of the graph. */
103  QRect _rec;
104  /** The maximum data value plotted. */
105  qreal _maxValue;
106  /** The position of the local maximum in the displayed bandwidth */
108  /** The maximum number of points to store. */
110  /** The total data sent/recv. */
111  qreal _totalSend;
112  qreal _totalRecv;
113  /** Show the respective lines and counters. */
114  bool _showRecv;
115  bool _showSend;
116  /** Width (in pixels) of the scale marker area on the left side of the
117  * graph. */
119 };
120 
121 #endif
GraphFrame::_showRecv
bool _showRecv
Definition: GraphFrame.h:114
GraphFrame::_totalSend
qreal _totalSend
Definition: GraphFrame.h:111
GraphFrame::setShowCounters
void setShowCounters(bool showRecv, bool showSend)
Definition: GraphFrame.cpp:125
GraphFrame::getNumPoints
int getNumPoints()
Definition: GraphFrame.cpp:53
GraphFrame::paintLine
void paintLine(QVector< QPointF > points, QColor color, Qt::PenStyle lineStyle=Qt::SolidLine)
Definition: GraphFrame.cpp:236
GraphFrame::_showSend
bool _showSend
Definition: GraphFrame.h:115
GraphFrame::setGraphStyle
void setGraphStyle(GraphStyle style)
Definition: GraphFrame.h:62
GraphFrame::_recvData
QList< qreal > * _recvData
Definition: GraphFrame.h:99
GraphFrame::_scaleWidth
int _scaleWidth
Definition: GraphFrame.h:118
GraphFrame::_painter
QPainter * _painter
Definition: GraphFrame.h:97
GraphFrame::pointsFromData
QVector< QPointF > pointsFromData(QList< qreal > *list)
Definition: GraphFrame.cpp:196
GraphFrame::~GraphFrame
~GraphFrame()
Definition: GraphFrame.cpp:43
GraphFrame::paintIntegral
void paintIntegral(QVector< QPointF > points, QColor color, qreal alpha=1.0)
Definition: GraphFrame.cpp:223
GraphFrame::addPoints
void addPoints(qreal recv, qreal send)
Definition: GraphFrame.cpp:60
GraphFrame::GraphStyle
GraphStyle
Definition: GraphFrame.h:45
GraphFrame::_maxValue
qreal _maxValue
Definition: GraphFrame.h:105
GraphFrame::_rec
QRect _rec
Definition: GraphFrame.h:103
GraphFrame::_totalRecv
qreal _totalRecv
Definition: GraphFrame.h:112
GraphFrame::totalToStr
QString totalToStr(qreal total)
Definition: GraphFrame.cpp:278
GraphFrame::AreaGraph
@ AreaGraph
Definition: GraphFrame.h:47
GraphFrame::paintScale
void paintScale()
Definition: GraphFrame.cpp:308
GraphFrame::SolidLine
@ SolidLine
Definition: GraphFrame.h:46
GraphFrame::_sendData
QList< qreal > * _sendData
Definition: GraphFrame.h:101
GraphFrame::labelWidth
int labelWidth(const QString &label)
Definition: GraphFrame.cpp:296
GraphFrame::resetGraph
void resetGraph()
Definition: GraphFrame.cpp:111
GraphFrame::_graphStyle
GraphStyle _graphStyle
Definition: GraphFrame.h:95
GraphFrame::_maxPoints
int _maxPoints
Definition: GraphFrame.h:109
GraphFrame::resizeEvent
void resizeEvent(QResizeEvent *ev)
Definition: GraphFrame.cpp:347
GraphFrame::paintEvent
void paintEvent(QPaintEvent *event)
Definition: GraphFrame.cpp:135
GraphFrame::GraphFrame
GraphFrame(QWidget *parent=0)
Definition: GraphFrame.cpp:22
GraphFrame
Definition: GraphFrame.h:39
GraphFrame::paintData
void paintData()
Definition: GraphFrame.cpp:169
GraphFrame::paintTotals
void paintTotals()
Definition: GraphFrame.cpp:247
GraphFrame::_maxPosition
int _maxPosition
Definition: GraphFrame.h:107