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

parley

  • sources
  • kde-4.12
  • kdeedu
  • parley
  • src
  • practice
practicesummarycomponent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2007-2009 Frederik Gladhorn <gladhorn@kde.org>
3  ***************************************************************************
4 
5  ***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "practicesummarycomponent.h"
15 #include "prefs.h"
16 
17 #include "parleyactions.h"
18 
19 #include <QTableWidgetItem>
20 #include <keduvocexpression.h>
21 #include <KConfigGroup>
22 #include <KActionCollection>
23 #include <KColorScheme>
24 #include <KToolBar>
25 
26 using namespace Practice;
27 
28 class PracticeSummaryComponent::SortedAttemptTableWidgetItem: public QTableWidgetItem
29 {
30  virtual bool operator<(const QTableWidgetItem &other) const
31  {
32  if (data(Qt::DisplayRole).toInt() == other.data(Qt::DisplayRole).toInt()) {
33  return data(Qt::UserRole).toInt() < other.data(Qt::UserRole).toInt();
34  }
35  return data(Qt::DisplayRole).toInt() < other.data(Qt::DisplayRole).toInt();
36  }
37 };
38 
39 PracticeSummaryComponent::PracticeSummaryComponent(TestEntryManager* testEntryManager, QWidget* parent)
40  :KXmlGuiWindow(parent)
41  ,m_testEntryManager(testEntryManager)
42 {
43  // KXmlGui
44  setXMLFile("practicesummaryui.rc");
45  setObjectName("Statistics");
46 
47  QWidget *mainWidget = new QWidget(this);
48  setupUi(mainWidget);
49  setCentralWidget(mainWidget);
50 
51  initActions(parent);
52 
53  setupDetailsTable();
54  summaryBar->setStatistics(m_testEntryManager->statisticTotalCorrectFirstAttempt(), m_testEntryManager->statisticTotalWrong(), m_testEntryManager->statisticTotalUnanswered());
55 
56  int total = m_testEntryManager->statisticTotalCorrectFirstAttempt() + m_testEntryManager->statisticTotalWrong();
57  int minutes = m_testEntryManager->totalTime() / 60;
58  int seconds = m_testEntryManager->totalTime() % 60;
59 
60  testSummaryLabel->setText(i18nc("number of words, minutes, seconds", "You practiced %1 in %2 and %3.",
61  i18np("one word", "%1 words", total),
62  i18np("one minute", "%1 minutes", minutes),
63  i18np("one second", "%1 seconds", seconds)));
64 
65  KConfigGroup cfg(KSharedConfig::openConfig("parleyrc"), objectName());
66  applyMainWindowSettings(cfg);
67 }
68 
69 PracticeSummaryComponent::~PracticeSummaryComponent()
70 {
71  KConfigGroup cfg(KSharedConfig::openConfig("parleyrc"), objectName());
72  saveMainWindowSettings(cfg);
73 }
74 
75 void PracticeSummaryComponent::initActions(QWidget* parleyMainWindow)
76 {
77  ParleyActions::create(ParleyActions::EnterEditMode, parleyMainWindow, SLOT(showEditor()), actionCollection());
78  ParleyActions::create(ParleyActions::StartPractice, parleyMainWindow, SLOT(showPracticeConfiguration()), actionCollection());
79  actionCollection()->action("practice_start")->setText(i18n("Practice Again"));
80  actionCollection()->action("practice_start")->setToolTip(i18n("Practice Again"));
81 }
82 
83 void PracticeSummaryComponent::setupDetailsTable()
84 {
85  tableWidget->setRowCount(m_testEntryManager->totalEntryCount());
86  tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
87 
88  Qt::ItemFlags flags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
89 
90  KColorScheme scheme(QPalette::Active);
91  QPalette correctPalette = QApplication::palette();
92  correctPalette.setColor(QPalette::WindowText, scheme.foreground(KColorScheme::PositiveText).color());
93  correctPalette.setColor(QPalette::Text, scheme.foreground(KColorScheme::PositiveText).color());
94 
95  QPalette wrongPalette = QApplication::palette();
96  wrongPalette.setColor(QPalette::WindowText, scheme.foreground(KColorScheme::NegativeText).color());
97  wrongPalette.setColor(QPalette::Text, scheme.foreground(KColorScheme::NegativeText).color());
98 
99  int i = 0;
100  // TODO headers with languages
101  // TODO some colors, maybe an indicator icon wether the word was right/wrong
102  foreach(TestEntry* entry, m_testEntryManager->allTestEntries()) {
103  QTableWidgetItem* itemFrom = new QTableWidgetItem(
104  entry->entry()->translation(TestEntry::gradeFrom())->text());
105  QTableWidgetItem* itemTo = new QTableWidgetItem(
106  entry->entry()->translation(TestEntry::gradeTo())->text());
107  if (entry->statisticGoodCount() > 0) {
108  itemTo->setForeground(correctPalette.foreground());
109  }
110 
111  QTableWidgetItem* itemUserAnswer = new QTableWidgetItem(
112  entry->userAnswers().join("; "));
113  itemUserAnswer->setForeground(wrongPalette.foreground());
114 
115  SortedAttemptTableWidgetItem* itemAttempts = new SortedAttemptTableWidgetItem();
116  itemAttempts->setData(Qt::DisplayRole, entry->statisticCount());
117  itemAttempts->setData(Qt::UserRole, entry->statisticBadCount());
118  itemAttempts->setTextAlignment(Qt::AlignRight);
119 
120  itemFrom->setFlags(flags);
121  itemTo->setFlags(flags);
122  itemUserAnswer->setFlags(flags);
123  itemAttempts->setFlags(flags);
124 
125  if (entry->correctAtFirstAttempt()) {
126  itemUserAnswer->setIcon(KIcon("dialog-ok-apply"));
127  } else if (entry->statisticGoodCount() > 0) {
128  itemUserAnswer->setIcon(KIcon("task-attempt"));
129  } else if (entry->statisticCount() > 0) {
130  itemUserAnswer->setIcon(KIcon("dialog-error"));
131  } else {
132  itemUserAnswer->setIcon(KIcon("task-attempt"));
133  }
134 
135  tableWidget->setItem(i, 0, itemAttempts);
136  tableWidget->setItem(i, 1, itemFrom);
137  tableWidget->setItem(i, 2, itemTo);
138  tableWidget->setItem(i, 3, itemUserAnswer);
139  ++i;
140  }
141 
142  tableWidget->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
143  tableWidget->setSortingEnabled(true);
144  tableWidget->sortItems(0, Qt::DescendingOrder);
145 }
146 
147 
148 #include "practicesummarycomponent.moc"
149 
TestEntry::statisticCount
int statisticCount()
Definition: testentry.cpp:49
Practice::PracticeSummaryComponent::~PracticeSummaryComponent
~PracticeSummaryComponent()
Definition: practicesummarycomponent.cpp:69
ParleyActions::create
KAction * create(ParleyAction id, const QObject *recvr, const char *slot, QObject *parent)
Definition: parleyactions.cpp:62
Practice::TestEntryManager::statisticTotalCorrectFirstAttempt
int statisticTotalCorrectFirstAttempt()
Finish the given entry.
Definition: testentrymanager.cpp:154
Practice::TestEntryManager::allTestEntries
QList< TestEntry * > allTestEntries()
Get a list of all entries in the test - used by the summary dialog.
Definition: testentrymanager.h:91
QWidget
TestEntry::gradeFrom
static int gradeFrom()
Definition: testentry.cpp:99
TestEntry::statisticGoodCount
int statisticGoodCount()
Definition: testentry.cpp:59
prefs.h
Practice::TestEntryManager
Definition: testentrymanager.h:31
parleyactions.h
TestEntry::gradeTo
static int gradeTo()
Definition: testentry.cpp:104
KXmlGuiWindow
Practice::TestEntryManager::totalTime
int totalTime()
the time in seconds
Definition: testentrymanager.cpp:116
TestEntry::userAnswers
QStringList userAnswers()
Definition: testentry.h:82
Practice::TestEntryManager::totalEntryCount
int totalEntryCount()
The number of entries in the practice.
Definition: testentrymanager.cpp:134
Practice::TestEntryManager::statisticTotalWrong
int statisticTotalWrong()
Definition: testentrymanager.cpp:165
ParleyActions::StartPractice
Definition: parleyactions.h:36
TestEntry::statisticBadCount
int statisticBadCount()
Definition: testentry.cpp:54
ParleyActions::EnterEditMode
Definition: parleyactions.h:37
practicesummarycomponent.h
TestEntry::correctAtFirstAttempt
bool correctAtFirstAttempt()
Definition: testentry.cpp:109
Practice::TestEntryManager::statisticTotalUnanswered
int statisticTotalUnanswered()
Definition: testentrymanager.cpp:176
Practice::PracticeSummaryComponent::PracticeSummaryComponent
PracticeSummaryComponent(TestEntryManager *testEntryManager, QWidget *parent)
Definition: practicesummarycomponent.cpp:39
TestEntry::entry
KEduVocExpression * entry()
Definition: testentry.cpp:134
TestEntry
Definition: testentry.h:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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