1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include "gui/conjugation.h"
5 #include <QtCore/QCoreApplication>
8 MainWindow::MainWindow(QWidget *parent)
9 : QMainWindow(parent), ui(new Ui::MainWindow)
12 this->setAttribute(Qt::WA_Maemo5StackedWindow);
13 this->setWindowFlags(Qt::Window);
20 void MainWindow::setupcodedUI()
22 cent = centralWidget();
23 mlayout = new QVBoxLayout;
24 btlayout = new QHBoxLayout;
26 resultPages = new QTabWidget;
27 resultPages->setTabPosition(QTabWidget::West);
28 mlayout->addWidget(resultPages);
30 btnClear = new QPushButton;
31 btnClear->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_delete.png"));
32 wordinput = new QLineEdit;
33 labVerb = new QLabel();
34 labVerb->setMinimumWidth(250);
35 btlayout->addWidget(btnClear);
36 btlayout->addWidget(labVerb);
37 btlayout->addWidget(wordinput);
38 btnLookup = new QPushButton; // Lookup button
39 btnLookup->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_search.png"));
40 btlayout->addWidget(btnLookup);
42 mlayout->addLayout(btlayout);
43 cent->setLayout(mlayout);
45 // Clear the word input when Clear button is tapped
46 connect(btnClear, SIGNAL(clicked()), this, SLOT(clearResults()));
48 connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
49 connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
52 MainWindow::~MainWindow()
57 void MainWindow::setOrientation(ScreenOrientation orientation)
59 #if defined(Q_OS_SYMBIAN)
60 // If the version of Qt on the device is < 4.7.2, that attribute won't work
61 if (orientation != ScreenOrientationAuto) {
62 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
63 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
64 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
68 #endif // Q_OS_SYMBIAN
70 Qt::WidgetAttribute attribute;
71 switch (orientation) {
72 #if QT_VERSION < 0x040702
73 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
74 case ScreenOrientationLockPortrait:
75 attribute = static_cast<Qt::WidgetAttribute>(128);
77 case ScreenOrientationLockLandscape:
78 attribute = static_cast<Qt::WidgetAttribute>(129);
81 case ScreenOrientationAuto:
82 attribute = static_cast<Qt::WidgetAttribute>(130);
84 #else // QT_VERSION < 0x040702
85 case ScreenOrientationLockPortrait:
86 attribute = Qt::WA_LockPortraitOrientation;
88 case ScreenOrientationLockLandscape:
89 attribute = Qt::WA_LockLandscapeOrientation;
92 case ScreenOrientationAuto:
93 attribute = Qt::WA_AutoOrientation;
95 #endif // QT_VERSION < 0x040702
97 setAttribute(attribute, true);
100 void MainWindow::showExpanded()
102 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
104 #elif defined(Q_WS_MAEMO_5)
109 wordinput->setFocus();
112 void MainWindow::initverbiste()
117 void MainWindow::startLookup()
119 QString input = wordinput->text();
121 FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
122 if (lang != FrenchVerbDictionary::FRENCH)
124 // TODO: If lang code is not supported?
127 /* Create verb dictionary, accept non-accent input */
128 freVerbDic = new FrenchVerbDictionary(true);
130 /* Get input word to look up */
131 const std::string word = input.toLower().toUtf8().constData();
134 * For each possible deconjugation, take the infinitive form and
135 * obtain its complete conjugation.
137 std::vector<InflectionDesc> v;
138 bool includePronouns = FALSE; // TODO: Will get this value from external
139 bool isItalian = FALSE; // TODO: Will get this value from external
141 freVerbDic->deconjugate(word, v);
143 std::string prevUTF8Infinitive, prevTemplateName;
144 for (std::vector<InflectionDesc>::const_iterator it = v.begin();
147 const InflectionDesc &d = *it;
149 getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
151 if (conjug.size() == 0 // if no tenses
152 || conjug[0].size() == 0 // if no infinitive tense
153 || conjug[0][0].size() == 0 // if no person in inf. tense
154 || conjug[0][0][0].empty()) // if infinitive string empty
159 std::string utf8Infinitive = conjug[0][0][0];
160 if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName)
161 // This result is duplicated
165 ResultPage *rsp = addResultPage(utf8Infinitive);
166 //QString infVerb = QString::fromUtf8(utf8Infinitive.c_str());
167 //labVerb->setText(infVerb);
169 /* Get modes and tenses of the verb */
171 for (VVVS::const_iterator t = conjug.begin();
172 t != conjug.end(); t++, i++)
178 assert(i >= 0 && i < 16);
182 qDebug() << row << col;
184 std::string utf8TenseName = getTenseNameForTableCell(row, col, isItalian);
185 if (utf8TenseName.empty())
188 qDebug() << utf8TenseName.c_str();
191 prevUTF8Infinitive = utf8Infinitive;
192 prevTemplateName = d.templateName;
196 ResultPage* MainWindow::addResultPage(const std::string &labelText)
198 ResultPage *rp = new ResultPage();
199 QString label = QString::fromUtf8(labelText.c_str());
200 resultPages->addTab(rp->page, label);
204 void MainWindow::clearResults()
209 while (resultPages->count()) {
210 int lastIndex = resultPages->count() - 1;
211 resultPages->widget(lastIndex)->deleteLater();
212 resultPages->removeTab(lastIndex);
214 wordinput->setFocus();
217 /**** For ResultPage class ****/
218 ResultPage::ResultPage()
219 : page(new QScrollArea),
220 table(new QTableWidget)