Mercurial > hg > easaier-soundaccess
comparison widgets/ConfidenceWidget.cpp @ 108:c107866fd387
first draft to the list result
author | benoitrigolleau |
---|---|
date | Fri, 14 Sep 2007 16:44:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
107:c3ac34b2e45b | 108:c107866fd387 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sound Access | |
5 EASAIER client application. | |
6 Silogic 2007. Benoit Rigolleau. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #include "ConfidenceWidget.h" | |
16 #include <QPainter> | |
17 #include <QString> | |
18 | |
19 ConfidenceWidget::ConfidenceWidget(QWidget *parent, int confidence):QWidget(parent){ | |
20 setConfidence(confidence); | |
21 } | |
22 | |
23 void ConfidenceWidget::setConfidence(int confidence){ | |
24 m_confidence=confidence; | |
25 } | |
26 int ConfidenceWidget::confidence(){ | |
27 return m_confidence; | |
28 } | |
29 | |
30 void ConfidenceWidget::paintEvent(QPaintEvent *event){ | |
31 QPainter painter(this); | |
32 painter.setRenderHint(QPainter::Antialiasing, false); | |
33 draw(&painter); | |
34 | |
35 } | |
36 | |
37 void ConfidenceWidget::draw(QPainter *painter){ | |
38 int marging = 2; | |
39 int confidenceHeight = 12; | |
40 int labelHeight = confidenceHeight/3; | |
41 | |
42 QColor niceGreen(QRgb(0xffdbf756)); | |
43 QLinearGradient rectRadian(0,0,0,confidenceHeight); | |
44 rectRadian.setColorAt(0.0,Qt::black); | |
45 rectRadian.setColorAt(0.2,niceGreen); | |
46 rectRadian.setColorAt(0.5,Qt::lightGray); | |
47 rectRadian.setColorAt(0.8,Qt::white); | |
48 rectRadian.setColorAt(1.0,Qt::black); | |
49 //painter->setBrush(rectRadian); | |
50 | |
51 painter->translate(0,height()/2-confidenceHeight/2-labelHeight/2+4); | |
52 | |
53 // the green rectangle | |
54 painter->setPen(QPen(palette().foreground(),1,Qt::NoPen,Qt::RoundCap)); | |
55 //painter->setBrush(QBrush(palette().highlight().color(),Qt::SolidPattern)); | |
56 painter->setBrush(rectRadian); | |
57 painter->drawRect(marging,0,(width()-2*marging)*(m_confidence/100.0),confidenceHeight); | |
58 | |
59 //the empty rectangle | |
60 QPen(palette().foreground(),1,Qt::SolidLine,Qt::RoundCap); | |
61 painter->setPen(QPen(palette().foreground(),1,Qt::SolidLine,Qt::RoundCap)); | |
62 painter->setBrush(QBrush(palette().highlight().color(),Qt::NoBrush)); | |
63 painter->drawRect(marging,0,width()-2*marging,confidenceHeight); | |
64 | |
65 //the text | |
66 QString text_integer; | |
67 text_integer = text_integer.setNum(m_confidence); | |
68 painter->drawText(marging,-1,QString(text_integer+"%")); | |
69 | |
70 painter->setPen(QPen(palette().foreground(),1,Qt::SolidLine,Qt::RoundCap)); | |
71 int step = (width()-2*marging)/4; | |
72 for(int i=1;i<4;i++){ | |
73 painter->drawLine(marging+i*step,confidenceHeight,marging+i*step,confidenceHeight+labelHeight); | |
74 } | |
75 } |