File indexing completed on 2024-09-01 03:41:56
0001 /* 0002 SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "comparisonwidget.h" 0007 0008 #include <KEduVocDocument> 0009 #include <KEduVocExpression> 0010 #include <KEduVocTranslation> 0011 #include <KEduVocWordtype> 0012 #include <KLocalizedString> 0013 #include <KMessageBox> 0014 0015 using namespace Editor; 0016 0017 ComparisonWidget::ComparisonWidget(QWidget *parent) 0018 : QWidget(parent) 0019 { 0020 setupUi(this); 0021 0022 connect(makeAdjectiveButton, &QPushButton::clicked, this, &ComparisonWidget::slotMakeAdjectiveButton); 0023 connect(makeAdverbButton, &QPushButton::clicked, this, &ComparisonWidget::slotMakeAdverbButton); 0024 0025 connect(comparativeLineEdit, &QLineEdit::editingFinished, this, &ComparisonWidget::slotComparativeChanged); 0026 connect(superlativeLineEdit, &QLineEdit::editingFinished, this, &ComparisonWidget::slotSuperlativeChanged); 0027 } 0028 0029 void ComparisonWidget::setTranslation(KEduVocExpression *entry, int translation) 0030 { 0031 comparativeLineEdit->setText(QString()); 0032 superlativeLineEdit->setText(QString()); 0033 comparativeLineEdit->setEnabled(false); 0034 superlativeLineEdit->setEnabled(false); 0035 0036 if (entry) { 0037 m_translation = entry->translation(translation); 0038 } else { 0039 m_translation = nullptr; 0040 } 0041 0042 if (m_translation) { 0043 absoluteEntryLabel->setText(m_translation->text()); 0044 setEnabled(true); 0045 0046 if (m_translation->wordType()) { 0047 if (m_translation->wordType()->wordType() & KEduVocWordFlag::Adjective || m_translation->wordType()->wordType() & KEduVocWordFlag::Adverb) { 0048 comparativeLineEdit->setEnabled(true); 0049 superlativeLineEdit->setEnabled(true); 0050 0051 comparativeLineEdit->setText(m_translation->comparativeForm().text()); 0052 superlativeLineEdit->setText(m_translation->superlativeForm().text()); 0053 } 0054 } 0055 } else { 0056 setEnabled(false); 0057 absoluteEntryLabel->setText(QString()); 0058 } 0059 } 0060 0061 void ComparisonWidget::slotMakeAdjectiveButton() 0062 { 0063 if (!m_doc) { 0064 return; 0065 } 0066 0067 // find an adjective container 0068 KEduVocWordType *container = m_doc->wordTypeContainer()->childOfType(KEduVocWordFlag::Adjective); 0069 if (container) { 0070 m_translation->setWordType(container); 0071 comparativeLineEdit->setEnabled(true); 0072 superlativeLineEdit->setEnabled(true); 0073 comparativeLineEdit->setFocus(); 0074 } else { 0075 ///@todo better message 0076 KMessageBox::information(this, i18n("Could not determine word type of adjectives")); 0077 } 0078 } 0079 0080 void ComparisonWidget::slotMakeAdverbButton() 0081 { 0082 if (!m_doc) { 0083 return; 0084 } 0085 0086 // find an adverb container 0087 KEduVocWordType *container = m_doc->wordTypeContainer()->childOfType(KEduVocWordFlag::Adverb); 0088 if (container) { 0089 m_translation->setWordType(container); 0090 comparativeLineEdit->setEnabled(true); 0091 superlativeLineEdit->setEnabled(true); 0092 comparativeLineEdit->setFocus(); 0093 } else { 0094 ///@todo better message 0095 KMessageBox::information(this, i18n("Could not determine word type of adverbs")); 0096 } 0097 } 0098 0099 void ComparisonWidget::setDocument(KEduVocDocument *doc) 0100 { 0101 m_doc = doc; 0102 } 0103 0104 void ComparisonWidget::slotComparativeChanged() 0105 { 0106 m_translation->setComparativeForm(comparativeLineEdit->text()); 0107 } 0108 0109 void ComparisonWidget::slotSuperlativeChanged() 0110 { 0111 m_translation->setSuperlativeForm(superlativeLineEdit->text()); 0112 } 0113 0114 #include "moc_comparisonwidget.cpp"