~ubuntu-branches/ubuntu/vivid/soundscaperenderer/vivid

« back to all changes in this revision

Viewing changes to src/gui/qcpulabel.cpp

  • Committer: Package Import Robot
  • Author(s): IOhannes m zmölnig (Debian/GNU)
  • Date: 2014-05-08 16:58:09 UTC
  • Revision ID: package-import@ubuntu.com-20140508165809-7tz9dhu5pvo5wy25
Tags: upstream-0.4.1~dfsg
Import upstream version 0.4.1~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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           *
 
5
 *                                                                            *
 
6
 * This file is part of the SoundScape Renderer (SSR).                        *
 
7
 *                                                                            *
 
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.                                                         *
 
12
 *                                                                            *
 
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.                       *
 
17
 *                                                                            *
 
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/>.            *
 
20
 *                                                                            *
 
21
 * The SSR is a tool  for  real-time  spatial audio reproduction  providing a *
 
22
 * variety of rendering algorithms.                                           *
 
23
 *                                                                            *
 
24
 * http://spatialaudio.net/ssr                           ssr@spatialaudio.net *
 
25
 ******************************************************************************/
 
26
 
 
27
/// @file
 
28
/// TODO: add description
 
29
 
 
30
#include <QPainter>
 
31
#include <QTimer>
 
32
#include <algorithm>
 
33
 
 
34
#include "qcpulabel.h"
 
35
 
 
36
QCPULabel::QCPULabel(QWidget* parent, unsigned int update_interval)
 
37
  : QLabel(parent), load(0.0f)
 
38
{
 
39
  setAlignment(Qt::AlignCenter);
 
40
 
 
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);
 
45
}
 
46
 
 
47
void QCPULabel::set_load(float l)
 
48
{
 
49
  load = l;
 
50
 
 
51
  // limit possible values
 
52
  load = std::min(load, 100.0f);
 
53
  load = std::max(load, 0.0f);
 
54
 
 
55
  //  update();
 
56
}
 
57
 
 
58
void QCPULabel::paintEvent(QPaintEvent * event)
 
59
{
 
60
  event->accept();
 
61
 
 
62
  // draw QLabel stuff
 
63
  QLabel::paintEvent(event);
 
64
 
 
65
  QPainter painter(this);
 
66
 
 
67
  // frame
 
68
  painter.setPen(QPen(QColor(237,237,230),1));
 
69
 
 
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));
 
74
 
 
75
  // choose colors
 
76
  if (load <= 60.0f){
 
77
    painter.setPen(QPen(QColor(58,239,58)));
 
78
    painter.setBrush(QBrush(QColor(58,239,58))); // green
 
79
  }
 
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
 
83
  }
 
84
  else {
 
85
    painter.setPen(QPen(QColor(255,255,0)));
 
86
    painter.setBrush(QBrush(QColor(255,255,0))); // yellow // TODO: rgb
 
87
  }
 
88
 
 
89
  // draw load bar
 
90
  painter.drawRect(1, 1, (int)(width()*load/100.0f)-1, height()-3);
 
91
 
 
92
  // set text
 
93
  //setText(QString().setNum((int)(load + 0.5f)));
 
94
 
 
95
  // quick-hack
 
96
  painter.setPen(QPen(QColor(0, 0, 0))); 
 
97
  painter.drawText(QRect(0, 1, width(), height()), Qt::AlignCenter, QString().setNum((int)(load + 0.5f)));
 
98
 
 
99
}
 
100
 
 
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'\:'='