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