File indexing completed on 2022-11-22 13:00:59

0001 /*
0002     SPDX-FileCopyrightText: 2014 Andreas Xavier
0003     SPDX-FileCopyrightText: 2014 Inge Wallin <inge@lysator.liu.se>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 // Own
0008 #include "gradereferencewidget.h"
0009 
0010 // Qt
0011 #include <QDebug>
0012 #include <QPainter>
0013 #include <QPainterPath>
0014 #include <QPen>
0015 
0016 // KDE
0017 #include <KLocalizedString>
0018 
0019 // Parley
0020 #include "barwidget.h" // for gradeColor^WglobalColors
0021 
0022 GradeReferenceWidget::GradeReferenceWidget(QWidget *parent)
0023     : QWidget(parent)
0024 {
0025 }
0026 
0027 void GradeReferenceWidget::paintEvent(QPaintEvent *)
0028 {
0029     QPainter painter(this);
0030     const int legendWidth = this->width();
0031     const int legendHeight = this->height();
0032     const int legendOffsetY = 0;
0033     const int legendOffsetX = (this->width() / 2) - (legendWidth / 2);
0034     const int gradeBarWidth = this->width() / 8;
0035     // const int alphaValueIncrement = 35;
0036     QRect roundedRect(0 + legendOffsetX, 0 + legendOffsetY, legendWidth, legendHeight);
0037     roundedRect.adjust(1, 1, -1, -1);
0038     QPainterPath roundedPath;
0039     roundedPath.addRoundedRect(roundedRect, 2.0, 2.0);
0040 
0041     for (int i = 7; i >= 0; --i) {
0042         QRectF barElement(0 + legendOffsetX + (7 - i) * gradeBarWidth, 0 + legendOffsetY, gradeBarWidth, legendHeight);
0043         QPainterPath barElementPath;
0044         barElementPath.addRect(barElement);
0045         QPainterPath barElementIntersectedPath = roundedPath.intersected(barElementPath);
0046         QColor color = globalColors.longTermColors[i];
0047         painter.setBrush(QBrush(color));
0048         painter.drawPath(barElementIntersectedPath);
0049     }
0050 }