• 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
  • 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  name = m_doc->identifier(i).name();
54  LanguageSettings currentSettings(m_doc->identifier(i).locale());
55  currentSettings.readConfig();
56  }
57 
58  KPageWidgetItem* editPage = new KPageWidgetItem(page, name);
59  editPage->setHeader( i18nc("Edit language properties", "Properties for %1", name) );
60 
61  m_pages.append(editPage);
62  addPage(editPage);
63 
64  editPage->setIcon( KIcon( "set-language" ) );
65 
66  connect(page->identifierNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(pageNameChanged(const QString&)));
67  connect(this, SIGNAL(accepted()), page, SLOT(accept()));
68 
69  return editPage;
70 }
71 
72 void LanguageProperties::accept()
73 {
74  KEduVocDocument *doc = m_doc;
75  int deleted = 0;
76 
77  for (int index = 0; index < m_pages.count(); index++) {
78  if (m_pages.value(index)->isEnabled()) {
79  if (index - deleted >= doc->identifierCount()) {
80  // add a language
81  doc->appendIdentifier();
82  }
83  LanguagePropertiesPage * page = static_cast<LanguagePropertiesPage *>(m_pages.value(index)->widget());
84  page->setLanguageIdentifierIndex(index-deleted);
85  } else {
86  // page is disabled, delete the language
87  if (index < doc->identifierCount()) {
88  if ( KMessageBox::warningYesNo(this, i18n("Really delete language: %1?", doc->identifier(index-deleted).name()), i18n("Remove Language")) == KMessageBox::Yes ) {
89  doc->removeIdentifier(index-deleted);
90  doc->setModified();
91  deleted++;
92  }
93  }
94  }
95  }
96 
97  KDialog::accept();
98 }
99 
100 
101 void LanguageProperties::slotAppendIdentifier()
102 {
103  // if a page that was "removed" is selected, simply enable it again to not delete it.
104  if (currentPage() && !currentPage()->isEnabled()) {
105  currentPage()->setEnabled(true);
106  return;
107  }
108 
109  int i = m_pages.count();
110  KPageWidgetItem* newPage = createPage( i );
111  setCurrentPage( newPage );
112 }
113 
114 void LanguageProperties::slotDeleteIdentifier()
115 {
116  currentPage()->setEnabled(false);
117 }
118 
119 void LanguageProperties::pageNameChanged(const QString & newName)
120 {
121  currentPage()->setName( newName );
122 }
123 
124 #include "languageproperties.moc"
KPageDialog
languagesettings.h
languagepropertiespage.h
LanguagePropertiesPage::setLanguageIdentifierIndex
void setLanguageIdentifierIndex(int newIndex)
Definition: languagepropertiespage.cpp:109
QWidget
languageproperties.h
LanguageSettings
Definition: languagesettings.h:10
LanguagePropertiesPage
Definition: languagepropertiespage.h:23
LanguageProperties::accept
virtual void accept()
Definition: languageproperties.cpp:72
LanguageProperties::LanguageProperties
LanguageProperties(KEduVocDocument *doc, QWidget *parent)
Definition: languageproperties.cpp:25
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