• 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
  • dashboard
barwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2014 Andreas Xavier
3  Copyright 2014 Inge Wallin
4  ***************************************************************************/
5 
6 /***************************************************************************
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  ***************************************************************************/
14 
15 
16 // Own
17 #include "barwidget.h"
18 
19 // Qt
20 #include <QDebug>
21 #include <QWidget>
22 #include <QPainter>
23 #include <QPen>
24 
25 // KDE
26 #include <KDebug>
27 #include <klocalizedstring.h>
28 
29 // Parley
30 #include "collectionwidget.h" // for COLLWIDTH, etc
31 
32 
33 // FIXME: Find a better home for this variable.
34 ConfidenceColors globalColors = ConfidenceColors();
35 
36 
37 BarWidget::BarWidget(QWidget *parent)
38  : QWidget(parent)
39 {
40 
41 }
42 
43 BarWidget::BarWidget(WordCount *dueWords, QWidget *parent)
44  : QWidget(parent)
45 {
46  QPalette palette(BarWidget::palette());
47  palette.setColor(backgroundRole(), Qt::white);
48  setPalette(palette);
49 
50  for (int i = 0; i <= KV_MAX_GRADE; i++) {
51  m_dueWords[i] = dueWords->grades[i];
52  }
53  m_totalDueWords = dueWords->totalWords;
54  m_percentageCompleted = dueWords->percentageCompleted();
55 }
56 
57 
58 void BarWidget::setDue(WordCount &wc)
59 {
60  for (int i = 0; i <= KV_MAX_GRADE; ++i) {
61  m_dueWords[i] = wc.grades[i];
62  }
63  m_totalDueWords = wc.totalWords;
64 
65  update();
66 }
67 
68 
69 void BarWidget::paintEvent(QPaintEvent *)
70 {
71  QPainter painter(this);
72  const int legendWidth = COLLWIDTH - 10;
73  const int legendHeight = 20;
74  const int legendOffsetY = 0;
75  const int legendOffsetX = 0;
76  //const int alphaValueIncrement = 35;
77 
78  int gradeBarWidth[9];
79  gradeBarWidth[8] = 0;
80  int gradeBarOffset[9];
81  gradeBarOffset[8] = 0;
82 
83  //kDebug() << "percentage completed: " << m_percentageCompleted;
84  //kDebug() << "Total due words: " << m_totalDueWords;
85 
86  if (m_percentageCompleted < 100) {
87  for(int j = 7; j >= 0; j--) {
88  gradeBarWidth[j] = (float)(m_dueWords[j]) / (float)(m_totalDueWords) * legendWidth;
89  gradeBarOffset[j] = gradeBarOffset[j+1] + gradeBarWidth[j+1];
90  }
91  }
92  else {
93  for(int j = 6; j >= 0; j--) {
94  gradeBarWidth[j] = 0;
95  gradeBarOffset[j] = legendWidth;
96  }
97  gradeBarWidth[7] = legendWidth;
98  gradeBarOffset[7] = 0;
99  }
100  if (m_percentageCompleted < 100 && m_totalDueWords == 0) {
101  for(int j = 6; j >= 0; j--) {
102  gradeBarWidth[j] = 0;
103  gradeBarOffset[j] = legendWidth;
104  }
105  gradeBarWidth[7] = legendWidth;
106  gradeBarOffset[7] = 0;
107  }
108 
109  QPen penBar(QColor(255,255,255));
110  painter.setPen(penBar);
111  QRect roundedRect(0, 0, legendWidth, legendHeight);
112  roundedRect.adjust(1, 1, -1, -1);
113  QPainterPath roundedPath;
114  roundedPath.addRoundedRect(roundedRect, 8.0, 8.0);
115 
116  for (int i = 7; i >= 0; i--) {
117  QRectF barElement(0 + legendOffsetX + gradeBarOffset[i], 0 + legendOffsetY, gradeBarWidth[i], legendHeight);
118  QPainterPath barElementPath;
119  barElementPath.addRect(barElement);
120  QPainterPath barElementIntersectedPath = roundedPath.intersected(barElementPath);
121  QColor color;
122  if (m_totalDueWords == 0 && m_percentageCompleted < 100) {
123  color = QColor(0, 0, 0, 128);
124  }
125  else {
126  color = globalColors.longTermColors[i];
127  }
128  painter.setBrush(QBrush(color));
129  painter.drawPath(barElementIntersectedPath);
130  }
131 
132  QPen pen(QColor(255,255,255));
133  //QPen pen(QColor(0, 0, 0));
134  painter.setPen(pen);
135  if (m_percentageCompleted < 100) {
136  painter.drawText(0, 0, legendWidth, 20, Qt::AlignCenter,
137  i18np("%1 word due", "%1 words due", m_totalDueWords));
138  }
139  else {
140  painter.drawText(0, 0, legendWidth, 20, Qt::AlignCenter, i18n("Fully learned"));
141  }
142 }
QWidget
QWidget::palette
const QPalette & palette() const
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QPainterPath::addRoundedRect
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
QBrush
ConfidenceColors::longTermColors
QColor longTermColors[KV_MAX_GRADE+1]
Definition: utils.h:60
COLLWIDTH
int COLLWIDTH
Definition: collectionwidget.cpp:33
collectionwidget.h
QWidget::update
void update()
WordCount
Definition: utils.h:30
QRect
BarWidget::BarWidget
BarWidget(QWidget *parent=0)
Definition: barwidget.cpp:37
QPainter::setPen
void setPen(const QColor &color)
BarWidget::paintEvent
void paintEvent(QPaintEvent *)
Definition: barwidget.cpp:69
QWidget::backgroundRole
QPalette::ColorRole backgroundRole() const
QPainter
globalColors
ConfidenceColors globalColors
Definition: barwidget.cpp:34
QPainterPath::addRect
void addRect(const QRectF &rectangle)
BarWidget::setDue
void setDue(WordCount &wc)
Definition: barwidget.cpp:58
QPainter::setBrush
void setBrush(const QBrush &brush)
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QColor
WordCount::percentageCompleted
int percentageCompleted() const
Definition: utils.cpp:51
WordCount::totalWords
int totalWords
Definition: utils.h:45
QPainterPath
QPainter::drawPath
void drawPath(const QPainterPath &path)
QRectF
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
ConfidenceColors
Definition: utils.h:50
QPen
WordCount::grades
int grades[KV_MAX_GRADE+1]
Definition: utils.h:39
QPaintEvent
barwidget.h
QPalette
QPainterPath::intersected
QPainterPath intersected(const QPainterPath &p) const
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