1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/***************************************************************************
** $Id: chart.cpp,v 1.8 2008/07/31 19:56:25 hoganrobert Exp $
* Copyright (C) 2006 - 2008 Robert Hogan *
* [email protected] *
* *
* Copyright (C) 2005 by Hugo Parente Lima *
* [email protected] *
* *
* 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 St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "chart.h"
#include "functions.h"
#include <ntqpainter.h>
#include <ntqbrush.h>
#include <kdebug.h>
using namespace tk;
Chart::Chart(TQWidget* parent, const double* uploadBuffer, const double* downloadBuffer, int bufferSize, const int* ptr, const double* maxspeed, const double* sys_uploadBuffer, const double* sys_downloadBuffer, int sys_bufferSize, const int* sys_ptr, const double* sys_maxspeed, bool gotEth0) : TQWidget(parent), mUplBuffer(uploadBuffer), mDldBuffer(downloadBuffer), mBufferSize(bufferSize), mPtr(ptr), mMaxSpeed(maxspeed),sys_mUplBuffer(sys_uploadBuffer), sys_mDldBuffer(sys_downloadBuffer), sys_mBufferSize(sys_bufferSize), sys_mPtr(sys_ptr), sys_mMaxSpeed(sys_maxspeed),mGotEth0(gotEth0) {
setWFlags(TQt::WNoAutoErase);
setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding);
}
void Chart::paintEvent(TQPaintEvent*) {
TQPainter paint(this);
paint.setBackgroundColor(TQt::black);
paint.setBackgroundMode(TQt::OpaqueMode);
TQBrush brush(TQColor(0x33, 0x33, 0x33), CrossPattern);
paint.fillRect(0, 0, width(), height(), brush);
const double step = width()/double(mBufferSize);
const int HEIGHT = height() - 1;
int x;
int lastX = x = width();
int lastRxY = HEIGHT - int(HEIGHT * (mDldBuffer[*mPtr]/(*mMaxSpeed)));
int lastTxY = HEIGHT - int(HEIGHT * (mUplBuffer[*mPtr]/(*mMaxSpeed)));
int count = 0;
for (int i = *mPtr; count < mBufferSize; i--) {
if (i < 0)
i = mBufferSize-1;
int rxY = HEIGHT - int(HEIGHT * (mDldBuffer[i]/(*mMaxSpeed)));
int txY = HEIGHT - int(HEIGHT * (mUplBuffer[i]/(*mMaxSpeed)));
paint.setPen(TQt::green);
paint.drawLine(lastX, lastRxY, x, rxY);
paint.setPen(TQt::red);
paint.drawLine(lastX, lastTxY, x, txY);
//tqDebug("%d => %d", i, int(mSpeedHistoryRx[i]));
lastX = x;
lastRxY = rxY;
lastTxY = txY;
count++;
x = width() - int(step*(count+1));
}
paint.setFont(TQFont("Helvetica", 8));
paint.setPen( TQt::red );
paint.drawText( rect(), TQt::AlignTop, TQString("Tor Tx: %1 ").arg(BytesPerSecToString(mUplBuffer[*mPtr])));
paint.setPen( TQt::green );
paint.drawText( rect(), TQt::AlignBottom, TQString("Tor Rx: %1 ").arg(BytesPerSecToString(mDldBuffer[*mPtr])));
if (mGotEth0){
lastX = x = width();
lastRxY = HEIGHT - int(HEIGHT * (sys_mDldBuffer[*sys_mPtr]/(*sys_mMaxSpeed)));
lastTxY = HEIGHT - int(HEIGHT * (sys_mUplBuffer[*sys_mPtr]/(*sys_mMaxSpeed)));
count = 0;
for (int i = *sys_mPtr; count < sys_mBufferSize; i--) {
if (i < 0)
i = sys_mBufferSize-1;
int rxY = HEIGHT - int(HEIGHT * (sys_mDldBuffer[i]/(*sys_mMaxSpeed)));
int txY = HEIGHT - int(HEIGHT * (sys_mUplBuffer[i]/(*sys_mMaxSpeed)));
paint.setPen(TQt::darkGreen);
paint.drawLine(lastX, lastRxY, x, rxY);
paint.setPen(TQt::darkRed);
paint.drawLine(lastX, lastTxY, x, txY);
//tqDebug("%d => %d", i, int(mSpeedHistoryRx[i]));
lastX = x;
lastRxY = rxY;
lastTxY = txY;
count++;
x = width() - int(step*(count+1));
}
TQString TorTX = TQString("Tor Tx: %1 ").arg(BytesPerSecToString(mUplBuffer[*mPtr]));
TQString SysTX = TQString("Sys Tx: %1 ").arg(BytesPerSecToString(sys_mUplBuffer[*sys_mPtr]));
TQString TorRX = TQString("Tor Rx: %1 ").arg(BytesPerSecToString(mDldBuffer[*mPtr]));
TQString SysRX = TQString("Sys Rx: %1 ").arg(BytesPerSecToString(sys_mDldBuffer[*sys_mPtr]));
//Paint Text Representation
TQRect first = paint.boundingRect( rect(), TQt::AlignTop, TorTX);
first.moveLeft(first.width());
first.setWidth(paint.boundingRect( rect(), TQt::AlignTop, SysTX).width());
paint.setPen( TQt::red );
paint.drawText( first, TQt::AlignTop, SysTX);
first = paint.boundingRect( rect(), TQt::AlignBottom, TorRX);
first.moveLeft(first.width());
first.setWidth(paint.boundingRect( rect(), TQt::AlignTop, SysRX).width());
paint.setPen( TQt::green );
paint.drawText( first, TQt::AlignTop, SysRX);
}
}
|