X-Git-Url: http://git.maemo.org/git/?p=mverbiste;a=blobdiff_plain;f=mainwindow.cpp;h=21d7de8cc716d7de2e95ce8682ff3c86a7def484;hp=2ae5a601b09f2ae39971cd5ab90bb00bc4cd9871;hb=00d4490c79412f355b2dd2ff54bb59637d0487d5;hpb=e2b4937b435d4973f9151b07503ef1fb869b43a4 diff --git a/mainwindow.cpp b/mainwindow.cpp index 2ae5a60..21d7de8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,15 +22,18 @@ 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); @@ -42,6 +45,7 @@ void MainWindow::setupcodedUI() 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(); @@ -49,7 +53,7 @@ void MainWindow::setupcodedUI() setWindowIcon(*icon); /* About Dialog */ - aboutDialog = new AboutDialog(ICONFILE, "MVerbiste"); + 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 \nPierre Sarrazin ")); @@ -57,6 +61,17 @@ void MainWindow::setupcodedUI() 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() @@ -136,6 +151,21 @@ void MainWindow::initverbiste() 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(); @@ -157,13 +187,9 @@ void MainWindow::startLookup() * obtain its complete conjugation. */ std::vector 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 -#ifndef QT_NO_DEBUG - timer.start(); - qDebug() << "Start " << timer.elapsed(); -#endif freVerbDic->deconjugate(word, infles); resultPages->setUpdatesEnabled(false); @@ -175,34 +201,13 @@ void MainWindow::startLookup() { const InflectionDesc &d = *it; -#ifndef QT_NO_DEBUG - qDebug() << ">> Infinitive " << d.infinitive.c_str(); - qDebug() << " Template " << d.templateName.c_str(); -#endif /* If this infinitive has been conjugated, we skip to the next infinitive */ if (d.infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName) { continue; } - /* FIXME: - * In original source (Verbiste), this checking is done later, - * after getConjugation(). I place it here to avoid calling again - * multitimes getConjugation(), which is very slow. - * We need to test more to see which place is more correct. - */ VVVS conjug; -#ifndef QT_NO_DEBUG - qDebug() << " START getConjugation " << timer.elapsed(); -#endif - getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, - #ifndef QT_NO_DEBUG - timer, - #endif - includePronouns); - -#ifndef QT_NO_DEBUG - qDebug() << " getConjugation() returns: " << timer.elapsed(); -#endif + getConjugation(*freVerbDic, d.infinitive, d.templateName, conjug, includePronouns); if (conjug.size() == 0 // if no tenses || conjug[0].size() == 0 // if no infinitive tense @@ -213,10 +218,6 @@ void MainWindow::startLookup() } std::string utf8Infinitive = conjug[0][0][0]; -#ifndef QT_NO_DEBUG - qDebug() << " Infinitive " << utf8Infinitive.c_str(); - qDebug() << " Template " << d.templateName.c_str(); -#endif /* Add result to GUI (not show yet) */ ResultPage *rsp = addResultPage(utf8Infinitive); @@ -287,7 +288,9 @@ QVBoxLayout* MainWindow::makeResultCell(const VVS &tenseIterator, /* Mode & Tense name */ QLabel *tenseLabel = new QLabel(); tenseLabel->setText(QString::fromUtf8(tenseName.c_str())); - tenseLabel->setStyleSheet("QLabel {background-color: #44A51C; " + tenseLabel->setStyleSheet("QLabel {background-color: #44A51C;" + "border-top-left-radius: 4px;" + "border-top-right-radius: 4px;" "padding-left: 10px; padding-right: 10px}"); /* Conjugaison */