[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [parley/KDE/4.14] src: Step IIb of solving the color issue: make the legend use the generic color ba
From: Inge Wallin <inge () lysator ! liu ! se>
Date: 2015-02-05 0:07:53
Message-ID: E1YJ9z7-0002a5-3l () scm ! kde ! org
[Download RAW message or body]
Git commit e4a289ff2cb10475968d7933d80dc55d20417e8e by Inge Wallin.
Committed on 04/02/2015 at 23:07.
Pushed by ingwa into branch 'KDE/4.14'.
Step IIb of solving the color issue: make the legend use the generic color bar painter
This step also finally removes all the old cruft that is no longer needed.
M +13 -109 src/statistics/statisticslegendwidget.cpp
M +1 -30 src/statistics/statisticslegendwidget.h
M +1 -2 src/utils.cpp
http://commits.kde.org/parley/e4a289ff2cb10475968d7933d80dc55d20417e8e
diff --git a/src/statistics/statisticslegendwidget.cpp b/src/statistics/statisticslegendwidget.cpp
index 35b0219..c307da9 100644
--- a/src/statistics/statisticslegendwidget.cpp
+++ b/src/statistics/statisticslegendwidget.cpp
@@ -31,7 +31,7 @@
// Parley
#include <keduvocexpression.h>
-#include "prefs.h"
+#include "utils.h"
StatisticsLegendWidget::StatisticsLegendWidget(QWidget * parent)
@@ -50,109 +50,6 @@ StatisticsLegendWidget::StatisticsLegendWidget(QWidget * parent)
}
-QColor StatisticsLegendWidget::gradeColor(int grade)
-{
- QColor color(Prefs::gradeColor());
- color.setAlpha(alphaMax - (KV_MAX_GRADE - grade - 1) * alphaStep);
- return color;
-}
-
-QColor StatisticsLegendWidget::preGradeColor()
-{
- QColor color(Prefs::preGradeColor());
- color.setAlpha(alphaMax);
- return color;
-}
-
-QColor StatisticsLegendWidget::unpracticedColor()
-{
- QColor color("#FFFFFF");
- color.setAlpha(alphaMax);
- return color;
-}
-
-QColor StatisticsLegendWidget::invalidColor()
-{
- return Prefs::invalidUnitColor();
-}
-
-QList< QVariant > StatisticsLegendWidget::legendFractions(KEduVocContainer & container, int index)
-{
- QVector<double> sums(KV_MAX_GRADE + fractionsOffset + 1, 0);
- double count(0);
-
- // 'index' is the index of the translation inside the KEduVocExpression.
- foreach (KEduVocExpression *entry, container.entries(KEduVocContainer::Recursive)) {
- KEduVocTranslation & trans(*entry->translation(index));
- ++count;
- if (!trans.isEmpty()) {
- if (trans.grade() != 0) {
- sums[trans.grade() + fractionsOffset - 1] += 1;
- } else {
- if (trans.preGrade() != 0) {
- sums[2] += 1;
- } else {
- sums[1] += 1; //unpracticed
- }
- }
- } else {
- sums[0] += 1; //invalid
- }
- }
-
- QList< QVariant > fractions;
- for (int ii = 0 ;ii < KV_MAX_GRADE + fractionsOffset; ++ii) {
- fractions.push_back((double) (sums[ii] / count));
- }
-
- return fractions;
-}
-
-void StatisticsLegendWidget::paintStatisticsBar(QPainter &painter, const QRect &rect,
- const QList< QVariant> &fractions)
-{
- QRect roundedRect(rect);
- roundedRect.adjust(1, 1, -1, -1);
- QPainterPath roundedPath;
- roundedPath.addRoundedRect(roundedRect, 2.0, 2.0);
-
- QColor color;
- int xPosition = 0;
- for (int ii = KV_MAX_GRADE + fractionsOffset - 1; ii >= 0; --ii) {
- double fraction(fractions[ii].toDouble());
- int barElementWidth = fraction * rect.width();
- QRectF barElement(rect.x() + xPosition, rect.y(), barElementWidth, rect.height());
- QPainterPath barElementPath;
- barElementPath.addRect(barElement);
- xPosition += barElementWidth;
-
- // Intersect the QPainterPath of inner rectangle with outer,
- // so that the inner rectangle takes the shape of the outer rounded rectangle.
- QPainterPath barElementIntersectedPath = roundedPath.intersected(barElementPath);
-
- if (ii >= fractionsOffset) {
- color = StatisticsLegendWidget::gradeColor(ii - fractionsOffset);
- } else {
- switch (ii) {
- case 2:
- color = StatisticsLegendWidget::preGradeColor();
- break;
- case 1:
- color = StatisticsLegendWidget::unpracticedColor();
- break;
- case 0:
- default:
- color = StatisticsLegendWidget::invalidColor();
- break;
- }
- }
-
- painter.setBrush(QBrush(color));
- painter.drawPath(barElementIntersectedPath);
- }
-}
-
-
void StatisticsLegendWidget::paintEvent(QPaintEvent *)
{
const int legendWidth = 320;
@@ -184,13 +81,20 @@ void StatisticsLegendWidget::paintEvent(QPaintEvent *)
rightRect.moveBottomLeft(QPoint(legendOffsetX + legendWidth + horizontalDistanceFromLegend,
legendOffsetY + legendHeight));
+ // Draw the legend color bar.
QRect rect(x() + legendOffsetX, legendOffsetY, legendWidth, legendHeight);
- QList<QVariant> fractions(
- QList<QVariant>::fromVector(
- QVector<QVariant>(KV_MAX_GRADE + fractionsOffset + 1,
- (double) 1.0 / (KV_MAX_GRADE + fractionsOffset))));
- paintStatisticsBar(painter, rect, fractions);
+ WordCount wordCount;
+ for (int i = 0; i <= KV_MAX_GRADE; ++i) {
+ wordCount.grades[i] = 1;
+ }
+ wordCount.invalid = 1;
+ wordCount.initialWords = 1;
+ wordCount.totalWords = 10;
+
+ ConfidenceColors colors(ConfidenceColors::ProgressiveColorScheme);
+ paintColorBar(painter, rect, wordCount, colors);
+ // Draw the legend texts
painter.setPen(Qt::black);
painter.drawText(leftRect, Qt::AlignRight | Qt::AlignVCenter, leftString);
painter.drawText(rightRect, Qt::AlignLeft | Qt::AlignVCenter, rightString);
diff --git a/src/statistics/statisticslegendwidget.h b/src/statistics/statisticslegendwidget.h
index 6caf326..86394f8 100644
--- a/src/statistics/statisticslegendwidget.h
+++ b/src/statistics/statisticslegendwidget.h
@@ -38,40 +38,11 @@ public:
/// constructor
StatisticsLegendWidget(QWidget * parent = 0);
- /**@brief the color of the @p grade
- @param grade
- @returns the color **/
- static QColor gradeColor(int grade);
- /**@returns the color of the preGrade stats
- **/
- static QColor preGradeColor();
- /**@returns the color of the unpracticed entries**/
- static QColor unpracticedColor();
- /**@returns the color of the invalid entries**/
- static QColor invalidColor();
-
- /** Calculate the fractions passed to paintStatisticsBar
- of late/early/unpracticed and invalid types.
- @returns calculated fractions practice statistics for @p container at @p index .**/
- static QList<QVariant> legendFractions(KEduVocContainer &container, int index);
-
- /** With a @p painter draw the stats bar with @p fractions within @p rect
- @param painter supplied painter
- @param rect bounding box
- @param fractions the fractional widths of each of the grade categories
- **/
- static void paintStatisticsBar(QPainter &painter, const QRect &rect,
- const QList< QVariant> &fractions);
protected:
/// paintEvent @p e event
void paintEvent(QPaintEvent *e);
-private:
- static const int alphaMax = 255; ///< full brightness
- /// steps small enought that the last is still visible
- static const int alphaStep = ((alphaMax - 10) / KV_MAX_GRADE);
- /// offset of table for unpracticed, invalid and preGrade types
- static const int fractionsOffset = 3;
};
+
#endif
diff --git a/src/utils.cpp b/src/utils.cpp
index 2d24471..787def2 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -130,14 +130,13 @@ void ConfidenceColors::initColors(ColorScheme colorScheme)
{
static const int AlphaMax = 255;
static const int AlphaStep = ((AlphaMax - 10) / KV_MAX_GRADE);
- //static const int fractionsOffset = 3;
QColor color;
// Confidence 1..max
for (int grade = 1; grade <= KV_MAX_GRADE; ++grade) {
color = Prefs::gradeColor();
- color.setAlpha(AlphaMax - (KV_MAX_GRADE - grade - 1) * AlphaStep);
+ color.setAlpha(AlphaMax - (KV_MAX_GRADE - grade) * AlphaStep);
longTermColors[grade] = color;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic