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

kanagram

  • sources
  • kde-4.12
  • kdeedu
  • kanagram
  • src
  • desktop
vocabedit.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Joshua Keel *
3  * joshuakeel@gmail.com *
4  * *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20  ***************************************************************************/
21 
22 #include "vocabedit.h"
23 
24 #include <qpushbutton.h>
25 #include <qlistwidget.h>
26 #include <qlineedit.h>
27 #include <qfile.h>
28 #include <qstring.h>
29 #include <qvector.h>
30 
31 #include <kstandarddirs.h>
32 #include <kglobal.h>
33 #include <kurl.h>
34 #include <kmessagebox.h>
35 #include <klocale.h>
36 
37 #include "keduvocdocument.h"
38 #include "keduvocexpression.h"
39 #include "vocabsettings.h"
40 #include <kanagramsettings.h>
41 
42 
43 VocabEdit::VocabEdit(QWidget *parent, const QString &fileName) : QDialog(parent), m_fileName("")
44 {
45  setupUi(this);
46 
47  if(!fileName.isEmpty())
48  {
49  m_fileName = fileName;
50  KEduVocDocument *doc = new KEduVocDocument(this);
51  doc->open(KUrl::fromPath(m_fileName));
52  for(int i = 0; i < doc->lesson()->entryCount(KEduVocLesson::Recursive); i++)
53  {
54  KEduVocExpression expr = *doc->lesson()->entries(KEduVocLesson::Recursive).value(i);
55  m_vocabList.append(expr);
56  lboxWords->addItem(doc->lesson()->entries(KEduVocLesson::Recursive).value(i)->translation(0)->text());
57  }
58  txtVocabName->setText(doc->title());
59  txtDescription->setText(doc->documentComment());
60  }
61 
62  connect(btnSave, SIGNAL(clicked()), this, SLOT(slotSave()));
63  connect(btnNewWord, SIGNAL(clicked()), this, SLOT(slotNewWord()));
64  connect(btnRemoveWord, SIGNAL(clicked()), this, SLOT(slotRemoveWord()));
65  connect(btnClose, SIGNAL(clicked()), this, SLOT(slotClose()));
66 
67  connect(txtWord, SIGNAL(textChanged(QString)), this, SLOT(slotWordTextChanged(QString)));
68  connect(txtHint, SIGNAL(textChanged(QString)), this, SLOT(slotHintTextChanged(QString)));
69 
70  //Connect the name and description boxes to a general textChanged slot, so that we can keep track of
71  //whether they've been changed or not
72  connect(txtVocabName, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
73  connect(txtDescription, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
74 
75  connect(lboxWords, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
76 
77  //Has anything in the dialog changed?
78  m_textChanged = false;
79 }
80 
81 VocabEdit::~VocabEdit()
82 {
83 }
84 
85 void VocabEdit::slotSave()
86 {
87  KEduVocDocument *doc = new KEduVocDocument(this);
88  doc->setTitle(txtVocabName->text());
89  doc->setDocumentComment(txtDescription->text());
90  KEduVocIdentifier id;
91  doc->appendIdentifier(id);
92  for(int i = 0; i < m_vocabList.size(); i++)
93  {
94  doc->lesson()->appendEntry(&m_vocabList[i]);
95  }
96 
97  QString fileName = txtVocabName->text().toLower().remove(' ') + ".kvtml";
98  doc->saveAs(KUrl::fromPath(KGlobal::dirs()->saveLocation("data", "kvtml/" + KanagramSettings::dataLanguage()) + fileName), KEduVocDocument::Automatic, "kanagram");
99 
100  VocabSettings *settings = (VocabSettings*)this->parentWidget();
101  settings->refreshView();
102  m_textChanged = false;
103 }
104 
105 void VocabEdit::slotClose()
106 {
107  //Has anything in the dialog changed?
108  if(m_textChanged && lboxWords->count() > 0)
109  {
110  int code = KMessageBox::warningYesNo(this, i18n("Would you like to save your changes?"), i18n("Save Changes Dialog"));
111  if(code == KMessageBox::Yes)
112  {
113  slotSave();
114  close();
115  }
116  else
117  close();
118  }
119  else
120  close();
121 }
122 
123 void VocabEdit::slotNewWord()
124 {
125  lboxWords->addItem(i18n("New Item"));
126  KEduVocExpression expr = KEduVocExpression();
127  m_vocabList.append(expr);
128  m_textChanged = true;
129 }
130 
131 void VocabEdit::slotSelectionChanged()
132 {
133  //A little hack to make things work right
134  disconnect(txtWord, SIGNAL(textChanged(QString)), this, SLOT(slotWordTextChanged(QString)));
135  disconnect(txtHint, SIGNAL(textChanged(QString)), this, SLOT(slotHintTextChanged(QString)));
136  if(lboxWords->currentRow() >= 0)
137  {
138  txtWord->setText(m_vocabList[lboxWords->currentRow()].translation(0)->text());
139  txtHint->setText(m_vocabList[lboxWords->currentRow()].translation(0)->comment());
140  }
141  connect(txtWord, SIGNAL(textChanged(QString)), this, SLOT(slotWordTextChanged(QString)));
142  connect(txtHint, SIGNAL(textChanged(QString)), this, SLOT(slotHintTextChanged(QString)));
143 }
144 
145 void VocabEdit::slotWordTextChanged(const QString &changes)
146 {
147  //Make sure there actually is a currentRow()
148  if(lboxWords->currentRow() != -1)
149  {
150  m_vocabList[lboxWords->currentRow()].setTranslation(0, changes);
151  lboxWords->currentItem()->setText(changes);
152  }
153  m_textChanged = true;
154 }
155 
156 void VocabEdit::slotHintTextChanged(const QString &changes)
157 {
158  //Make sure there actually is a currentItem()
159  if(lboxWords->currentRow() != -1)
160  m_vocabList[lboxWords->currentRow()].translation(0)->setComment(changes);
161  m_textChanged = true;
162 }
163 
164 void VocabEdit::slotTextChanged(const QString &changes)
165 {
166  //Make sure we know when text has been modified and not saved, so we
167  //can notify the user
168  m_textChanged = true;
169 
170  //Make gcc happy
171  (void)changes;
172 }
173 
174 void VocabEdit::slotRemoveWord()
175 {
176  if (lboxWords->count()) {
177  m_vocabList.erase(m_vocabList.begin() + lboxWords->currentRow());
178  delete lboxWords->takeItem(lboxWords->currentRow());
179  }
180 
181  m_textChanged = true;
182 }
183 
184 #include "vocabedit.moc"
VocabEdit::~VocabEdit
~VocabEdit()
Definition: vocabedit.cpp:81
VocabEdit::slotTextChanged
void slotTextChanged(const QString &changes)
Definition: vocabedit.cpp:164
QDialog
QWidget
VocabEdit::slotRemoveWord
void slotRemoveWord()
Definition: vocabedit.cpp:174
VocabEdit::VocabEdit
VocabEdit(QWidget *parent)
VocabSettings::refreshView
void refreshView()
reload the list of vocabularies from what's on disk
Definition: vocabsettings.cpp:53
VocabEdit::slotClose
void slotClose()
Definition: vocabedit.cpp:105
kanagramsettings.h
VocabEdit::slotWordTextChanged
void slotWordTextChanged(const QString &changes)
Definition: vocabedit.cpp:145
vocabedit.h
VocabSettings
Vocabulary Settings class.
Definition: vocabsettings.h:34
vocabsettings.h
VocabEdit::slotHintTextChanged
void slotHintTextChanged(const QString &changes)
Definition: vocabedit.cpp:156
KanagramSettings::dataLanguage
static QString dataLanguage()
Get Set the default translation.
Definition: kanagramsettings.h:127
VocabEdit::slotSelectionChanged
void slotSelectionChanged()
Definition: vocabedit.cpp:131
VocabEdit::slotSave
void slotSave()
Definition: vocabedit.cpp:85
VocabEdit::slotNewWord
void slotNewWord()
Definition: vocabedit.cpp:123
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:35 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kanagram

Skip menu "kanagram"
  • Main Page
  • Namespace List
  • 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