mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Used RSGraphWidget for bandwidth window too; Cleaned up remaining unused graph classes; Added a few missing params to RSGraphWidget; End of graph work.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7616 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
bd688f0156
commit
1f1c51b7d3
@ -52,7 +52,7 @@
|
||||
#include "ChatLobbyWidget.h"
|
||||
#include "HelpDialog.h"
|
||||
#include "AboutDialog.h"
|
||||
#include "bwgraph/bwgraph.h"
|
||||
#include "bwgraph/BandwidthGraphWindow.h"
|
||||
#include "help/browser/helpbrowser.h"
|
||||
#include "chat/ChatDialog.h"
|
||||
#include "RetroShareLink.h"
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <rshare.h>
|
||||
#include <control/bandwidthevent.h>
|
||||
#include "bwgraph.h"
|
||||
#include <gui/bwgraph/BandwidthGraphWindow.h>
|
||||
#include <retroshare-gui/RsAutoUpdatePage.h>
|
||||
#include <retroshare/rsconfig.h>
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#define DEFAULT_FILTER (BWGRAPH_LINE_SEND|BWGRAPH_LINE_RECV)
|
||||
#define DEFAULT_ALWAYS_ON_TOP false
|
||||
#define DEFAULT_OPACITY 100
|
||||
#define DEFAULT_STYLE GraphFrame::AreaGraph
|
||||
#define DEFAULT_STYLE LineGraph
|
||||
|
||||
#define ADD_TO_FILTER(f,v,b) (f = ((b) ? ((f) | (v)) : ((f) & ~(v))))
|
||||
|
||||
@ -77,86 +77,27 @@ BandwidthGraph::BandwidthGraph(QWidget *parent, Qt::WindowFlags flags)
|
||||
/* Load the previously saved settings */
|
||||
loadSettings();
|
||||
|
||||
/* Turn off opacity group on unsupported platforms */
|
||||
#if defined(Q_WS_WIN)
|
||||
if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion && QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) {
|
||||
ui.frmOpacity->setVisible(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
ui.frmOpacity->setVisible(false);
|
||||
#endif
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updategraphstatus()));
|
||||
timer->start(BWGRAPH_REFRESH_RATE);
|
||||
}
|
||||
|
||||
/** Custom event handler. Checks if the event is a bandwidth update event. If it
|
||||
* is, it will add the data point to the history and updates the graph. */
|
||||
void
|
||||
BandwidthGraph::customEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == CustomEventType::BandwidthEvent) {
|
||||
BandwidthEvent *bw = (BandwidthEvent *)event;
|
||||
updateGraph(bw->bytesRead(), bw->bytesWritten());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BandwidthGraph::timerEvent( QTimerEvent * )
|
||||
{
|
||||
/* set users/friends/network */
|
||||
/*float downKb = 0;
|
||||
float upKb = 0;
|
||||
rsConfig->GetCurrentDataRates(downKb, upKb);
|
||||
|
||||
updateGraph(downKb,upKb);*/
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
BandwidthGraph::updategraphstatus( )
|
||||
{
|
||||
if(RsAutoUpdatePage::eventsLocked())
|
||||
return ;
|
||||
|
||||
/* set users/friends/network */
|
||||
float downKb = 0;
|
||||
float upKb = 0;
|
||||
rsConfig->GetCurrentDataRates(downKb, upKb);
|
||||
|
||||
updateGraph(downKb,upKb);
|
||||
/* Turn off opacity group on unsupported platforms */
|
||||
#if defined(Q_WS_WIN)
|
||||
if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion && QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) {
|
||||
ui.frmOpacity->setVisible(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
ui.frmOpacity->setVisible(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Binds events to actions. */
|
||||
void
|
||||
BandwidthGraph::createActions()
|
||||
{
|
||||
connect(ui.btnToggleSettings, SIGNAL(toggled(bool)),
|
||||
this, SLOT(showSettingsFrame(bool)));
|
||||
|
||||
connect(ui.btnReset, SIGNAL(clicked()),
|
||||
this, SLOT(reset()));
|
||||
|
||||
connect(ui.btnSaveSettings, SIGNAL(clicked()),
|
||||
this, SLOT(saveChanges()));
|
||||
|
||||
connect(ui.btnCancelSettings, SIGNAL(clicked()),
|
||||
this, SLOT(cancelChanges()));
|
||||
|
||||
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(setOpacity(int)));
|
||||
}
|
||||
|
||||
/** Adds new data to the graph. */
|
||||
void
|
||||
BandwidthGraph::updateGraph(qreal bytesRead, qreal bytesWritten)
|
||||
{
|
||||
/* Graph only cares about kilobytes */
|
||||
ui.frmGraph->addPoints(bytesRead/*/1024.0*/, bytesWritten/*/1024.0*/);
|
||||
connect(ui.btnToggleSettings, SIGNAL(toggled(bool)), this, SLOT(showSettingsFrame(bool)));
|
||||
connect(ui.btnReset, SIGNAL(clicked()), this, SLOT(reset()));
|
||||
connect(ui.btnSaveSettings, SIGNAL(clicked()), this, SLOT(saveChanges()));
|
||||
connect(ui.btnCancelSettings, SIGNAL(clicked()), this, SLOT(cancelChanges()));
|
||||
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)), this, SLOT(setOpacity(int)));
|
||||
}
|
||||
|
||||
/** Loads the saved Bandwidth Graph settings. */
|
||||
@ -168,8 +109,8 @@ BandwidthGraph::loadSettings()
|
||||
setOpacity(ui.sldrOpacity->value());
|
||||
|
||||
/* Set whether the window appears on top. */
|
||||
ui.chkAlwaysOnTop->setChecked(getSetting(SETTING_ALWAYS_ON_TOP,
|
||||
DEFAULT_ALWAYS_ON_TOP).toBool());
|
||||
ui.chkAlwaysOnTop->setChecked(getSetting(SETTING_ALWAYS_ON_TOP, DEFAULT_ALWAYS_ON_TOP).toBool());
|
||||
|
||||
if (ui.chkAlwaysOnTop->isChecked()) {
|
||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||||
} else {
|
||||
@ -183,32 +124,35 @@ BandwidthGraph::loadSettings()
|
||||
|
||||
/* Set whether we are plotting bandwidth as area graphs or not */
|
||||
int graphStyle = getSetting(SETTING_STYLE, DEFAULT_STYLE).toInt();
|
||||
|
||||
if (graphStyle < 0 || graphStyle >= ui.cmbGraphStyle->count()) {
|
||||
graphStyle = DEFAULT_STYLE;
|
||||
}
|
||||
ui.cmbGraphStyle->setCurrentIndex(graphStyle);
|
||||
ui.frmGraph->setGraphStyle((GraphFrame::GraphStyle)graphStyle);
|
||||
|
||||
if(graphStyle==0)
|
||||
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
|
||||
else
|
||||
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
|
||||
|
||||
/* Set graph frame settings */
|
||||
ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
|
||||
ui.chkSendRate->isChecked());
|
||||
ui.frmGraph->setShowEntry(0,ui.chkReceiveRate->isChecked()) ;
|
||||
ui.frmGraph->setShowEntry(1,ui.chkSendRate->isChecked()) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Resets the log start time. */
|
||||
void
|
||||
BandwidthGraph::reset()
|
||||
void BandwidthGraph::reset()
|
||||
{
|
||||
/* Set to current time */
|
||||
ui.statusbar->showMessage(tr("Since:") + " " +
|
||||
QDateTime::currentDateTime()
|
||||
.toString(DATETIME_FMT));
|
||||
ui.statusbar->showMessage(tr("Since:") + " " + QDateTime::currentDateTime() .toString(DATETIME_FMT));
|
||||
/* Reset the graph */
|
||||
ui.frmGraph->resetGraph();
|
||||
}
|
||||
|
||||
/** Saves the Bandwidth Graph settings and adjusts the graph if necessary. */
|
||||
void
|
||||
BandwidthGraph::saveChanges()
|
||||
void BandwidthGraph::saveChanges()
|
||||
{
|
||||
/* Hide the settings frame and reset toggle button */
|
||||
showSettingsFrame(false);
|
||||
@ -234,10 +178,14 @@ BandwidthGraph::saveChanges()
|
||||
|
||||
|
||||
/* Update the graph frame settings */
|
||||
ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
|
||||
ui.chkSendRate->isChecked());
|
||||
ui.frmGraph->setGraphStyle((GraphFrame::GraphStyle)ui.cmbGraphStyle->currentIndex());
|
||||
|
||||
ui.frmGraph->setShowEntry(0,ui.chkReceiveRate->isChecked()) ;
|
||||
ui.frmGraph->setShowEntry(1,ui.chkSendRate->isChecked()) ;
|
||||
|
||||
if(ui.cmbGraphStyle->currentIndex()==0)
|
||||
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
|
||||
else
|
||||
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
|
||||
|
||||
/* A change in window flags causes the window to disappear, so make sure
|
||||
* it's still visible. */
|
||||
showNormal();
|
||||
@ -283,8 +231,7 @@ BandwidthGraph::showSettingsFrame(bool show)
|
||||
}
|
||||
|
||||
/** Sets the opacity of the Bandwidth Graph window. */
|
||||
void
|
||||
BandwidthGraph::setOpacity(int value)
|
||||
void BandwidthGraph::setOpacity(int value)
|
||||
{
|
||||
qreal newValue = value / 100.0;
|
||||
|
@ -20,15 +20,14 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
#ifndef _BWGRAPH_H
|
||||
#define _BWGRAPH_H
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QEvent>
|
||||
#include <QTimer>
|
||||
|
||||
#include <gui/common/rwindow.h>
|
||||
#include <gui/statistics/bwgraph.h>
|
||||
|
||||
#include "ui_bwgraph.h"
|
||||
|
||||
@ -41,6 +40,8 @@ class BandwidthGraph : public RWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum { AreaGraph=0,LineGraph=1 } ;
|
||||
|
||||
/** Default constructor */
|
||||
BandwidthGraph(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
@ -48,14 +49,7 @@ public slots:
|
||||
/** Overloaded QWidget.show */
|
||||
void showWindow();
|
||||
|
||||
protected:
|
||||
/** Called to deliver a bandwidth update event from Tor. */
|
||||
void customEvent(QEvent *event);
|
||||
void timerEvent(QTimerEvent*);
|
||||
|
||||
private slots:
|
||||
/** Adds new data to the graph */
|
||||
void updateGraph(qreal bytesRead, qreal bytesWritten);
|
||||
/** Called when settings button is toggled */
|
||||
void showSettingsFrame(bool show);
|
||||
/** Called when the settings button is toggled */
|
||||
@ -67,9 +61,6 @@ private slots:
|
||||
/** Called when the reset button is pressed */
|
||||
void reset();
|
||||
|
||||
void updategraphstatus();
|
||||
|
||||
|
||||
private:
|
||||
/** Create and bind actions to events **/
|
||||
void createActions();
|
||||
@ -80,5 +71,4 @@ private:
|
||||
Ui::BandwidthGraph ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,30 +19,6 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="GraphFrame" name="frmGraph">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="_8">
|
||||
<property name="spacing">
|
||||
@ -466,15 +442,33 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="BWGraph" name="frmGraph" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GraphFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/graphframe.h</header>
|
||||
<class>BWGraph</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">gui/statistics/bwgraph.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
@ -68,6 +68,9 @@ int RSGraphSource::n_values() const { return _points.size() ; }
|
||||
|
||||
QString RSGraphSource::displayName(int i) const
|
||||
{
|
||||
if(_points.empty())
|
||||
return QString() ;
|
||||
|
||||
std::map<std::string,std::list<std::pair<qint64,float> > >::const_iterator it = _points.begin();
|
||||
|
||||
int n=0;
|
||||
@ -114,6 +117,18 @@ void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts) const
|
||||
pts.push_back(QPointF( (now - (*it2).first)/1000.0f,(*it2).second)) ;
|
||||
}
|
||||
|
||||
void RSGraphWidget::setShowEntry(uint32_t entry,bool b)
|
||||
{
|
||||
if(b)
|
||||
{
|
||||
std::set<std::string>::iterator it = _masked_entries.find(_source->displayName(entry).toStdString()) ;
|
||||
if(it != _masked_entries.end())
|
||||
_masked_entries.erase(it) ;
|
||||
}
|
||||
else
|
||||
_masked_entries.insert(_source->displayName(entry).toStdString()) ;
|
||||
}
|
||||
|
||||
void RSGraphWidget::addSource(RSGraphSource *gs)
|
||||
{
|
||||
if(_source != NULL)
|
||||
@ -163,6 +178,10 @@ void RSGraphSource::update()
|
||||
else
|
||||
++it ;
|
||||
}
|
||||
void RSGraphSource::reset()
|
||||
{
|
||||
_points.clear() ;
|
||||
}
|
||||
|
||||
void RSGraphSource::setCollectionTimeLimit(qint64 s) { _time_limit_msecs = s ; }
|
||||
void RSGraphSource::setCollectionTimePeriod(qint64 s) { _update_period_msecs = s ; }
|
||||
@ -183,6 +202,7 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
|
||||
_maxPoints = getNumPoints();
|
||||
_maxValue = MINUSER_SCALE;
|
||||
|
||||
_opacity = 0.6 ;
|
||||
_flags = 0;
|
||||
_time_scale = 5.0f ; // in pixels per second.
|
||||
_timer = new QTimer ;
|
||||
@ -213,6 +233,7 @@ RSGraphWidget::getNumPoints()
|
||||
void
|
||||
RSGraphWidget::resetGraph()
|
||||
{
|
||||
_source->reset() ;
|
||||
_maxValue = MINUSER_SCALE;
|
||||
update();
|
||||
}
|
||||
@ -268,6 +289,10 @@ QColor RSGraphWidget::getColor(int i)
|
||||
return QColor::fromHsv(h,128+127*(i&1),255) ;
|
||||
}
|
||||
|
||||
void RSGraphWidget::setCurvesOpacity(float f)
|
||||
{
|
||||
_opacity = f ;
|
||||
}
|
||||
/** Paints an integral and an outline of that integral for each data set (rsdht
|
||||
* and/or alldht) that is to be displayed. The integrals will be drawn first,
|
||||
* followed by the outlines, since we want the area of overlapping integrals
|
||||
@ -283,21 +308,22 @@ void RSGraphWidget::paintData()
|
||||
_maxValue = 0.0f ;
|
||||
|
||||
for(int i=0;i<source.n_values();++i)
|
||||
{
|
||||
std::vector<QPointF> values ;
|
||||
source.getDataPoints(i,values) ;
|
||||
if( _masked_entries.find(source.displayName(i).toStdString()) == _masked_entries.end() )
|
||||
{
|
||||
std::vector<QPointF> values ;
|
||||
source.getDataPoints(i,values) ;
|
||||
|
||||
QVector<QPointF> points ;
|
||||
pointsFromData(values,points) ;
|
||||
QVector<QPointF> points ;
|
||||
pointsFromData(values,points) ;
|
||||
|
||||
/* Plot the bandwidth data as area graphs */
|
||||
if (_flags & RSGRAPH_FLAGS_PAINT_STYLE_PLAIN)
|
||||
paintIntegral(points, getColor(i), 0.6);
|
||||
/* Plot the bandwidth data as area graphs */
|
||||
if (_flags & RSGRAPH_FLAGS_PAINT_STYLE_PLAIN)
|
||||
paintIntegral(points, getColor(i), _opacity);
|
||||
|
||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||
* area graph, we end up outlining the integrals. */
|
||||
paintLine(points, getColor(i));
|
||||
}
|
||||
paintLine(points, getColor(i));
|
||||
}
|
||||
if(_maxValue > 0.0f)
|
||||
if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y)
|
||||
_y_scale = _rec.height()*0.8 / log(_maxValue) ;
|
||||
@ -334,8 +360,6 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
|
||||
qreal px = x - (values[i].x()-last)*_time_scale ;
|
||||
qreal py = y - valueToPixels(values[i].y()) ;
|
||||
|
||||
_maxValue = std::max(_maxValue,values[i].y()) ;
|
||||
|
||||
if(px >= SCALE_WIDTH && last_px < SCALE_WIDTH)
|
||||
{
|
||||
float alpha = (SCALE_WIDTH - last_px)/(px - last_px) ;
|
||||
@ -354,6 +378,8 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
|
||||
if(px < SCALE_WIDTH)
|
||||
continue ;
|
||||
|
||||
_maxValue = std::max(_maxValue,values[i].y()) ;
|
||||
|
||||
// remove midle point when 3 consecutive points have the same value.
|
||||
|
||||
if(points.size() > 1 && points[points.size()-2].y() == points.back().y() && points.back().y() == py)
|
||||
@ -364,7 +390,6 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
|
||||
if(i==values.size()-1)
|
||||
points << QPointF(px,y) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
qreal RSGraphWidget::valueToPixels(qreal val)
|
||||
|
@ -24,6 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
@ -58,6 +59,7 @@ public:
|
||||
void start() ;
|
||||
void stop() ;
|
||||
void clear() ;
|
||||
void reset() ;
|
||||
|
||||
virtual QString unitName() const { return "" ; }// overload to give your own unit name (KB/s, Users, etc)
|
||||
|
||||
@ -119,7 +121,6 @@ class RSGraphWidget: public QFrame
|
||||
static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ;// keep collecting while not displayed
|
||||
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style
|
||||
static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph
|
||||
|
||||
/** Bandwidth graph style. */
|
||||
enum GraphStyle
|
||||
{
|
||||
@ -143,7 +144,10 @@ class RSGraphWidget: public QFrame
|
||||
/** Clears the graph. */
|
||||
void resetGraph();
|
||||
/** Toggles display of data counters. */
|
||||
//void setShowCounters(bool showRSDHT, bool showALLDHT);
|
||||
//void setShowCounters(bool showRSDHT, bool showALLDHT);
|
||||
|
||||
void setShowEntry(uint32_t entry, bool show) ;
|
||||
void setCurvesOpacity(float f) ;
|
||||
|
||||
void setFlags(uint32_t flag) { _flags |= flag ; }
|
||||
void resetFlags(uint32_t flag) { _flags &= ~flag ; }
|
||||
@ -190,11 +194,14 @@ class RSGraphWidget: public QFrame
|
||||
qreal _maxValue;
|
||||
/** The maximum number of points to store. */
|
||||
qreal _y_scale ;
|
||||
qreal _opacity ;
|
||||
|
||||
qreal pixelsToValue(qreal) ;
|
||||
qreal valueToPixels(qreal) ;
|
||||
int _maxPoints;
|
||||
|
||||
std::set<std::string> _masked_entries ;
|
||||
|
||||
qreal _time_scale ; // horizontal scale in pixels per sec.
|
||||
|
||||
/** Show the respective lines and counters. */
|
||||
|
@ -1,304 +0,0 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2006-2007, crypton
|
||||
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "graphframe.h"
|
||||
#include "gui/bwgraph/bwgraph.h"
|
||||
|
||||
|
||||
/** Default contructor */
|
||||
GraphFrame::GraphFrame(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
/* Create Graph Frame related objects */
|
||||
_recvData = new QList<qreal>();
|
||||
_sendData = new QList<qreal>();
|
||||
_painter = new QPainter();
|
||||
_graphStyle = SolidLine;
|
||||
|
||||
/* Initialize graph values */
|
||||
_recvData->prepend(0);
|
||||
_sendData->prepend(0);
|
||||
_maxPoints = getNumPoints();
|
||||
_showRecv = true;
|
||||
_showSend = true;
|
||||
_maxValue = MIN_SCALE;
|
||||
}
|
||||
|
||||
/** Default destructor */
|
||||
GraphFrame::~GraphFrame()
|
||||
{
|
||||
delete _painter;
|
||||
delete _recvData;
|
||||
delete _sendData;
|
||||
}
|
||||
|
||||
/** Gets the width of the desktop, which is the maximum number of points
|
||||
* we can plot in the graph. */
|
||||
int
|
||||
GraphFrame::getNumPoints()
|
||||
{
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
int width = desktop->width();
|
||||
return width;
|
||||
}
|
||||
|
||||
/** Adds new data points to the graph. */
|
||||
void
|
||||
GraphFrame::addPoints(qreal recv, qreal send)
|
||||
{
|
||||
/* If maximum number of points plotted, remove oldest */
|
||||
if (_sendData->size() == _maxPoints) {
|
||||
_sendData->removeLast();
|
||||
_recvData->removeLast();
|
||||
}
|
||||
|
||||
/* Add the points to their respective lists */
|
||||
_sendData->prepend(send);
|
||||
_recvData->prepend(recv);
|
||||
|
||||
/* Add to the total counters */
|
||||
/* These are not the real total values, but should be close enough. */
|
||||
_totalSend += BWGRAPH_REFRESH_RATE * send / 1000;
|
||||
_totalRecv += BWGRAPH_REFRESH_RATE * recv / 1000;
|
||||
|
||||
/* Check for a new maximum value */
|
||||
if (send > _maxValue) _maxValue = send;
|
||||
if (recv > _maxValue) _maxValue = recv;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Clears the graph. */
|
||||
void
|
||||
GraphFrame::resetGraph()
|
||||
{
|
||||
_recvData->clear();
|
||||
_sendData->clear();
|
||||
_recvData->prepend(0);
|
||||
_sendData->prepend(0);
|
||||
_maxValue = MIN_SCALE;
|
||||
_totalSend = 0;
|
||||
_totalRecv = 0;
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Toggles display of respective graph lines and counters. */
|
||||
void
|
||||
GraphFrame::setShowCounters(bool showRecv, bool showSend)
|
||||
{
|
||||
_showRecv = showRecv;
|
||||
_showSend = showSend;
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Overloads default QWidget::paintEvent. Draws the actual
|
||||
* bandwidth graph. */
|
||||
void
|
||||
GraphFrame::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
/* Set current graph dimensions */
|
||||
_rec = this->frameRect();
|
||||
|
||||
/* Start the painter */
|
||||
_painter->begin(this);
|
||||
|
||||
/* We want antialiased lines and text */
|
||||
_painter->setRenderHint(QPainter::Antialiasing);
|
||||
_painter->setRenderHint(QPainter::TextAntialiasing);
|
||||
|
||||
/* Fill in the background */
|
||||
_painter->fillRect(_rec, QBrush(BACK_COLOR));
|
||||
_painter->drawRect(_rec);
|
||||
|
||||
/* Paint the scale */
|
||||
paintScale();
|
||||
/* Plot the send/receive data */
|
||||
paintData();
|
||||
/* Paint the send/recv totals */
|
||||
paintTotals();
|
||||
|
||||
/* Stop the painter */
|
||||
_painter->end();
|
||||
}
|
||||
|
||||
/** Paints an integral and an outline of that integral for each data set (send
|
||||
* and/or receive) that is to be displayed. The integrals will be drawn first,
|
||||
* followed by the outlines, since we want the area of overlapping integrals
|
||||
* to blend, but not the outlines of those integrals. */
|
||||
void
|
||||
GraphFrame::paintData()
|
||||
{
|
||||
QVector<QPointF> recvPoints, sendPoints;
|
||||
|
||||
/* Convert the bandwidth data points to graph points */
|
||||
recvPoints = pointsFromData(_recvData);
|
||||
sendPoints = pointsFromData(_sendData);
|
||||
|
||||
if (_graphStyle == AreaGraph) {
|
||||
/* Plot the bandwidth data as area graphs */
|
||||
if (_showRecv)
|
||||
paintIntegral(recvPoints, RECV_COLOR, 0.6);
|
||||
if (_showSend)
|
||||
paintIntegral(sendPoints, SEND_COLOR, 0.4);
|
||||
}
|
||||
|
||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||
* area graph, we end up outlining the integrals. */
|
||||
if (_showRecv)
|
||||
paintLine(recvPoints, RECV_COLOR);
|
||||
if (_showSend)
|
||||
paintLine(sendPoints, SEND_COLOR);
|
||||
}
|
||||
|
||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
||||
* of send or receive values. */
|
||||
QVector<QPointF>
|
||||
GraphFrame::pointsFromData(QList<qreal>* list)
|
||||
{
|
||||
QVector<QPointF> points;
|
||||
int x = _rec.width();
|
||||
int y = _rec.height();
|
||||
qreal scale = (y - (y/10)) / _maxValue;
|
||||
qreal currValue;
|
||||
|
||||
/* Translate all data points to points on the graph frame */
|
||||
points << QPointF(x, y);
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
currValue = y - (list->at(i) * scale);
|
||||
if (x - SCROLL_STEP < SCALE_WIDTH) {
|
||||
points << QPointF(SCALE_WIDTH, currValue);
|
||||
break;
|
||||
}
|
||||
points << QPointF(x, currValue);
|
||||
x -= SCROLL_STEP;
|
||||
}
|
||||
points << QPointF(SCALE_WIDTH, y);
|
||||
return points;
|
||||
}
|
||||
|
||||
/** Plots an integral using the data points in <b>points</b>. The area will be
|
||||
* filled in using <b>color</b> and an alpha-blending level of <b>alpha</b>
|
||||
* (default is opaque). */
|
||||
void
|
||||
GraphFrame::paintIntegral(QVector<QPointF> points, QColor color, qreal alpha)
|
||||
{
|
||||
/* Save the current brush, plot the integral, and restore the old brush */
|
||||
QBrush oldBrush = _painter->brush();
|
||||
color.setAlphaF(alpha);
|
||||
_painter->setBrush(QBrush(color));
|
||||
_painter->drawPolygon(points.data(), points.size());
|
||||
_painter->setBrush(oldBrush);
|
||||
}
|
||||
|
||||
/** Iterates the input list and draws a line on the graph in the appropriate
|
||||
* color. */
|
||||
void
|
||||
GraphFrame::paintLine(QVector<QPointF> points, QColor color, Qt::PenStyle lineStyle)
|
||||
{
|
||||
/* Save the current brush, plot the line, and restore the old brush */
|
||||
QPen oldPen = _painter->pen();
|
||||
_painter->setPen(QPen(color, lineStyle));
|
||||
_painter->drawPolyline(points.data(), points.size());
|
||||
_painter->setPen(oldPen);
|
||||
}
|
||||
|
||||
/** Paints selected total indicators on the graph. */
|
||||
void
|
||||
GraphFrame::paintTotals()
|
||||
{
|
||||
int x = SCALE_WIDTH + FONT_SIZE, y = 0;
|
||||
int rowHeight = FONT_SIZE;
|
||||
|
||||
#if !defined(Q_WS_MAC)
|
||||
/* On Mac, we don't need vertical spacing between the text rows. */
|
||||
rowHeight += 5;
|
||||
#endif
|
||||
|
||||
/* If total received is selected */
|
||||
if (_showRecv) {
|
||||
y = rowHeight;
|
||||
_painter->setPen(RECV_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Recv: ") + totalToStr(_totalRecv) +
|
||||
" ("+tr("%1 KB/s").arg(_recvData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
if (_showSend) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(SEND_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Sent: ") + totalToStr(_totalSend) +
|
||||
" ("+tr("%1 KB/s").arg(_sendData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a formatted string with the correct size suffix. */
|
||||
QString
|
||||
GraphFrame::totalToStr(qreal total)
|
||||
{
|
||||
/* Determine the correct size suffix */
|
||||
if (total < 1024) {
|
||||
/* Use KB suffix */
|
||||
return tr("%1 KB").arg(total, 0, 'f', 2);
|
||||
} else if (total < 1048576) {
|
||||
/* Use MB suffix */
|
||||
return tr("%1 MB").arg(total/1024.0, 0, 'f', 2);
|
||||
} else {
|
||||
/* Use GB suffix */
|
||||
return tr("%1 GB").arg(total/1048576.0, 0, 'f', 2);
|
||||
}
|
||||
}
|
||||
|
||||
/** Paints the scale on the graph. */
|
||||
void
|
||||
GraphFrame::paintScale()
|
||||
{
|
||||
qreal markStep = _maxValue * .25;
|
||||
int top = _rec.y();
|
||||
int bottom = _rec.height();
|
||||
qreal paintStep = (bottom - (bottom/10)) / 4;
|
||||
|
||||
/* Draw the other marks in their correctly scaled locations */
|
||||
qreal scale;
|
||||
qreal pos;
|
||||
for (int i = 1; i < 5; i++) {
|
||||
pos = bottom - (i * paintStep);
|
||||
scale = i * markStep;
|
||||
_painter->setPen(SCALE_COLOR);
|
||||
_painter->drawText(QPointF(5, pos+FONT_SIZE),
|
||||
tr("%1 KB/s").arg(scale, 0, 'f', 2));
|
||||
_painter->setPen(GRID_COLOR);
|
||||
_painter->drawLine(QPointF(SCALE_WIDTH, pos),
|
||||
QPointF(_rec.width(), pos));
|
||||
}
|
||||
|
||||
/* Draw vertical separator */
|
||||
_painter->drawLine(SCALE_WIDTH, top, SCALE_WIDTH, bottom);
|
||||
}
|
||||
|
@ -1,121 +0,0 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2006-2007, crypton
|
||||
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
#ifndef _GRAPHFRAME_H
|
||||
#define _GRAPHFRAME_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFrame>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QList>
|
||||
|
||||
#define HOR_SPC 2 /** Space between data points */
|
||||
#define SCALE_WIDTH 75 /** Width of the scale */
|
||||
#define MIN_SCALE 10 /** 10 kB/s is the minimum scale */
|
||||
#define SCROLL_STEP 4 /** Horizontal change on graph update */
|
||||
|
||||
#define BACK_COLOR Qt::black
|
||||
#define SCALE_COLOR Qt::green
|
||||
#define GRID_COLOR Qt::darkGreen
|
||||
#define RECV_COLOR Qt::cyan
|
||||
#define SEND_COLOR Qt::yellow
|
||||
|
||||
#define FONT_SIZE 11
|
||||
|
||||
|
||||
class GraphFrame : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Bandwidth graph style. */
|
||||
enum GraphStyle {
|
||||
SolidLine = 0, /**< Plot bandwidth as solid lines. */
|
||||
AreaGraph /**< Plot bandwidth as alpha blended area graphs. */
|
||||
};
|
||||
|
||||
/** Default Constructor */
|
||||
GraphFrame(QWidget *parent = 0);
|
||||
/** Default Destructor */
|
||||
~GraphFrame();
|
||||
|
||||
/** Add data points. */
|
||||
void addPoints(qreal recv, qreal send);
|
||||
/** Clears the graph. */
|
||||
void resetGraph();
|
||||
/** Toggles display of data counters. */
|
||||
void setShowCounters(bool showRecv, bool showSend);
|
||||
/** Sets the graph style used to display bandwidth data. */
|
||||
void setGraphStyle(GraphStyle style) { _graphStyle = style; }
|
||||
|
||||
protected:
|
||||
/** Overloaded QWidget::paintEvent() */
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
/** Gets the width of the desktop, the max # of points. */
|
||||
int getNumPoints();
|
||||
|
||||
/** Paints an integral and an outline of that integral for each data set
|
||||
* (send and/or receive) that is to be displayed. */
|
||||
void paintData();
|
||||
/** Paints the send/receive totals. */
|
||||
void paintTotals();
|
||||
/** Paints the scale in the graph. */
|
||||
void paintScale();
|
||||
/** Returns a formatted string representation of total. */
|
||||
QString totalToStr(qreal total);
|
||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
||||
* of send or receive values. */
|
||||
QVector<QPointF> pointsFromData(QList<qreal>* list);
|
||||
/** Paints a line with the data in <b>points</b>. */
|
||||
void paintLine(QVector<QPointF> points, QColor color,
|
||||
Qt::PenStyle lineStyle = Qt::SolidLine);
|
||||
/** Paints an integral using the supplied data. */
|
||||
void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0);
|
||||
|
||||
/** Style with which the bandwidth data will be graphed. */
|
||||
GraphStyle _graphStyle;
|
||||
/** A QPainter object that handles drawing the various graph elements. */
|
||||
QPainter* _painter;
|
||||
/** Holds the received data points. */
|
||||
QList<qreal> *_recvData;
|
||||
/** Holds the sent data points. */
|
||||
QList<qreal> *_sendData;
|
||||
/** The current dimensions of the graph. */
|
||||
QRect _rec;
|
||||
/** The maximum data value plotted. */
|
||||
qreal _maxValue;
|
||||
/** The maximum number of points to store. */
|
||||
int _maxPoints;
|
||||
/** The total data sent/recv. */
|
||||
qreal _totalSend;
|
||||
qreal _totalRecv;
|
||||
/** Show the respective lines and counters. */
|
||||
bool _showRecv;
|
||||
bool _showSend;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,384 +0,0 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2006-2007, crypton
|
||||
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "graphframetunnel.h"
|
||||
|
||||
|
||||
/** Default contructor */
|
||||
GraphFrameTunnel::GraphFrameTunnel(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
/* Create Graph Frame related objects */
|
||||
_tunnelrequestdownData = new QList<qreal>();
|
||||
_tunnelrequestupData = new QList<qreal>();
|
||||
_incomingfileData = new QList<qreal>();
|
||||
_outgoingfileData = new QList<qreal>();
|
||||
_forwardedData = new QList<qreal>();
|
||||
|
||||
_painter = new QPainter();
|
||||
_graphStyle = SolidLine;
|
||||
|
||||
/* Initialize graph values */
|
||||
_tunnelrequestdownData->prepend(0);
|
||||
_tunnelrequestupData->prepend(0);
|
||||
_incomingfileData->prepend(0);
|
||||
_outgoingfileData->prepend(0);
|
||||
_forwardedData->prepend(0);
|
||||
|
||||
_maxPoints = getNumPoints();
|
||||
_showTrdown = true;
|
||||
_showTrup = true;
|
||||
_showIncoming = true;
|
||||
_showOutgoing = true;
|
||||
_showForwarded = true;
|
||||
_maxValue = MIN_SCALE;
|
||||
}
|
||||
|
||||
/** Default destructor */
|
||||
GraphFrameTunnel::~GraphFrameTunnel()
|
||||
{
|
||||
delete _painter;
|
||||
delete _tunnelrequestdownData;
|
||||
delete _tunnelrequestupData;
|
||||
delete _incomingfileData;
|
||||
delete _outgoingfileData;
|
||||
delete _forwardedData;
|
||||
}
|
||||
|
||||
/** Gets the width of the desktop, which is the maximum number of points
|
||||
* we can plot in the graph. */
|
||||
int
|
||||
GraphFrameTunnel::getNumPoints()
|
||||
{
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
int width = desktop->width();
|
||||
return width;
|
||||
}
|
||||
|
||||
/** Adds new data points to the graph. */
|
||||
void
|
||||
GraphFrameTunnel::addPoints(qreal trup, qreal trdown, qreal datadown,qreal dataup, qreal forwardupdown)
|
||||
{
|
||||
/* If maximum number of points plotted, remove oldest */
|
||||
if (_tunnelrequestupData->size() == _maxPoints) {
|
||||
_tunnelrequestdownData->removeLast();
|
||||
_tunnelrequestupData->removeLast();
|
||||
_incomingfileData->removeLast();
|
||||
_outgoingfileData->removeLast();
|
||||
_forwardedData->removeLast();
|
||||
}
|
||||
|
||||
/* Add the points to their respective lists */
|
||||
_tunnelrequestupData->prepend(trup);
|
||||
_tunnelrequestdownData->prepend(trdown);
|
||||
_incomingfileData->prepend(datadown);
|
||||
_outgoingfileData->prepend(dataup);
|
||||
_forwardedData->prepend(forwardupdown);
|
||||
|
||||
/* Add to the total counters */
|
||||
/* These are not the real total values, but should be close enough. */
|
||||
_totalTrup += GRAPH_REFRESH_RATE * trup / 1000;
|
||||
_totalTrdown += GRAPH_REFRESH_RATE * trdown / 1000;
|
||||
_totalInFileData += GRAPH_REFRESH_RATE * datadown / 1000;
|
||||
_totalOutgoingFileData += GRAPH_REFRESH_RATE * dataup / 1000;
|
||||
_totalForwardedData += GRAPH_REFRESH_RATE * forwardupdown / 1000;
|
||||
|
||||
/* Check for a new maximum value */
|
||||
if (trup > _maxValue) _maxValue = trup;
|
||||
if (trdown > _maxValue) _maxValue = trdown;
|
||||
if (datadown > _maxValue) _maxValue = datadown;
|
||||
if (dataup > _maxValue) _maxValue = dataup;
|
||||
if (forwardupdown > _maxValue) _maxValue = forwardupdown;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Clears the graph. */
|
||||
void
|
||||
GraphFrameTunnel::resetGraph()
|
||||
{
|
||||
_tunnelrequestupData->clear();
|
||||
_tunnelrequestdownData->clear();
|
||||
_incomingfileData->clear();
|
||||
_outgoingfileData->clear();
|
||||
_forwardedData->clear();
|
||||
|
||||
_tunnelrequestdownData->prepend(0);
|
||||
_tunnelrequestupData->prepend(0);
|
||||
_incomingfileData->prepend(0);
|
||||
_outgoingfileData->prepend(0);
|
||||
_forwardedData->prepend(0);
|
||||
|
||||
_maxValue = MIN_SCALE;
|
||||
|
||||
_totalTrup = 0;
|
||||
_totalTrdown = 0;
|
||||
_totalInFileData = 0;
|
||||
_totalOutgoingFileData = 0;
|
||||
_totalForwardedData = 0;
|
||||
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Toggles display of respective graph lines and counters. */
|
||||
void
|
||||
GraphFrameTunnel::setShowCounters(bool showTrdown, bool showTrup, bool showIncoming, bool showOutgoing)
|
||||
{
|
||||
_showTrdown = showTrdown;
|
||||
_showTrup = showTrup;
|
||||
_showIncoming = showIncoming;
|
||||
_showOutgoing = showOutgoing;
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Overloads default QWidget::paintEvent. Draws the actual
|
||||
* bandwidth graph. */
|
||||
void
|
||||
GraphFrameTunnel::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
/* Set current graph dimensions */
|
||||
_rec = this->frameRect();
|
||||
|
||||
/* Start the painter */
|
||||
_painter->begin(this);
|
||||
|
||||
/* We want antialiased lines and text */
|
||||
_painter->setRenderHint(QPainter::Antialiasing);
|
||||
_painter->setRenderHint(QPainter::TextAntialiasing);
|
||||
|
||||
/* Fill in the background */
|
||||
_painter->fillRect(_rec, QBrush(TBACK_COLOR));
|
||||
_painter->drawRect(_rec);
|
||||
|
||||
/* Paint the scale */
|
||||
paintScale();
|
||||
/* Plot the send/receive data */
|
||||
paintData();
|
||||
/* Paint the send/recv totals */
|
||||
paintTotals();
|
||||
|
||||
/* Stop the painter */
|
||||
_painter->end();
|
||||
}
|
||||
|
||||
/** Paints an integral and an outline of that integral for each data set (send
|
||||
* and/or receive) that is to be displayed. The integrals will be drawn first,
|
||||
* followed by the outlines, since we want the area of overlapping integrals
|
||||
* to blend, but not the outlines of those integrals. */
|
||||
void
|
||||
GraphFrameTunnel::paintData()
|
||||
{
|
||||
//QVector<QPointF> recvPoints, sendPoints;
|
||||
QVector<QPointF> trdownPoints, trupPoints, infilePoints, outfilePoints, forwardedPoints;
|
||||
|
||||
/* Convert the bandwidth data points to graph points */
|
||||
trdownPoints = pointsFromData( _tunnelrequestupData);
|
||||
trupPoints = pointsFromData( _tunnelrequestdownData);
|
||||
infilePoints = pointsFromData(_incomingfileData);
|
||||
outfilePoints = pointsFromData(_outgoingfileData);
|
||||
forwardedPoints = pointsFromData(_forwardedData);
|
||||
|
||||
if (_graphStyle == AreaGraph) {
|
||||
/* Plot the bandwidth data as area graphs */
|
||||
if (_showTrdown)
|
||||
paintIntegral(trdownPoints, TRDOWN_COLOR, 0.6);
|
||||
if (_showTrup)
|
||||
paintIntegral(trupPoints, TRUP_COLOR, 0.4);
|
||||
|
||||
paintIntegral(infilePoints, INFILEDATA_COLOR, 0.6);
|
||||
paintIntegral(outfilePoints, OUTFILEDATA_COLOR, 0.4);
|
||||
//paintIntegral(forwardedPoints, FORWARDED_COLOR, 0.6);
|
||||
}
|
||||
|
||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||
* area graph, we end up outlining the integrals. */
|
||||
if (_showTrdown)
|
||||
paintLine(trdownPoints, TRDOWN_COLOR);
|
||||
if (_showTrup)
|
||||
paintLine(trupPoints, TRUP_COLOR);
|
||||
|
||||
paintLine(infilePoints, INFILEDATA_COLOR);
|
||||
paintLine(outfilePoints, OUTFILEDATA_COLOR);
|
||||
//paintLine(forwardedPoints, FORWARDED_COLOR);
|
||||
}
|
||||
|
||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
||||
* of send or receive values. */
|
||||
QVector<QPointF>
|
||||
GraphFrameTunnel::pointsFromData(QList<qreal>* list)
|
||||
{
|
||||
QVector<QPointF> points;
|
||||
int x = _rec.width();
|
||||
int y = _rec.height();
|
||||
qreal scale = (y - (y/10)) / _maxValue;
|
||||
qreal currValue;
|
||||
|
||||
/* Translate all data points to points on the graph frame */
|
||||
points << QPointF(x, y);
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
currValue = y - (list->at(i) * scale);
|
||||
if (x - SCROLL_STEP < SCALE_WIDTH) {
|
||||
points << QPointF(SCALE_WIDTH, currValue);
|
||||
break;
|
||||
}
|
||||
points << QPointF(x, currValue);
|
||||
x -= SCROLL_STEP;
|
||||
}
|
||||
points << QPointF(SCALE_WIDTH, y);
|
||||
return points;
|
||||
}
|
||||
|
||||
/** Plots an integral using the data points in <b>points</b>. The area will be
|
||||
* filled in using <b>color</b> and an alpha-blending level of <b>alpha</b>
|
||||
* (default is opaque). */
|
||||
void
|
||||
GraphFrameTunnel::paintIntegral(QVector<QPointF> points, QColor color, qreal alpha)
|
||||
{
|
||||
/* Save the current brush, plot the integral, and restore the old brush */
|
||||
QBrush oldBrush = _painter->brush();
|
||||
color.setAlphaF(alpha);
|
||||
_painter->setBrush(QBrush(color));
|
||||
_painter->drawPolygon(points.data(), points.size());
|
||||
_painter->setBrush(oldBrush);
|
||||
}
|
||||
|
||||
/** Iterates the input list and draws a line on the graph in the appropriate
|
||||
* color. */
|
||||
void
|
||||
GraphFrameTunnel::paintLine(QVector<QPointF> points, QColor color, Qt::PenStyle lineStyle)
|
||||
{
|
||||
/* Save the current brush, plot the line, and restore the old brush */
|
||||
QPen oldPen = _painter->pen();
|
||||
_painter->setPen(QPen(color, lineStyle));
|
||||
_painter->drawPolyline(points.data(), points.size());
|
||||
_painter->setPen(oldPen);
|
||||
}
|
||||
|
||||
/** Paints selected total indicators on the graph. */
|
||||
void
|
||||
GraphFrameTunnel::paintTotals()
|
||||
{
|
||||
int x = SCALE_WIDTH + FONT_SIZE, y = 0;
|
||||
int rowHeight = FONT_SIZE;
|
||||
|
||||
#if !defined(Q_WS_MAC)
|
||||
/* On Mac, we don't need vertical spacing between the text rows. */
|
||||
rowHeight += 5;
|
||||
#endif
|
||||
|
||||
/* If total received is selected */
|
||||
if (_showTrdown) {
|
||||
y = rowHeight;
|
||||
_painter->setPen(TRDOWN_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Tunnel requests Down: ") + totalToStr(_totalTrdown) +
|
||||
" ("+tr("%1 KB/s").arg(_tunnelrequestdownData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
if (_showTrup) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(TRUP_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Tunnel requests Up: ") + totalToStr(_totalTrup) +
|
||||
" ("+tr("%1 KB/s").arg(_tunnelrequestupData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total received is selected */
|
||||
if (_showIncoming) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(INFILEDATA_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Incoming file data: ") + totalToStr(_totalInFileData) +
|
||||
" ("+tr("%1 KB/s").arg(_incomingfileData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
if (_showOutgoing) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(OUTFILEDATA_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Outgoing file data: ") + totalToStr(_totalOutgoingFileData) +
|
||||
" ("+tr("%1 KB/s").arg(_outgoingfileData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
/*if (_showForwarded) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(FORWARDED_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Forwarded data: ") + totalToStr(_totalOutgoingFileData) +
|
||||
" ("+tr("%1 KB/s").arg(_outgoingfileData->first(), 0, 'f', 2)+")");
|
||||
}*/
|
||||
}
|
||||
|
||||
/** Returns a formatted string with the correct size suffix. */
|
||||
QString
|
||||
GraphFrameTunnel::totalToStr(qreal total)
|
||||
{
|
||||
/* Determine the correct size suffix */
|
||||
if (total < 1024) {
|
||||
/* Use KB suffix */
|
||||
return tr("%1 KB").arg(total, 0, 'f', 2);
|
||||
} else if (total < 1048576) {
|
||||
/* Use MB suffix */
|
||||
return tr("%1 MB").arg(total/1024.0, 0, 'f', 2);
|
||||
} else {
|
||||
/* Use GB suffix */
|
||||
return tr("%1 GB").arg(total/1048576.0, 0, 'f', 2);
|
||||
}
|
||||
}
|
||||
|
||||
/** Paints the scale on the graph. */
|
||||
void
|
||||
GraphFrameTunnel::paintScale()
|
||||
{
|
||||
qreal markStep = _maxValue * .25;
|
||||
int top = _rec.y();
|
||||
int bottom = _rec.height();
|
||||
qreal paintStep = (bottom - (bottom/10)) / 4;
|
||||
|
||||
/* Draw the other marks in their correctly scaled locations */
|
||||
qreal scale;
|
||||
qreal pos;
|
||||
for (int i = 1; i < 5; i++) {
|
||||
pos = bottom - (i * paintStep);
|
||||
scale = i * markStep;
|
||||
_painter->setPen(TSCALE_COLOR);
|
||||
_painter->drawText(QPointF(5, pos+FONT_SIZE),
|
||||
tr("%1 KB/s").arg(scale, 0, 'f', 2));
|
||||
_painter->setPen(TGRID_COLOR);
|
||||
_painter->drawLine(QPointF(SCALE_WIDTH, pos),
|
||||
QPointF(_rec.width(), pos));
|
||||
}
|
||||
|
||||
/* Draw vertical separator */
|
||||
_painter->drawLine(SCALE_WIDTH, top, SCALE_WIDTH, bottom);
|
||||
}
|
||||
|
@ -1,143 +0,0 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2006-2007, crypton
|
||||
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
#ifndef _GRAPHFRAMETUNNEL_H
|
||||
#define _GRAPHFRAMETUNNEL_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFrame>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QList>
|
||||
|
||||
#define HOR_SPC 2 /** Space between data points */
|
||||
#define SCALE_WIDTH 75 /** Width of the scale */
|
||||
#define MIN_SCALE 5 /** 5 kB/s is the minimum scale */
|
||||
#define SCROLL_STEP 4 /** Horizontal change on graph update */
|
||||
|
||||
#define TBACK_COLOR Qt::black
|
||||
#define TSCALE_COLOR Qt::green
|
||||
#define TGRID_COLOR Qt::darkGreen
|
||||
#define TRDOWN_COLOR Qt::cyan
|
||||
#define TRUP_COLOR Qt::yellow
|
||||
#define INFILEDATA_COLOR Qt::magenta
|
||||
#define OUTFILEDATA_COLOR Qt::blue
|
||||
#define FORWARDED_COLOR qt::red
|
||||
|
||||
#define FONT_SIZE 11
|
||||
|
||||
/** Redraw graph every BWGRAPH_REFRESH_RATE ms **/
|
||||
#define GRAPH_REFRESH_RATE 5113
|
||||
|
||||
|
||||
class GraphFrameTunnel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Bandwidth graph style. */
|
||||
enum GraphStyle {
|
||||
SolidLine = 0, /**< Plot bandwidth as solid lines. */
|
||||
AreaGraph /**< Plot bandwidth as alpha blended area graphs. */
|
||||
};
|
||||
|
||||
/** Default Constructor */
|
||||
GraphFrameTunnel(QWidget *parent = 0);
|
||||
/** Default Destructor */
|
||||
~GraphFrameTunnel();
|
||||
|
||||
/** Add data points. */
|
||||
void addPoints(qreal trup, qreal trdown, qreal datadown,qreal dataup, qreal forwardupdown );
|
||||
/** Clears the graph. */
|
||||
void resetGraph();
|
||||
/** Toggles display of data counters. */
|
||||
void setShowCounters(bool showTrdown, bool showTrup, bool showIncoming, bool showOutgoing);
|
||||
/** Sets the graph style used to display bandwidth data. */
|
||||
void setGraphStyle(GraphStyle style) { _graphStyle = style; }
|
||||
|
||||
protected:
|
||||
/** Overloaded QWidget::paintEvent() */
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
/** Gets the width of the desktop, the max # of points. */
|
||||
int getNumPoints();
|
||||
|
||||
/** Paints an integral and an outline of that integral for each data set
|
||||
* (send and/or receive) that is to be displayed. */
|
||||
void paintData();
|
||||
/** Paints the send/receive totals. */
|
||||
void paintTotals();
|
||||
/** Paints the scale in the graph. */
|
||||
void paintScale();
|
||||
/** Returns a formatted string representation of total. */
|
||||
QString totalToStr(qreal total);
|
||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
||||
* of send or receive values. */
|
||||
QVector<QPointF> pointsFromData(QList<qreal>* list);
|
||||
/** Paints a line with the data in <b>points</b>. */
|
||||
void paintLine(QVector<QPointF> points, QColor color,
|
||||
Qt::PenStyle lineStyle = Qt::SolidLine);
|
||||
/** Paints an integral using the supplied data. */
|
||||
void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0);
|
||||
|
||||
/** Style with which the bandwidth data will be graphed. */
|
||||
GraphStyle _graphStyle;
|
||||
/** A QPainter object that handles drawing the various graph elements. */
|
||||
QPainter* _painter;
|
||||
/** Holds the tunnel request down data points. */
|
||||
QList<qreal> *_tunnelrequestdownData;
|
||||
/** Holds the tunnel request up data points. */
|
||||
QList<qreal> *_tunnelrequestupData;
|
||||
/** Holds the incoming file data points. */
|
||||
QList<qreal> *_incomingfileData;
|
||||
/** Holds the outgoin file data points. */
|
||||
QList<qreal> *_outgoingfileData;
|
||||
/** Holds the received data points. */
|
||||
QList<qreal> *_forwardedData;
|
||||
|
||||
|
||||
/** The current dimensions of the graph. */
|
||||
QRect _rec;
|
||||
/** The maximum data value plotted. */
|
||||
qreal _maxValue;
|
||||
/** The maximum number of points to store. */
|
||||
int _maxPoints;
|
||||
/** The total data sent/recv. */
|
||||
|
||||
qreal _totalTrup;
|
||||
qreal _totalTrdown;
|
||||
qreal _totalInFileData;
|
||||
qreal _totalOutgoingFileData;
|
||||
qreal _totalForwardedData;
|
||||
|
||||
/** Show the respective lines and counters. */
|
||||
bool _showTrdown;
|
||||
bool _showTrup;
|
||||
bool _showIncoming;
|
||||
bool _showOutgoing;
|
||||
bool _showForwarded;
|
||||
};
|
||||
|
||||
#endif
|
@ -313,8 +313,6 @@ HEADERS += rshare.h \
|
||||
gui/StartDialog.h \
|
||||
gui/NetworkDialog.h \
|
||||
gui/GenCertDialog.h \
|
||||
gui/graphframe.h \
|
||||
gui/graphframetunnel.h \
|
||||
gui/linetypes.h \
|
||||
gui/mainpagestack.h \
|
||||
gui/MainWindow.h \
|
||||
@ -379,7 +377,7 @@ HEADERS += rshare.h \
|
||||
util/ObjectPainter.h \
|
||||
util/QtVersion.h \
|
||||
util/RsFile.h \
|
||||
gui/bwgraph/bwgraph.h \
|
||||
gui/bwgraph/BandwidthGraphWindow.h \
|
||||
gui/profile/ProfileWidget.h \
|
||||
gui/profile/ProfileManager.h \
|
||||
gui/profile/StatusMessage.h \
|
||||
@ -560,7 +558,7 @@ FORMS += gui/StartDialog.ui \
|
||||
gui/help/browser/helpbrowser.ui \
|
||||
gui/HelpDialog.ui \
|
||||
gui/ServicePermissionDialog.ui \
|
||||
gui/bwgraph/bwgraph.ui \
|
||||
gui/bwgraph/BandwidthGraphWindow.ui \
|
||||
gui/profile/ProfileWidget.ui \
|
||||
gui/profile/StatusMessage.ui \
|
||||
gui/profile/ProfileManager.ui \
|
||||
@ -655,8 +653,6 @@ SOURCES += main.cpp \
|
||||
gui/StartDialog.cpp \
|
||||
gui/GenCertDialog.cpp \
|
||||
gui/NetworkDialog.cpp \
|
||||
gui/graphframe.cpp \
|
||||
gui/graphframetunnel.cpp \
|
||||
gui/mainpagestack.cpp \
|
||||
gui/MainWindow.cpp \
|
||||
gui/NetworkView.cpp \
|
||||
@ -713,7 +709,7 @@ SOURCES += main.cpp \
|
||||
util/HandleRichText.cpp \
|
||||
util/ObjectPainter.cpp \
|
||||
util/RsFile.cpp \
|
||||
gui/bwgraph/bwgraph.cpp \
|
||||
gui/bwgraph/BandwidthGraphWindow.cpp \
|
||||
gui/profile/ProfileWidget.cpp \
|
||||
gui/profile/StatusMessage.cpp \
|
||||
gui/profile/ProfileManager.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user