1
/******************************************************************************
2
* Copyright © 2012-2014 Institut für Nachrichtentechnik, Universität Rostock *
3
* Copyright © 2006-2012 Quality & Usability Lab, *
4
* Telekom Innovation Laboratories, TU Berlin *
6
* This file is part of the SoundScape Renderer (SSR). *
8
* The SSR is free software: you can redistribute it and/or modify it under *
9
* the terms of the GNU General Public License as published by the Free *
10
* Software Foundation, either version 3 of the License, or (at your option) *
11
* any later version. *
13
* The SSR is distributed in the hope that it will be useful, but WITHOUT ANY *
14
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
15
* FOR A PARTICULAR PURPOSE. *
16
* See the GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License along *
19
* with this program. If not, see <http://www.gnu.org/licenses/>. *
21
* The SSR is a tool for real-time spatial audio reproduction providing a *
22
* variety of rendering algorithms. *
24
* http://spatialaudio.net/ssr ssr@spatialaudio.net *
25
******************************************************************************/
28
/// TODO: add description
34
#include "qcpulabel.h"
36
QCPULabel::QCPULabel(QWidget* parent, unsigned int update_interval)
37
: QLabel(parent), load(0.0f)
39
setAlignment(Qt::AlignCenter);
41
// update widget every update_interval msec
42
QTimer *timer = new QTimer(this);
43
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
44
timer->start(update_interval);
47
void QCPULabel::set_load(float l)
51
// limit possible values
52
load = std::min(load, 100.0f);
53
load = std::max(load, 0.0f);
58
void QCPULabel::paintEvent(QPaintEvent * event)
63
QLabel::paintEvent(event);
65
QPainter painter(this);
68
painter.setPen(QPen(QColor(237,237,230),1));
70
painter.drawLine(QLine(0,0,width(),0));
71
painter.drawLine(QLine(0,height()-1,width(),height()-1));
72
painter.drawLine(QLine(0,0,0,height()));
73
painter.drawLine(QLine(width()-1,0,width()-1,height()-1));
77
painter.setPen(QPen(QColor(58,239,58)));
78
painter.setBrush(QBrush(QColor(58,239,58))); // green
80
else if (load > 80.0f){
81
painter.setPen(QPen(QColor(255,0,0)));
82
painter.setBrush(QBrush(QColor(255,0,0))); // red // TODO: rgb
85
painter.setPen(QPen(QColor(255,255,0)));
86
painter.setBrush(QBrush(QColor(255,255,0))); // yellow // TODO: rgb
90
painter.drawRect(1, 1, (int)(width()*load/100.0f)-1, height()-3);
93
//setText(QString().setNum((int)(load + 0.5f)));
96
painter.setPen(QPen(QColor(0, 0, 0)));
97
painter.drawText(QRect(0, 1, width(), height()), Qt::AlignCenter, QString().setNum((int)(load + 0.5f)));
101
// Settings for Vim (http://www.vim.org/), please do not remove:
102
// vim:softtabstop=2:shiftwidth=2:expandtab:textwidth=80:cindent
103
// vim:fdm=expr:foldexpr=getline(v\:lnum)=~'/\\*\\*'&&getline(v\:lnum)!~'\\*\\*/'?'a1'\:getline(v\:lnum)=~'\\*\\*/'&&getline(v\:lnum)!~'/\\*\\*'?'s1'\:'='