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
39class GraphFrame : public QFrame
40{
41 Q_OBJECT
42
43public:
44 /** Bandwidth graph style. */
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 */
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
64protected:
65 /** Overloaded QWidget::paintEvent() */
66 void paintEvent(QPaintEvent *event);
67
68private:
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. */
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. */
113 /** Show the respective lines and counters. */
116 /** Width (in pixels) of the scale marker area on the left side of the
117 * graph. */
119};
120
121#endif
QPainter * _painter
Definition: GraphFrame.h:97
void resizeEvent(QResizeEvent *ev)
Definition: GraphFrame.cpp:347
qreal _maxValue
Definition: GraphFrame.h:105
qreal _totalRecv
Definition: GraphFrame.h:112
bool _showRecv
Definition: GraphFrame.h:114
QList< qreal > * _recvData
Definition: GraphFrame.h:99
int _maxPoints
Definition: GraphFrame.h:109
void paintIntegral(QVector< QPointF > points, QColor color, qreal alpha=1.0)
Definition: GraphFrame.cpp:223
void addPoints(qreal recv, qreal send)
Definition: GraphFrame.cpp:60
void paintData()
Definition: GraphFrame.cpp:169
QRect _rec
Definition: GraphFrame.h:103
GraphFrame(QWidget *parent=0)
Definition: GraphFrame.cpp:22
void resetGraph()
Definition: GraphFrame.cpp:111
void paintLine(QVector< QPointF > points, QColor color, Qt::PenStyle lineStyle=Qt::SolidLine)
Definition: GraphFrame.cpp:236
int getNumPoints()
Definition: GraphFrame.cpp:53
int _scaleWidth
Definition: GraphFrame.h:118
void setShowCounters(bool showRecv, bool showSend)
Definition: GraphFrame.cpp:125
void paintEvent(QPaintEvent *event)
Definition: GraphFrame.cpp:135
QList< qreal > * _sendData
Definition: GraphFrame.h:101
qreal _totalSend
Definition: GraphFrame.h:111
GraphStyle _graphStyle
Definition: GraphFrame.h:95
void paintTotals()
Definition: GraphFrame.cpp:247
bool _showSend
Definition: GraphFrame.h:115
QString totalToStr(qreal total)
Definition: GraphFrame.cpp:278
void paintScale()
Definition: GraphFrame.cpp:308
int _maxPosition
Definition: GraphFrame.h:107
void setGraphStyle(GraphStyle style)
Definition: GraphFrame.h:62
QVector< QPointF > pointsFromData(QList< qreal > *list)
Definition: GraphFrame.cpp:196
int labelWidth(const QString &label)
Definition: GraphFrame.cpp:296