File indexing completed on 2022-12-06 18:52:34

0001 /*
0002     SPDX-FileCopyrightText: 2008 Danilo Balzaque <danilo.balzaque@ltia.fc.unesp.br>
0003     SPDX-FileCopyrightText: 2008 Tadeu Araujo <tadeu.araujo@ltia.fc.unesp.br>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "StatisticsBarWidget.h"
0009 
0010 /* these includes are needed for Qt support */
0011 #include <QGridLayout>
0012 #include <QLabel>
0013 #include <QProgressBar>
0014 
0015 #ifdef DEBUG
0016 #include <QDebug>
0017 #endif
0018 
0019 #include "settingsclass.h"
0020 
0021 /* constructor */
0022 StatisticsBarWidget::StatisticsBarWidget(QWidget * parent) :
0023     QWidget(parent)
0024 {
0025 #ifdef DEBUG
0026     qDebug() << QStringLiteral("constructor StatisticsBarWidget()");
0027 #endif
0028     m_correct = 0;
0029     m_skipped = 0;
0030     m_total = 0;
0031 
0032     defaultFont = SettingsClass::taskFont();
0033     defaultFont.setBold(true);
0034     defaultFont.setPointSize(10);
0035 
0036     QGridLayout * barLayout = new QGridLayout();
0037 
0038     m_correctBar = new QProgressBar(this);
0039     m_correctBar->setTextVisible(false);
0040     QPalette progressPalette;
0041     progressPalette.setColor(QPalette::Window, QColor(192, 234, 194));
0042     progressPalette.setColor(QPalette::Highlight, Qt::green);
0043     m_correctBar->setPalette(progressPalette);
0044     m_correctBar->setMinimumSize(QSize(210, 14));
0045     m_correctBar->setRange(0, 100);
0046     m_correctBar->setValue(0);
0047 
0048     m_incorrectBar = new QProgressBar(this);
0049     m_incorrectBar->setTextVisible(false);
0050     progressPalette.setColor(QPalette::Window, QColor(234, 192, 192));
0051     progressPalette.setColor(QPalette::Highlight, Qt::red);
0052     m_incorrectBar->setPalette(progressPalette);
0053     m_incorrectBar->setMinimumSize(QSize(210, 14));
0054     m_incorrectBar->setRange(0, 100);
0055     m_incorrectBar->setValue(0);
0056 
0057     m_skippedBar = new QProgressBar(this);
0058     m_skippedBar->setTextVisible(false);
0059     progressPalette.setColor(QPalette::Window, QColor(233, 234, 192));
0060     progressPalette.setColor(QPalette::Highlight, Qt::yellow);
0061     m_skippedBar->setPalette(progressPalette);
0062     m_skippedBar->setMinimumSize(QSize(210, 14));
0063     m_skippedBar->setRange(0, 100);
0064     m_skippedBar->setValue(0);
0065 
0066     m_correctLabel = new QLabel(QStringLiteral("0%"), this);
0067     m_correctLabel->setFont(defaultFont);
0068     m_correctLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
0069     m_incorrectLabel = new QLabel(QStringLiteral("0%"), this);
0070     m_incorrectLabel->setFont(defaultFont);
0071     m_incorrectLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
0072     m_skippedLabel = new QLabel(QStringLiteral("0%"), this);
0073     m_skippedLabel->setFont(defaultFont);
0074     m_skippedLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
0075 
0076     barLayout->addWidget(m_correctBar, 0, 0, Qt::AlignVCenter | Qt::AlignLeft);
0077     barLayout->addWidget(m_incorrectBar, 1, 0, Qt::AlignVCenter | Qt::AlignLeft);
0078     barLayout->addWidget(m_skippedBar, 2, 0, Qt::AlignVCenter | Qt::AlignLeft);
0079 
0080     barLayout->addWidget(m_correctLabel, 0, 1);
0081     barLayout->addWidget(m_incorrectLabel, 1, 1);
0082     barLayout->addWidget(m_skippedLabel, 2, 1);
0083 
0084     setLayout(barLayout);
0085 }
0086 
0087 /* destructor */
0088 StatisticsBarWidget::~StatisticsBarWidget()
0089 {
0090 #ifdef DEBUG
0091     qDebug() << QStringLiteral("destructor StatisticsBarWidget()");
0092 #endif
0093 }
0094 
0095 void StatisticsBarWidget::updateBar(int correct, int skipped, int total)
0096 {
0097 #ifdef DEBUG
0098     qDebug() << QStringLiteral("StatisticsBarWidget::updateBar()");
0099 #endif
0100     m_correct = correct;
0101     m_skipped = skipped;
0102     m_total = total;
0103 
0104     m_correctBar->setRange(0, m_total);
0105     m_correctBar->setValue(correct);
0106 
0107     m_incorrectBar->setRange(0, m_total);
0108     m_incorrectBar->setValue(m_total - m_correct - m_skipped);
0109 
0110     m_skippedBar->setRange(0, m_total);
0111     m_skippedBar->setValue(m_skipped);
0112 
0113     m_incorrectLabel->setText(m_incorrectBar->text());
0114     m_skippedLabel->setText(m_skippedBar->text());
0115     m_correctLabel->setText(m_correctBar->text());
0116 
0117     update();
0118 }