• 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
  • settings
languageproperties.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2008 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 "languageproperties.h"
15 
16 #include "languagepropertiespage.h"
17 #include "languagesettings.h"
18 
19 #include <keduvocdocument.h>
20 
21 #include <KMessageBox>
22 #include <QLabel>
23 #include <KLocale>
24 
25 LanguageProperties::LanguageProperties(KEduVocDocument* doc, QWidget * parent)
26  : KPageDialog(parent), m_doc(doc)
27 {
28  setCaption(i18n("Edit Languages"));
29  setFaceType(List);
30  setButtons(User1 | User2 | Ok | Cancel);
31 
32  setButtonText(User2, i18n("Add language"));
33  setButtonIcon(User2, KIcon("list-add"));
34  setButtonText(User1, i18n("Remove language"));
35  setButtonIcon(User1, KIcon("list-remove"));
36 
37  connect(this, SIGNAL(user2Clicked()), this, SLOT(slotAppendIdentifier()));
38  connect(this, SIGNAL(user1Clicked()), this, SLOT(slotDeleteIdentifier()));
39 
40  for (int i = 0; i < m_doc->identifierCount(); i++) {
41  createPage(i);
42  }
43 }
44 
45 KPageWidgetItem* LanguageProperties::createPage(int i)
46 {
47  LanguagePropertiesPage* page = new LanguagePropertiesPage(m_doc, i, this);
48 
49  QString name = i18n("New Language");
50 
51  // check if this language already exists in the doc
52  if (m_doc->identifierCount() <= i) {
53  m_doc->appendIdentifier();
54  }
55  if (m_doc->identifierCount() > i) {
56  name = m_doc->identifier(i).name();
57  LanguageSettings currentSettings(m_doc->identifier(i).locale());
58  currentSettings.readConfig();
59  }
60 
61  KPageWidgetItem* editPage = new KPageWidgetItem(page, name);
62  editPage->setHeader(i18nc("Edit language properties", "Properties for %1", name));
63 
64  m_pages.append(editPage);
65  addPage(editPage);
66 
67  editPage->setIcon(KIcon("set-language"));
68 
69  connect(page->identifierNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(pageNameChanged(const QString&)));
70  connect(this, SIGNAL(accepted()), page, SLOT(accept()));
71 
72  return editPage;
73 }
74 
75 void LanguageProperties::accept()
76 {
77  KEduVocDocument *doc = m_doc;
78  int deleted = 0;
79 
80  for (int index = 0; index < m_pages.count(); index++) {
81  if (m_pages.value(index)->isEnabled()) {
82  if (index - deleted >= doc->identifierCount()) {
83  // add a language
84  doc->appendIdentifier();
85  }
86  LanguagePropertiesPage * page = static_cast<LanguagePropertiesPage *>(m_pages.value(index)->widget());
87  page->setLanguageIdentifierIndex(index - deleted);
88  } else {
89  // page is disabled, delete the language
90  if (index < doc->identifierCount()) {
91  if (KMessageBox::warningYesNo(this, i18n("Really delete language: %1?", doc->identifier(index - deleted).name()), i18n("Remove Language")) == KMessageBox::Yes) {
92  doc->removeIdentifier(index - deleted);
93  deleted++;
94  }
95  }
96  }
97  }
98 
99  KDialog::accept();
100 }
101 
102 
103 void LanguageProperties::slotAppendIdentifier()
104 {
105  // if a page that was "removed" is selected, simply enable it again to not delete it.
106  if (currentPage() && !currentPage()->isEnabled()) {
107  currentPage()->setEnabled(true);
108  return;
109  }
110 
111  int i = m_pages.count();
112  KPageWidgetItem* newPage = createPage(i);
113  setCurrentPage(newPage);
114 }
115 
116 void LanguageProperties::slotDeleteIdentifier()
117 {
118  currentPage()->setEnabled(false);
119 }
120 
121 void LanguageProperties::pageNameChanged(const QString & newName)
122 {
123  currentPage()->setName(newName);
124 }
125 
126 #include "languageproperties.moc"
QWidget
KPageDialog
languagesettings.h
languagepropertiespage.h
LanguagePropertiesPage::setLanguageIdentifierIndex
void setLanguageIdentifierIndex(int newIndex)
Definition: languagepropertiespage.cpp:109
QList::value
T value(int i) const
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QString
languageproperties.h
LanguageSettings
Definition: languagesettings.h:10
LanguagePropertiesPage
Definition: languagepropertiespage.h:23
LanguageProperties::accept
virtual void accept()
Definition: languageproperties.cpp:75
LanguageProperties::LanguageProperties
LanguageProperties(KEduVocDocument *doc, QWidget *parent)
Definition: languageproperties.cpp:25
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