• 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
  • editor
FromToEntryPage.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  edit properties from/to original
4 
5  -----------------------------------------------------------------------
6 
7  begin : Mon Jun 28 21:02:16 1999
8 
9  copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
10  (C) 2005-2007 Peter Hedlund <peter.hedlund@kdemail.net>
11  (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
12 
13  -----------------------------------------------------------------------
14 
15  ***************************************************************************/
16 
17 /***************************************************************************
18  * *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or *
22  * (at your option) any later version. *
23  * *
24  ***************************************************************************/
25 
26 #include "FromToEntryPage.h"
27 
28 #include <QPushButton>
29 #include <QGroupBox>
30 
31 #include <klocale.h>
32 #include <KComboBox>
33 #include <KLineEdit>
34 
35 #include "EntryDlg.h"
36 
37 
38 // this has nothing really to do with the rest. stays here until it has a better home.
39 QString FromToEntryPage::gradeToString(int i)
40 {
41  switch (i) {
42  case KV_NORM_GRADE:
43  return i18n(KV_NORM_TEXT);
44  break;
45  case KV_LEV1_GRADE:
46  return i18n(KV_LEV1_TEXT);
47  break;
48  case KV_LEV2_GRADE:
49  return i18n(KV_LEV2_TEXT);
50  break;
51  case KV_LEV3_GRADE:
52  return i18n(KV_LEV3_TEXT);
53  break;
54  case KV_LEV4_GRADE:
55  return i18n(KV_LEV4_TEXT);
56  break;
57  case KV_LEV5_GRADE:
58  return i18n(KV_LEV5_TEXT);
59  break;
60  case KV_LEV6_GRADE:
61  return i18n(KV_LEV6_TEXT);
62  break;
63  case KV_LEV7_GRADE:
64  return i18n(KV_LEV7_TEXT);
65  break;
66  default:
67  return i18n(KV_LEV1_TEXT);
68  break;
69  }
70 }
71 
72 
73 FromToEntryPage::FromToEntryPage(KEduVocDocument *doc, int fromIdentifier, int toIdentifier, QWidget *parent) : QWidget(parent)
74 {
75  m_doc = doc;
76 
77  m_translationFrom = fromIdentifier;
78  m_translationTo = toIdentifier;
79 
80  setupUi(this);
81 
82  connect(fauxami_line, SIGNAL(textChanged(const QString&)), this, SLOT(slotFalseFriendChanged(const QString &)));
83 
84  connect(never, SIGNAL(clicked()), this, SLOT(slotNever()));
85  connect(today, SIGNAL(clicked()), this, SLOT(slotToday()));
86  connect(gradebox, SIGNAL(activated(int)), this, SLOT(slotGradeSelected(int)));
87 
88  connect(queryDateEdit, SIGNAL(dateChanged(const QDate &)), this, SLOT(slotDateChanged(const QDate &)));
89  connect(totalCountEdit, SIGNAL(valueChanged(int)), this, SLOT(totalCountChanged(int)));
90  connect(badCountEdit, SIGNAL(valueChanged(int)), this, SLOT(badCountChanged(int)));
91 
92  connect(resetGradesButton, SIGNAL(clicked()), SLOT(slotResetGrades()));
93 
94  for (int i = 0; i <= KV_MAX_GRADE; i++) {
95  gradebox->addItem(gradeToString(i));
96  }
97 
98 }
99 
100 
101 void FromToEntryPage::slotFalseFriendChanged(const QString& s)
102 {
103  Q_UNUSED(s)
104  emit sigModified();
105 }
106 
107 
108 void FromToEntryPage::slotGradeSelected(int g)
109 {
110  m_gradeChanged = true;
111  Q_UNUSED(g)
112  emit sigModified();
113 }
114 
115 
116 void FromToEntryPage::slotToday()
117 {
118  m_practiceDateChanged = true;
119  queryDateEdit->setDateTime(QDateTime::currentDateTime());
120  emit sigModified();
121 }
122 
123 
124 void FromToEntryPage::slotNever()
125 {
126  m_practiceDateChanged = true;
127  queryDateEdit->setDate(queryDateEdit->minimumDate());
128  queryDateEdit->setTime(queryDateEdit->minimumTime());
129  emit sigModified();
130 }
131 
132 
133 void FromToEntryPage::slotDateChanged(const QDate & d)
134 {
135  m_practiceDateChanged = true;
136  Q_UNUSED(d)
137  emit sigModified();
138 }
139 
140 void FromToEntryPage::totalCountChanged(int count)
141 {
142  m_totalCountChanged = true;
143  Q_UNUSED(count)
144  emit sigModified();
145 }
146 
147 void FromToEntryPage::badCountChanged(int count)
148 {
149  m_wrongCountChanged = true;
150  Q_UNUSED(count)
151  emit sigModified();
152 }
153 
154 
155 void FromToEntryPage::setData(const QList<int>& entries)
156 {
157  m_entries = entries;
158 
159  // only set Grades as title for now:
160  direc_label->setTitle(QString(i18n("Confidence Levels from %1 to %2", m_doc->identifier(m_translationFrom).name(), m_doc->identifier(m_translationTo).name())));
161 
162  KEduVocExpression *firstEntry = m_doc->entry(m_entries.value(0));
163 
164  queryDateEdit->setDateTime(
165  firstEntry->translation(m_translationTo)
166  .gradeFrom(m_translationFrom).practiceDate());
167 
168  gradebox->setCurrentIndex(firstEntry->translation(m_translationTo).gradeFrom(m_translationFrom).grade());
169 
170  totalCountEdit->setValue(firstEntry->translation(m_translationTo).gradeFrom(m_translationFrom).practiceCount());
171 
172  badCountEdit->setValue(firstEntry->translation(m_translationTo).gradeFrom(m_translationFrom).badCount());
173 
174  if (m_entries.count() > 1) {
175  // fill enabled fields if equal for all edited entries, otherwise empty.
176  foreach(int entry, m_entries) {
177  // grade
178  KEduVocExpression *currentEntry = m_doc->entry(entry);
179  if (firstEntry->translation(m_translationTo)
180  .gradeFrom(m_translationFrom).grade()
181  != currentEntry->translation(m_translationTo)
182  .gradeFrom(m_translationFrom).grade()) {
183  gradebox->setCurrentIndex(-1);
184  }
185  // date
186  if (firstEntry->translation(m_translationTo)
187  .gradeFrom(m_translationFrom).practiceDate()
188  != currentEntry->translation(m_translationTo)
189  .gradeFrom(m_translationFrom).practiceDate()) {
190  queryDateEdit->setDate(queryDateEdit->minimumDate());
191  queryDateEdit->setTime(queryDateEdit->minimumTime());
192  }
193 
194  // total count
195  if (firstEntry->translation(m_translationTo)
196  .gradeFrom(m_translationFrom).practiceCount()
197  != currentEntry->translation(m_translationTo)
198  .gradeFrom(m_translationFrom).practiceCount()) {
199  totalCountEdit->clear();
200  }
201 
202  // wrong count
203  if (firstEntry->translation(m_translationTo)
204  .gradeFrom(m_translationFrom).badCount()
205  != currentEntry->translation(m_translationTo)
206  .gradeFrom(m_translationFrom).badCount()) {
207  badCountEdit->clear();
208  }
209 
210  }
211  fauxami_line->setEnabled(false);
212  fauxami_line->setText(QString());
213  } else {
214  fauxami_line->setEnabled(true);
215  fauxami_line->setText(firstEntry->translation(m_translationTo).falseFriend(m_translationFrom));
216  }
217 
218  m_gradeChanged = false;
219  m_practiceDateChanged = false;
220  m_totalCountChanged = false;
221  m_wrongCountChanged = false;
222 
223 }
224 
225 void FromToEntryPage::commitData()
226 {
227  kDebug() << "Grade page commit data: " << m_translationFrom << m_translationTo;
228  if (m_entries.count() == 1) {
229  // these things are only changed when editing a single entry
230  KEduVocTranslation * trans = &m_doc->entry(m_entries.value(0))->translation(m_translationTo);
231  trans->setFalseFriend(m_translationFrom, fauxami_line->text());
232  }
233 
234  // things that are changed for multiple or single entries
235  foreach(int entry, m_entries) {
236  if (m_gradeChanged) {
237  m_doc->entry(entry)->translation(m_translationTo).gradeFrom(m_translationFrom).setGrade(gradebox->currentIndex());
238  }
239  if (m_totalCountChanged) {
240  m_doc->entry(entry)->translation(m_translationTo).gradeFrom(m_translationFrom).setPracticeCount(totalCountEdit->value());
241  }
242  if (m_wrongCountChanged) {
243  m_doc->entry(entry)->translation(m_translationTo).gradeFrom(m_translationFrom).setBadCount(badCountEdit->value());
244  }
245  if (m_practiceDateChanged) {
246  m_doc->entry(entry)->translation(m_translationTo).gradeFrom(m_translationFrom).setPracticeDate(queryDateEdit->dateTime());
247  }
248  }
249 }
250 
251 void FromToEntryPage::slotResetGrades()
252 {
253  queryDateEdit->setDate(queryDateEdit->minimumDate());
254  queryDateEdit->setTime(queryDateEdit->minimumTime());
255 
256  gradebox->setCurrentIndex(KV_MIN_GRADE);
257  totalCountEdit->setValue(0);
258  badCountEdit->setValue(0);
259 
260  m_gradeChanged = true;
261  m_practiceDateChanged = true;
262  m_totalCountChanged = true;
263  m_wrongCountChanged = true;
264 
265 // emit sigModified();
266 }
267 
268 
269 #include "FromToEntryPage.moc"
270 
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
FromToEntryPage::commitData
void commitData()
Definition: FromToEntryPage.cpp:225
QList::value
T value(int i) const
QList::count
int count(const T &value) const
FromToEntryPage
Definition: FromToEntryPage.h:36
QDate
QString
QList
QDateTime::currentDateTime
QDateTime currentDateTime()
FromToEntryPage::setData
void setData(const QList< int > &entries)
Definition: FromToEntryPage.cpp:155
FromToEntryPage.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
FromToEntryPage::FromToEntryPage
FromToEntryPage(KEduVocDocument *doc, int fromIdentifier, int toIdentifier, QWidget *parent=0)
Definition: FromToEntryPage.cpp:73
FromToEntryPage::sigModified
void sigModified()
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