1 | /******************************************************************* |
2 | * backtraceratingwidget.cpp |
3 | * Copyright 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as |
7 | * published by the Free Software Foundation; either version 2 of |
8 | * the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | ******************************************************************/ |
19 | |
20 | #include "backtraceratingwidget.h" |
21 | |
22 | #include <QPainter> |
23 | #include <QPixmap> |
24 | |
25 | #include <KIcon> |
26 | |
27 | BacktraceRatingWidget::BacktraceRatingWidget(QWidget * parent) : |
28 | QWidget(parent), |
29 | m_state(BacktraceGenerator::NotLoaded), |
30 | m_star1(false), |
31 | m_star2(false), |
32 | m_star3(false) |
33 | { |
34 | setMinimumSize(105, 24); |
35 | |
36 | m_starPixmap = KIcon("favorites" ).pixmap(QSize(22, 22)); |
37 | m_disabledStarPixmap = KIcon("favorites" ).pixmap(QSize(22, 22), QIcon::Disabled); |
38 | m_errorPixmap = KIcon("dialog-error" ).pixmap(QSize(22, 22)); |
39 | } |
40 | |
41 | void BacktraceRatingWidget::setUsefulness(BacktraceParser::Usefulness usefulness) |
42 | { |
43 | switch (usefulness) { |
44 | case BacktraceParser::ReallyUseful: { |
45 | m_star1 = true; |
46 | m_star2 = true; |
47 | m_star3 = true; |
48 | break; |
49 | } |
50 | case BacktraceParser::MayBeUseful: { |
51 | m_star1 = true; |
52 | m_star2 = true; |
53 | m_star3 = false; |
54 | break; |
55 | } |
56 | case BacktraceParser::ProbablyUseless: { |
57 | m_star1 = true; |
58 | m_star2 = false; |
59 | m_star3 = false; |
60 | break; |
61 | } |
62 | case BacktraceParser::Useless: |
63 | case BacktraceParser::InvalidUsefulness: { |
64 | m_star1 = false; |
65 | m_star2 = false; |
66 | m_star3 = false; |
67 | break; |
68 | } |
69 | } |
70 | |
71 | update(); |
72 | } |
73 | |
74 | void BacktraceRatingWidget::paintEvent(QPaintEvent * event) |
75 | { |
76 | Q_UNUSED(event); |
77 | |
78 | QPainter p(this); |
79 | |
80 | p.drawPixmap(QPoint(30, 1) , m_star1 ? m_starPixmap : m_disabledStarPixmap); |
81 | p.drawPixmap(QPoint(55, 1) , m_star2 ? m_starPixmap : m_disabledStarPixmap); |
82 | p.drawPixmap(QPoint(80, 1) , m_star3 ? m_starPixmap : m_disabledStarPixmap); |
83 | |
84 | switch (m_state) { |
85 | case BacktraceGenerator::Failed: |
86 | case BacktraceGenerator::FailedToStart: { |
87 | p.drawPixmap(QPoint(0, 1) , m_errorPixmap); |
88 | break; |
89 | } |
90 | case BacktraceGenerator::Loading: |
91 | case BacktraceGenerator::Loaded: |
92 | default: |
93 | break; |
94 | } |
95 | |
96 | p.end(); |
97 | } |
98 | |