• 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
  • 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 "vocabularymodel.h"
20 #include "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 // kDebug() << index.row() << index.data(Qt::DisplayRole);
101  KEduVocExpression * expr = qvariant_cast<KEduVocExpression*> (index.data(VocabularyModel::EntryRole));
102  kentries << expr;
103  }
104 
105  //convert them to Expression objects and add them to the QVariantList
106  foreach(KEduVocExpression * expr, kentries) {
107 // Expression entry(expr);
108 // kDebug() << entry.translationTexts();
109  QObject * obj = new Expression(expr);
110  entries << qVariantFromValue(obj);
111  }
112 
113  return entries;
114 }
115 
116 QVariantList Parley::selectedTranslations()
117 {
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  if (VocabularyModel::columnType(index.column()) == VocabularyModel::Translation) {
128  KEduVocExpression * expr = qvariant_cast<KEduVocExpression*> (index.data(VocabularyModel::EntryRole));
129  ktranslations << expr->translation(VocabularyModel::translation(index.column()));
130  }
131 // kDebug() << index.row() << index.data(Qt::DisplayRole);
132  }
133 
134  //convert them to Expression objects and add them to the QVariantList
135  foreach(KEduVocTranslation * tr, ktranslations) {
136 // Translation transltion(tr);
137 // kDebug() << entry.translationTexts();
138  QObject * obj = new Translation(tr);
139  translations << qVariantFromValue(obj);
140  }
141 
142  return translations;
143 }
144 
145 QObject * Scripting::Parley::newAction(const QString & name, const QString& text)
146 {
147  //create new action
148  KAction* action = new KAction(text, m_editor);
149  m_editor->m_scriptManager->addScriptAction(name, action);
150  return action;
151 
152 }
153 
154 }
155 
156 
157 
158 
QModelIndex
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:145
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:446
Scripting::Parley::callTranslateWord
void callTranslateWord(const QString &word, const QString &fromLanguage, const QString &toLanguage)
Definition: parley.cpp:54
VocabularyModel::Translation
Definition: vocabularymodel.h:34
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:97
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::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
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
VocabularyModel::columnType
static int columnType(int column)
Returns the type of the column specified.
Definition: vocabularymodel.cpp:315
QObject
expression.h
document.h
QSet< KEduVocExpression * >
VocabularyModel::EntryRole
Definition: vocabularymodel.h:50
Scripting::Parley::locales
QStringList locales()
Returns a list of all available locales (to be used by the scripts)
Definition: parley.cpp:67
QString
translation.h
QStringList
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:116
lesson.h
Scripting::Parley::translationFinished
void translationFinished(const QString &word, const QString &fromLanguage, const QString &toLanguage)
QModelIndex::data
QVariant data(int role) const
VocabularyModel::translation
static int translation(int column)
Returns which translation this column matches.
Definition: vocabularymodel.cpp:310
Editor::EditorWindow
Definition: editor.h:50
QModelIndex::column
int column() const
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:191
ParleyMainWindow::parleyDocument
ParleyDocument * parleyDocument()
Return the ParleyDocument member object.
Definition: parleymainwindow.cpp:413
VocabularyModel::lesson
KEduVocLesson * lesson()
Definition: vocabularymodel.cpp:90
Scripting::Parley::~Parley
~Parley()
Definition: parley.cpp:48
vocabularymodel.h
vocabularyview.h
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