• 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
  • editor
synonymwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
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 "synonymwidget.h"
15 
16 #include <keduvoctranslation.h>
17 #include <keduvocexpression.h>
18 
19 #include <QStringListModel>
20 #include <QDragEnterEvent>
21 
22 using namespace Editor;
23 
24 SynonymWidget::SynonymWidget(SynonymWidgetType type, QWidget *parent) : QWidget(parent)
25 {
26  m_type = type;
27  m_currentTranslation = 0;
28  m_lastTranslation = 0;
29  setupUi(this);
30 
31  connect(synonymButton, SIGNAL(clicked()), SLOT(togglePair()));
32  m_listModel = new QStringListModel(this); listView->setModel(m_listModel);
33 
34  updateList();
35 }
36 
37 void SynonymWidget::setTranslation(KEduVocExpression * entry, int translation)
38 {
39  // ignore zeros
40  if (entry) {
41  m_lastTranslation = m_currentTranslation;
42  m_currentTranslation = entry->translation(translation);
43  updateList();
44  } else {
45  // better play save, the entry most likely has been deleted.
46  m_lastTranslation = 0;
47  m_currentTranslation = 0;
48  updateList();
49  }
50 }
51 
52 void SynonymWidget::updateList()
53 {
54  // clear the list
55  m_listModel->removeRows(0, m_listModel->rowCount());
56 
57  // set the button text
58  if (!(m_lastTranslation && m_currentTranslation)) {
59  synonymButton->setEnabled(false);
60  synonymButton->setText(i18n("Select Synonyms"));
61  } else {
62  synonymButton->setEnabled(true);
63  switch(m_type) {
64  case Synonym:
65  if (m_currentTranslation->synonyms().contains(m_lastTranslation)) {
66  synonymButton->setText(i18n("%1 and %2 are not Synonyms", m_currentTranslation->text(), m_lastTranslation->text()));
67  } else {
68  synonymButton->setText(i18n("%1 and %2 are Synonyms", m_currentTranslation->text(), m_lastTranslation->text()));
69  }
70  break;
71  case Antonym:
72  if (m_currentTranslation->antonyms().contains(m_lastTranslation)) {
73  synonymButton->setText(i18n("%1 and %2 are not Antonyms", m_currentTranslation->text(), m_lastTranslation->text()));
74  } else {
75  synonymButton->setText(i18n("%1 and %2 are Antonyms", m_currentTranslation->text(), m_lastTranslation->text()));
76  }
77  break;
78  case FalseFriend:
79  if (m_currentTranslation->falseFriends().contains(m_lastTranslation)) {
80  synonymButton->setText(i18n("%1 and %2 are not False Friends", m_currentTranslation->text(), m_lastTranslation->text()));
81  } else {
82  synonymButton->setText(i18n("%1 and %2 are False Friends", m_currentTranslation->text(), m_lastTranslation->text()));
83  }
84  break;
85  }
86  }
87 
88  if (m_currentTranslation) {
89  switch(m_type) {
90  case Synonym:
91  synonymLabel->setText(i18nc("Title for a list of synonyms for a word", "Synonyms of %1:", m_currentTranslation->text()));
92  break;
93  case Antonym:
94  synonymLabel->setText(i18nc("Title for a list of antonyms (opposites) for a word", "Antonyms of %1:", m_currentTranslation->text()));
95  break;
96  case FalseFriend:
97  synonymLabel->setText(i18nc("Title for a list of false friend (things that sound similar but have different meanings) for a word", "False Friends of %1:", m_currentTranslation->text()));
98  break;
99  }
100 
101  // load list of synonyms/antonyms/ffs
102  QList< KEduVocTranslation* > list;
103  switch(m_type) {
104  case Synonym:
105  list = m_currentTranslation->synonyms();
106  break;
107  case Antonym:
108  list = m_currentTranslation->antonyms();
109  break;
110  case FalseFriend:
111  list = m_currentTranslation->falseFriends();
112  break;
113  }
114  foreach (KEduVocTranslation* translation, list) {
115  int row = m_listModel->rowCount();
116  m_listModel->insertRow(row);
117  m_listModel->setData(m_listModel->index(row), translation->text());
118  }
119  } else {
120  synonymLabel->clear();
121  }
122 }
123 
124 void SynonymWidget::togglePair()
125 {
126  // pair them up
127  switch(m_type) {
128  case Synonym:
129  if (m_currentTranslation->synonyms().contains(m_lastTranslation)) {
130  m_currentTranslation->removeSynonym(m_lastTranslation);
131  m_lastTranslation->removeSynonym(m_currentTranslation);
132  } else {
133  m_currentTranslation->addSynonym(m_lastTranslation);
134  m_lastTranslation->addSynonym(m_currentTranslation);
135  }
136  break;
137  case Antonym:
138  if (m_currentTranslation->antonyms().contains(m_lastTranslation)) {
139  m_currentTranslation->removeAntonym(m_lastTranslation);
140  m_lastTranslation->removeAntonym(m_currentTranslation);
141  } else {
142  m_currentTranslation->addAntonym(m_lastTranslation);
143  m_lastTranslation->addAntonym(m_currentTranslation);
144  }
145  break;
146  case FalseFriend:
147  if (m_currentTranslation->falseFriends().contains(m_lastTranslation)) {
148  m_currentTranslation->removeFalseFriend(m_lastTranslation);
149  m_lastTranslation->removeFalseFriend(m_currentTranslation);
150  } else {
151  m_currentTranslation->addFalseFriend(m_lastTranslation);
152  m_lastTranslation->addFalseFriend(m_currentTranslation);
153  }
154  break;
155  }
156  updateList();
157 }
158 
159 
160 #include "synonymwidget.moc"
161 
Editor::SynonymWidget::FalseFriend
Definition: synonymwidget.h:34
Editor::SynonymWidget::SynonymWidgetType
SynonymWidgetType
Definition: synonymwidget.h:31
Editor::SynonymWidget::SynonymWidget
SynonymWidget(SynonymWidgetType type, QWidget *parent=0)
Definition: synonymwidget.cpp:24
QWidget
synonymwidget.h
Editor::SynonymWidget::setTranslation
void setTranslation(KEduVocExpression *entry, int translation)
Definition: synonymwidget.cpp:37
Editor::SynonymWidget::Antonym
Definition: synonymwidget.h:33
Editor::SynonymWidget::Synonym
Definition: synonymwidget.h:32
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