/*********************************************************************** * Copyright 2003-2004 Max Howell * Copyright 2008-2009 Martin Sandsmark * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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, see . ***********************************************************************/ #include "widget.h" #include #include #include #include #include ChartArea::Widget::Widget(QWidget *parent) : QWidget(parent) { setSizePolicy(QSizePolicy::Preferred,QSizePolicy::MinimumExpanding); setMinimumHeight(20); setMinimumWidth(100); } ChartArea::Widget::~Widget() { } void ChartArea::Widget::invalidate() { } void ChartArea::Widget::resizeEvent(QResizeEvent*) { /*std::cerr << "width(): " << width() << std::endl; std::cerr << "height(): " << height() << std::endl;*/ } void ChartArea::Widget::addValue(uint64_t value) { //m_values.push_back(value); while(m_values.size()>64) m_values.erase(m_values.begin()); update(); } void ChartArea::Widget::paintEvent(QPaintEvent*) { //std::cerr << "paintEvent(): " << width() << std::endl; QPainter painter; painter.begin(this); painter.drawRect(0,0,width()-1,height()-1); painter.setRenderHint(QPainter::Antialiasing,true); painter.setRenderHint(QPainter::SmoothPixmapTransform,true); painter.setRenderHint(QPainter::HighQualityAntialiasing,true); while(m_values.size()<64) m_values.insert(m_values.begin(),0); std::vector values=m_values; QVector points; { uint64_t max=0; unsigned int index=0; while(index250000) painter.setPen(QPen(QColor(160,240,160), 3)); else painter.setPen(QPen(QColor(160,240,160), 2)); painter.drawPolyline(QPolygonF(points)); // todo: bounding rect + center flag if(height()>30) { QFont font = painter.font(); int heightTemp=height()/5; if(heightTemp<14) heightTemp=14; font.setPixelSize(heightTemp); painter.setFont(font); painter.setPen(QPen(QColor(140,140,140), 3)); painter.drawText(0,0,width(),height(),Qt::AlignHCenter | Qt::AlignBottom,tr("%1B/s").arg(m_values.back())); } painter.end(); }