• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • statistics
statisticslegendwidget.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Andreas Xavier <andxav at zoho dot com>
3  * Copyright 2014 Inge Wallin
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 3 of
8  * the License or any later version accepted by the membership of
9  * KDE e.V. (or its successor approved by the membership of KDE
10  * e.V.), which shall act as a proxy defined in Section 14 of
11  * version 3 of the license.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 // Own
23 #include "statisticslegendwidget.h"
24 
25 // Qt
26 #include <QDebug>
27 #include <QPainter>
28 
29 // KDE
30 #include <KLocalizedString>
31 
32 // Parley
33 #include <keduvocexpression.h>
34 #include "utils.h"
35 
36 
37 StatisticsLegendWidget::StatisticsLegendWidget(QWidget * parent)
38  : QWidget(parent)
39 {
40  // QString tooltip;
41  // tooltip += "<table><tr><td>"+i18n("Progress gradients")+"</td><td bgcolor=\""
42  // + gradeColor(KV_MAX_GRADE - 1).name()+"\"><nobr> </nobr></td></tr>"
43  // + "<tr><td>"+i18n("Early progress")+"</td><td bgcolor=\""
44  // + preGradeColor().name()+"\"><nobr> </nobr></td></tr>"
45  // + "<tr><td>"+i18n("Not Practiced")+"</td><td bgcolor=\""
46  // + unpracticedColor().name()+"\"><nobr> </nobr></td></tr>"
47  // + "<tr><td>"+i18n("Invalid Entries")+"</td><td bgcolor=\""
48  // + invalidColor().name()+"\" width=\"15%\"><nobr> </nobr></td></tr></table>";
49  // setToolTip(tooltip);
50 }
51 
52 
53 void StatisticsLegendWidget::paintEvent(QPaintEvent *)
54 {
55  const int legendWidth = 320;
56  const int legendHeight = 30;
57  const int legendOffsetY = 10;
58  const int legendOffsetX = (width() / 2) - (legendWidth / 2);
59  const int extraRoomInRectSize = 10;
60  const int horizontalDistanceFromLegend = 10;
61 
62  QPainter painter(this);
63 
64  QString leftString = i18nc("adjective, The word has been properly and fully learned by the user","Fully learned");
65  QString rightString = i18nc("adjective, The word has not even been practiced once by the user","Not practiced");
66  QFontMetrics fontMetrics(painter.font());
67 
68  // Calculate the size and position of the rectangle that will contain the
69  // string on the left side of the legend.
70  QRect leftRect = fontMetrics.boundingRect(leftString);
71  leftRect.setWidth(leftRect.width() + extraRoomInRectSize);
72  leftRect.setHeight(leftRect.height() + extraRoomInRectSize);
73  leftRect.moveBottomRight(QPoint(legendOffsetX - horizontalDistanceFromLegend,
74  legendOffsetY + legendHeight));
75 
76  // Calculate the size and position of the rectangle that will contain the
77  // string on the right side of the legend.
78  QRect rightRect = fontMetrics.boundingRect(rightString);
79  rightRect.setWidth(rightRect.width() + extraRoomInRectSize);
80  rightRect.setHeight(rightRect.height() + extraRoomInRectSize);
81  rightRect.moveBottomLeft(QPoint(legendOffsetX + legendWidth + horizontalDistanceFromLegend,
82  legendOffsetY + legendHeight));
83 
84  // Draw the legend color bar.
85  QRect rect(x() + legendOffsetX, legendOffsetY, legendWidth, legendHeight);
86  WordCount wordCount;
87  for (int i = 0; i <= KV_MAX_GRADE; ++i) {
88  wordCount.grades[i] = 1;
89  }
90  wordCount.invalid = 1;
91  wordCount.initialWords = 1;
92  wordCount.totalWords = 10;
93 
94  ConfidenceColors colors(ConfidenceColors::ProgressiveColorScheme);
95  paintColorBar(painter, rect, wordCount, colors);
96 
97  // Draw the legend texts
98  painter.setPen(Qt::black);
99  painter.drawText(leftRect, Qt::AlignRight | Qt::AlignVCenter, leftString);
100  painter.drawText(rightRect, Qt::AlignLeft | Qt::AlignVCenter, rightString);
101 }
QWidget
ConfidenceColors::ProgressiveColorScheme
Definition: utils.h:53
WordCount::invalid
int invalid
Definition: utils.h:41
QPainter::font
const QFont & font() const
paintColorBar
void paintColorBar(QPainter &painter, const QRect &rect, const WordCount &wordCount, const ConfidenceColors &colors)
Definition: utils.cpp:171
QRect::height
int height() const
QPoint
QFontMetrics
QRect::moveBottomLeft
void moveBottomLeft(const QPoint &position)
WordCount
Definition: utils.h:30
QWidget::width
int width() const
utils.h
QRect
QFontMetrics::boundingRect
QRect boundingRect(QChar ch) const
QWidget::x
int x() const
QPainter::setPen
void setPen(const QColor &color)
QPainter
WordCount::initialWords
int initialWords
Definition: utils.h:43
QRect::setWidth
void setWidth(int width)
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QString
QWidget::rect
QRect rect() const
statisticslegendwidget.h
WordCount::totalWords
int totalWords
Definition: utils.h:45
StatisticsLegendWidget::paintEvent
void paintEvent(QPaintEvent *e)
paintEvent e event
Definition: statisticslegendwidget.cpp:53
QRect::width
int width() const
QWidget::fontMetrics
QFontMetrics fontMetrics() const
StatisticsLegendWidget::StatisticsLegendWidget
StatisticsLegendWidget(QWidget *parent=0)
constructor
Definition: statisticslegendwidget.cpp:37
QRect::setHeight
void setHeight(int height)
ConfidenceColors
Definition: utils.h:50
WordCount::grades
int grades[KV_MAX_GRADE+1]
Definition: utils.h:39
QPaintEvent
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal