#include "gui/conjugation.h"
#include <QtCore/QCoreApplication>
-#ifdef DEBUG
-#include <QDebug>
-#endif
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
#endif
ui->setupUi(this);
setupcodedUI();
- initverbiste();
}
void MainWindow::setupcodedUI()
btlayout = new QHBoxLayout;
resultPages = new QTabWidget;
- resultPages->setTabPosition(QTabWidget::West);
+ resultPages->setStyleSheet("QTabBar::tab { height: 50px }");
mlayout->addWidget(resultPages);
- btnClear = new QPushButton;
+ btnPron = new QCheckBox();
+ btnPron->setIcon(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_conference_avatar.png"));
+ btnClear = new QPushButton; /* Clearbutton */
btnClear->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_delete.png"));
- wordinput = new QLineEdit;
+ wordinput = new QLineEdit; /* Word input */
+ btlayout->addWidget(btnPron);
btlayout->addWidget(btnClear);
btlayout->addWidget(wordinput);
- btnLookup = new QPushButton; // Lookup button
+ btnLookup = new QPushButton; /* Lookup button */
btnLookup->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_search.png"));
btlayout->addWidget(btnLookup);
connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
+ connect(btnPron, SIGNAL(clicked()), this, SLOT(startLookup()));
+
+ /* Icon */
+ QIcon *icon = new QIcon();
+ icon->addFile(ICONFILE);
+ setWindowIcon(*icon);
+
+ /* About Dialog */
+ aboutDialog = new AboutDialog(ICONFILE, QString("MVerbiste v%1").arg(VERSTR));
+ aboutDialog->setIntro(trUtf8("A French conjugation utility for Maemo and MeeGo"));
+ aboutDialog->addAuthor(QString::fromUtf8("Nguyễn Hồng Quân <ng.hong.quan@gmail.com>\nPierre Sarrazin <sarrazip@sarrazip.com>"));
+
+ /* Menu */
+ QMenu *menu = ui->menuBar->addMenu(tr("Top menu"));
+ QAction *act_about = menu->addAction(tr("About"));
+ connect(act_about, SIGNAL(triggered()), aboutDialog, SLOT(show()));
+ /* Menu filters */
+ QActionGroup *filterGroup = new QActionGroup(this);
+ filterGroup->setExclusive(true);
+ filFrench = new QAction(tr("Search French"), filterGroup);
+ filFrench->setCheckable(true);
+ filFrench->setChecked(true);
+ filItalian = new QAction(tr("Search Italian"), filterGroup);
+ filItalian->setCheckable(true);
+ menu->addActions(filterGroup->actions());
+ connect(filItalian, SIGNAL(changed()), this, SLOT(switchLang()));
+ connect(filFrench, SIGNAL(changed()), this, SLOT(switchLang()));
}
MainWindow::~MainWindow()
{
delete ui;
delete freVerbDic;
+ delete aboutDialog;
}
void MainWindow::setOrientation(ScreenOrientation orientation)
#else
show();
#endif
+ initverbiste();
wordinput->setFocus();
}
void MainWindow::initverbiste()
{
langCode = "fr";
-}
-
-void MainWindow::startLookup()
-{
- btnLookup->setText(tr("Please wait..."));
- btnLookup->setEnabled(false);
- clearResults();
- /* Pending the lookup job to the next event loop (redraw the button right now) */
- QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
- QString input = wordinput->text();
FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
if (lang != FrenchVerbDictionary::FRENCH)
/* Create verb dictionary, accept non-accent input */
freVerbDic = new FrenchVerbDictionary(true);
+}
+
+void MainWindow::switchLang()
+{
+ FrenchVerbDictionary::Language curlang = freVerbDic->getLanguage();
+ FrenchVerbDictionary::Language targetlang = filItalian->isChecked() ? FrenchVerbDictionary::ITALIAN
+ : FrenchVerbDictionary::FRENCH;
+ if (curlang == targetlang) {
+ return;
+ }
+ /* If lang change */
+ std::string conjFN, verbsFN;
+ FrenchVerbDictionary::getXMLFilenames(conjFN, verbsFN, targetlang);
+ delete freVerbDic;
+ freVerbDic = new FrenchVerbDictionary(conjFN, verbsFN, true, targetlang);
+}
+
+void MainWindow::startLookup()
+{
+ QString input = wordinput->text().trimmed();
+ if (input.isEmpty()) {
+ return;
+ }
+
+ btnLookup->setText(tr("Please wait..."));
+ btnLookup->setEnabled(false);
+ clearResults();
+ /* Pending the lookup job to the next event loop (redraw the button right now) */
+ QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
/* Get input word to look up */
const std::string word = input.toLower().toUtf8().constData();
* obtain its complete conjugation.
*/
std::vector<InflectionDesc> infles;
- bool includePronouns = FALSE; // TODO: Will get this value from external
- bool isItalian = FALSE; // TODO: Will get this value from external
+ bool includePronouns = btnPron->isChecked();
+ bool isItalian = filItalian->isChecked(); // TODO: Will get this value from external
freVerbDic->deconjugate(word, infles);
resultPages->setUpdatesEnabled(false);
- std::string prevUTF8Infinitive, prevTemplateName;
+ std::string prevUTF8Infinitive, prevTemplateName; /* Remember found word
+ to avoid conjugating again */
+
for (std::vector<InflectionDesc>::const_iterator it = infles.begin();
it != infles.end(); it++)
{
const InflectionDesc &d = *it;
+
+ /* If this infinitive has been conjugated, we skip to the next infinitive */
+ if (d.infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName) {
+ continue;
+ }
+
VVVS conjug;
- getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
+ getConjugation(*freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
if (conjug.size() == 0 // if no tenses
|| conjug[0].size() == 0 // if no infinitive tense
}
std::string utf8Infinitive = conjug[0][0][0];
- if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName)
- // This result is duplicated
- continue;
- /* Show on GUI */
+ /* Add result to GUI (not show yet) */
ResultPage *rsp = addResultPage(utf8Infinitive);
/* Get modes and tenses of the verb */
QVBoxLayout *cell = makeResultCell(*t, utf8TenseName, word, freVerbDic);
rsp->grid->addLayout(cell, row, col);
}
+
+ /* Show the result on GUI */
rsp->packContent();
prevUTF8Infinitive = utf8Infinitive;
prevTemplateName = d.templateName;
}
+
/* Enable the button again */
btnLookup->setEnabled(true);
btnLookup->setText("");