File indexing completed on 2024-04-21 03:51:09
0001 /* 0002 SPDX-FileCopyrightText: 2014 Andreas Xavier <andxav at zoho dot com> 0003 SPDX-FileCopyrightText: 2014 Inge Wallin <inge@lysator.liu.se> 0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 // Own 0008 #include "statisticslegendwidget.h" 0009 0010 // Qt 0011 #include <QDebug> 0012 #include <QPainter> /// 0013 0014 // KDE 0015 #include <KLocalizedString> 0016 0017 // Parley 0018 #include "utils.h" 0019 #include <KEduVocExpression> 0020 0021 StatisticsLegendWidget::StatisticsLegendWidget(QWidget *parent) 0022 : QWidget(parent) 0023 { 0024 ConfidenceColors colors(ConfidenceColors::ProgressiveColorScheme); 0025 0026 QString tooltip; 0027 tooltip += "<table><tr><td>" + i18n("Progress gradients") + "</td><td bgcolor=\"" + colors.longTermColors[KV_MAX_GRADE].name() 0028 + "\"><nobr> </nobr></td></tr>" + "<tr><td>" + i18n("Early progress") + "</td><td bgcolor=\"" + colors.initialTermColor.name() 0029 + "\"><nobr> </nobr></td></tr>" + "<tr><td>" + i18n("Not Practiced") + "</td><td bgcolor=\"" + colors.longTermColors[0].name() 0030 + "\"><nobr> </nobr></td></tr>" + "<tr><td>" + i18n("Invalid Entries") + "</td><td bgcolor=\"" + colors.invalidColor.name() 0031 + "\" width=\"15%\"><nobr> </nobr></td></tr></table>"; 0032 setToolTip(tooltip); 0033 } 0034 0035 void StatisticsLegendWidget::paintEvent(QPaintEvent *) 0036 { 0037 const int legendWidth = 320; 0038 const int legendHeight = 30; 0039 const int legendOffsetY = 10; 0040 const int legendOffsetX = (width() / 2) - (legendWidth / 2); 0041 const int extraRoomInRectSize = 10; 0042 const int horizontalDistanceFromLegend = 10; 0043 0044 QPainter painter(this); 0045 0046 QString leftString = i18nc("adjective, The word has been properly and fully learned by the user", "Fully learned"); 0047 QString rightString = i18nc("adjective, The word has not even been practiced once by the user", "Not practiced"); 0048 QFontMetrics fontMetrics(painter.font()); 0049 0050 // Calculate the size and position of the rectangle that will contain the 0051 // string on the left side of the legend. 0052 QRect leftRect = fontMetrics.boundingRect(leftString); 0053 leftRect.setWidth(leftRect.width() + extraRoomInRectSize); 0054 leftRect.setHeight(leftRect.height() + extraRoomInRectSize); 0055 leftRect.moveBottomRight(QPoint(legendOffsetX - horizontalDistanceFromLegend, legendOffsetY + legendHeight)); 0056 0057 // Calculate the size and position of the rectangle that will contain the 0058 // string on the right side of the legend. 0059 QRect rightRect = fontMetrics.boundingRect(rightString); 0060 rightRect.setWidth(rightRect.width() + extraRoomInRectSize); 0061 rightRect.setHeight(rightRect.height() + extraRoomInRectSize); 0062 rightRect.moveBottomLeft(QPoint(legendOffsetX + legendWidth + horizontalDistanceFromLegend, legendOffsetY + legendHeight)); 0063 0064 // Draw the legend color bar. 0065 QRect rect(x() + legendOffsetX, legendOffsetY, legendWidth, legendHeight); 0066 WordCount wordCount; 0067 for (int i = 0; i <= KV_MAX_GRADE; ++i) { 0068 wordCount.grades[i] = 1; 0069 } 0070 wordCount.invalid = 1; 0071 wordCount.initialWords = 1; 0072 wordCount.totalWords = 10; 0073 0074 ConfidenceColors colors(ConfidenceColors::ProgressiveColorScheme); 0075 paintColorBar(painter, rect, wordCount, colors); 0076 0077 // Draw the legend texts 0078 painter.setPen(QPalette().color(QPalette::WindowText)); 0079 painter.drawText(leftRect, Qt::AlignRight | Qt::AlignVCenter, leftString); 0080 painter.drawText(rightRect, Qt::AlignLeft | Qt::AlignVCenter, rightString); 0081 } 0082 0083 #include "moc_statisticslegendwidget.cpp"