• 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
  • scripts
  • scripting
parley.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2008 Avgoustinos Kadis <avgoustinos.kadis@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "parley.h"
17 
18 #include "editor/editor.h"
19 #include "../../vocabulary/vocabularymodel.h"
20 #include "../../vocabulary/vocabularyview.h"
21 
22 #include "../scriptmanager.h"
23 #include "../translator.h"
24 
25 #include "document.h"
26 #include "lesson.h"
27 #include "expression.h"
28 #include "translation.h"
29 
30 #include <KLocale>
31 #include <KGlobal>
32 #include <KDebug>
33 #include <KActionCollection>
34 #include <KMenuBar>
35 
36 
37 using namespace Editor;
38 
39 namespace Scripting
40 {
41 
42  Parley::Parley ( EditorWindow * editor ) : QObject(), m_editor ( editor )
43  {
44  m_translator = new Translator(this); //parameter has to be <this> cause it's used by Translator to access callTranslateWord
45  m_doc = new Document ( m_editor->m_mainWindow->parleyDocument()->document() );
46  }
47 
48  Parley::~Parley()
49  {
50  delete m_translator;
51  delete m_doc;
52  }
53 
54  void Parley::callTranslateWord ( const QString & word,const QString& fromLanguage,const QString& toLanguage )
55  {
56  emit translationStarted ( word, fromLanguage, toLanguage );
57  emit translateWord ( word, fromLanguage, toLanguage );
58  emit translationFinished ( word, fromLanguage, toLanguage );
59  }
60 
61  void Parley::addTranslation ( QString word,QString fromLanguage,QString toLanguage, QString translation )
62  {
63  if ( m_translator )
64  m_translator->addTranslation ( word,fromLanguage,toLanguage,translation );
65  }
66 
67  QStringList Parley::locales()
68  {
70  return KGlobal::locale()->allLanguagesList();
71  }
72 
73  QString Parley::localeName ( QString locale )
74  {
75  return KGlobal::locale()->languageCodeToName ( locale );
76  }
77 
78  void Parley::open( QString filename )
79  {
80  KUrl url(filename);
81  kDebug() << url;
82  m_editor->m_mainWindow->parleyDocument()->open( url );
83  }
84 
85  QObject* Parley::activeLesson()
86  {
87  return new Lesson ( m_editor->m_vocabularyModel->lesson() );
88  }
89 
90  QVariantList Parley::selectedEntries()
91  {
92  QVariantList entries;
93 
94  //get selected indexes and active lesson
95  QModelIndexList indexes = m_editor->m_vocabularyView->getSelectedIndexes();
96 
97  //get the unique selected entries
98  QSet<KEduVocExpression*> kentries;
99  foreach ( const QModelIndex &index, indexes )
100  {
101 // kDebug() << index.row() << index.data(Qt::DisplayRole);
102  KEduVocExpression * expr = qvariant_cast<KEduVocExpression*> ( index.data(VocabularyModel::EntryRole) );
103  kentries << expr;
104  }
105 
106  //convert them to Expression objects and add them to the QVariantList
107  foreach (KEduVocExpression * expr, kentries) {
108 // Expression entry(expr);
109 // kDebug() << entry.translationTexts();
110  QObject * obj = new Expression(expr);
111  entries << qVariantFromValue ( obj );
112  }
113 
114  return entries;
115  }
116 
117  QVariantList Parley::selectedTranslations() {
118  QVariantList translations;
119 
120  //get selected indexes and active lesson
121  QModelIndexList indexes = m_editor->m_vocabularyView->getSelectedIndexes();
122 
123  //get the unique selected entries
124  QSet<KEduVocTranslation*> ktranslations;
125 // const QModelIndex &index;
126  foreach ( const QModelIndex &index, indexes )
127  {
128  if (VocabularyModel::columnType( index.column() ) == VocabularyModel::Translation) {
129  KEduVocExpression * expr = qvariant_cast<KEduVocExpression*> ( index.data(VocabularyModel::EntryRole) );
130  ktranslations << expr->translation(VocabularyModel::translation(index.column()));
131  }
132 // kDebug() << index.row() << index.data(Qt::DisplayRole);
133  }
134 
135  //convert them to Expression objects and add them to the QVariantList
136  foreach (KEduVocTranslation * tr, ktranslations) {
137 // Translation transltion(tr);
138 // kDebug() << entry.translationTexts();
139  QObject * obj = new Translation(tr);
140  translations << qVariantFromValue ( obj );
141  }
142 
143  return translations;
144  }
145 
146  QObject * Scripting::Parley::newAction ( const QString & name, const QString& text )
147  {
148  //create new action
149  KAction* action = new KAction ( text, m_editor );
150  m_editor->m_scriptManager->addScriptAction ( name,action );
151  return action;
152 
153  }
154 
155 }
156 
157 
158 
159 
Scripting::Parley::newAction
QObject * newAction(const QString &name, const QString &text=QString())
Creates and adds to the Scripts menu a new KAction (see KAction documentation)
Definition: parley.cpp:146
Scripting::Parley::addTranslation
void addTranslation(QString word, QString fromLanguage, QString toLanguage, QString translation)
Adds the found translation of the word from language fromLanguage to language toLanguage to Parley tr...
Definition: parley.cpp:61
Scripting::Parley::selectedEntries
QVariantList selectedEntries()
Returns a list of Expression objects (the selected entries of the active lesson)
Definition: parley.cpp:90
Editor::VocabularyView::getSelectedIndexes
QModelIndexList getSelectedIndexes() const
Definition: vocabularyview.cpp:445
Scripting::Parley::callTranslateWord
void callTranslateWord(const QString &word, const QString &fromLanguage, const QString &toLanguage)
Definition: parley.cpp:54
Scripting::Parley::translationStarted
void translationStarted(const QString &word, const QString &fromLanguage, const QString &toLanguage)
Scripting::Lesson
KEduVocLesson wrapping class for Kross scripts.
Definition: lesson.h:47
ParleyDocument::document
KEduVocDocument * document()
Definition: parleydocument.cpp:93
Scripting::Parley::translateWord
void translateWord(const QString &word, const QString &fromLanguage, const QString &toLanguage)
Slots (script functions) connected to this signal are called when a translation of word is requested...
Scripting::Translation
KEduVocTranslation wrapper class for scripting with Kross.
Definition: translation.h:36
QObject
parley.h
editor.h
Scripting::Parley::open
void open(QString filename)
Definition: parley.cpp:78
Scripting::Document
KEduVocDocument wrapping class for Kross scripts.
Definition: document.h:66
Translator::addTranslation
void addTranslation(QString word, QString fromLanguage, QString toLanguage, QString translation)
Stores the translation of word from language fromLanguage, to language toLanguage.
Definition: translator.cpp:33
expression.h
document.h
Scripting::Parley::locales
QStringList locales()
Returns a list of all available locales (to be used by the scripts)
Definition: parley.cpp:67
translation.h
Scripting::Parley::activeLesson
QObject * activeLesson()
Translator
Keeps the translated words.
Definition: translator.h:74
Scripting::Parley::selectedTranslations
QVariantList selectedTranslations()
Returns a list of Translation objects (the selected translations of the active lesson) ...
Definition: parley.cpp:117
lesson.h
Scripting::Parley::translationFinished
void translationFinished(const QString &word, const QString &fromLanguage, const QString &toLanguage)
Editor::VocabularyModel::lesson
KEduVocLesson * lesson()
Definition: vocabularymodel.cpp:91
Editor::EditorWindow
Definition: editor.h:46
Scripting::Parley::localeName
QString localeName(QString locale)
Gives the language name of the given locale.
Definition: parley.cpp:73
Scripting::Expression
This class represents.
Definition: expression.h:35
ParleyDocument::open
bool open(const KUrl &)
Opens the given url, displays an error message and returns false on failure.
Definition: parleydocument.cpp:182
ParleyMainWindow::parleyDocument
ParleyDocument * parleyDocument()
Return the ParleyDocument member object.
Definition: parleymainwindow.cpp:412
Scripting::Parley::~Parley
~Parley()
Definition: parley.cpp:48
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