#include "mainwindow.h"
#include "ui_mainwindow.h"
+#include "gui/conjugation.h"
#include <QtCore/QCoreApplication>
#endif
ui->setupUi(this);
setupcodedUI();
+ initverbiste();
}
void MainWindow::setupcodedUI()
// Clear the word input when Clear button is tapped
QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(clear()));
QObject::connect(btnClear, SIGNAL(clicked()), labVerb, SLOT(clear()));
+ QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(setFocus()));
QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
QObject::connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
#else
show();
#endif
+ wordinput->setFocus();
}
void MainWindow::startLookup()
{
- QString text = wordinput->text();
- labVerb->setText(text);
+ QString input = wordinput->text();
+
+ FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
+ if (lang != FrenchVerbDictionary::FRENCH)
+ {
+ // TODO: If lang code is not supported?
+ }
+
+ /* Create verb dictionary, accept non-accent input */
+ freVerbDic = new FrenchVerbDictionary(true);
+
+ /* Get input word to look up */
+ const std::string word = input.toLower().toUtf8().constData();
+
+ /*
+ * For each possible deconjugation, take the infinitive form and
+ * obtain its complete conjugation.
+ */
+ std::vector<InflectionDesc> v;
+ bool includePronouns = FALSE; // TODO: Will get this value from external
+
+ freVerbDic->deconjugate(word, v);
+
+ std::string prevUTF8Infinitive, prevTemplateName;
+ for (std::vector<InflectionDesc>::const_iterator it = v.begin();
+ it != v.end(); it++)
+ {
+ const InflectionDesc &d = *it;
+ VVVS conjug;
+ getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
+
+ if (conjug.size() == 0 // if no tenses
+ || conjug[0].size() == 0 // if no infinitive tense
+ || conjug[0][0].size() == 0 // if no person in inf. tense
+ || conjug[0][0][0].empty()) // if infinitive string empty
+ {
+ continue;
+ }
+
+ std::string utf8Infinitive = conjug[0][0][0];
+ if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName)
+ // This result is duplicated
+ continue;
+
+ /* Show on GUI */
+ labVerb->setText(QString::fromUtf8(utf8Infinitive.c_str()));
+ }
+}
+
+void MainWindow::initverbiste()
+{
+ langCode = "fr";
}