File indexing completed on 2022-11-29 20:01:34

0001 /*******************************************************************
0002  * backtraceratingwidget.cpp
0003  * SPDX-FileCopyrightText: 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  ******************************************************************/
0008 
0009 #include "backtraceratingwidget.h"
0010 
0011 #include <QIcon>
0012 #include <QPainter>
0013 
0014 BacktraceRatingWidget::BacktraceRatingWidget(QWidget *parent)
0015     : QWidget(parent)
0016     , m_state(BacktraceGenerator::NotLoaded)
0017 {
0018     setMinimumSize(105, 24);
0019 
0020     m_starPixmap = QIcon::fromTheme(QStringLiteral("rating")).pixmap(QSize(22, 22));
0021     m_disabledStarPixmap = QIcon::fromTheme(QStringLiteral("rating")).pixmap(QSize(22, 22), QIcon::Disabled);
0022     m_errorPixmap = QIcon::fromTheme(QStringLiteral("dialog-error")).pixmap(QSize(22, 22));
0023 }
0024 
0025 void BacktraceRatingWidget::setUsefulness(BacktraceParser::Usefulness usefulness)
0026 {
0027     switch (usefulness) {
0028     case BacktraceParser::ReallyUseful:
0029         m_numStars = 3;
0030         break;
0031     case BacktraceParser::MayBeUseful:
0032         m_numStars = 2;
0033         break;
0034     case BacktraceParser::ProbablyUseless:
0035         m_numStars = 1;
0036         break;
0037     case BacktraceParser::Useless:
0038     case BacktraceParser::InvalidUsefulness:
0039         m_numStars = 0;
0040         break;
0041     }
0042     update();
0043 }
0044 
0045 void BacktraceRatingWidget::paintEvent(QPaintEvent *event)
0046 {
0047     Q_UNUSED(event);
0048 
0049     QPainter p(this);
0050     p.drawPixmap(QPoint(30, 1), m_numStars >= 1 ? m_starPixmap : m_disabledStarPixmap);
0051     p.drawPixmap(QPoint(55, 1), m_numStars >= 2 ? m_starPixmap : m_disabledStarPixmap);
0052     p.drawPixmap(QPoint(80, 1), m_numStars >= 3 ? m_starPixmap : m_disabledStarPixmap);
0053 
0054     switch (m_state) {
0055     case BacktraceGenerator::Failed:
0056     case BacktraceGenerator::FailedToStart: {
0057         p.drawPixmap(QPoint(0, 1), m_errorPixmap);
0058         break;
0059     }
0060     default:
0061         break;
0062     }
0063 
0064     p.end();
0065 }