1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include "gui/conjugation.h"
5 #include <QtCore/QCoreApplication>
10 MainWindow::MainWindow(QWidget *parent)
11 : QMainWindow(parent), ui(new Ui::MainWindow)
14 this->setAttribute(Qt::WA_Maemo5StackedWindow);
15 this->setWindowFlags(Qt::Window);
22 void MainWindow::setupcodedUI()
24 cent = centralWidget();
25 mlayout = new QVBoxLayout;
26 btlayout = new QHBoxLayout;
28 resultPages = new QTabWidget;
29 resultPages->setTabPosition(QTabWidget::West);
30 mlayout->addWidget(resultPages);
32 btnClear = new QPushButton;
33 btnClear->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_delete.png"));
34 wordinput = new QLineEdit;
35 labVerb = new QLabel();
36 labVerb->setMinimumWidth(250);
37 btlayout->addWidget(btnClear);
38 btlayout->addWidget(labVerb);
39 btlayout->addWidget(wordinput);
40 btnLookup = new QPushButton; // Lookup button
41 btnLookup->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_search.png"));
42 btlayout->addWidget(btnLookup);
44 mlayout->addLayout(btlayout);
45 cent->setLayout(mlayout);
47 // Clear the word input when Clear button is tapped
48 connect(btnClear, SIGNAL(clicked()), this, SLOT(clearResults()));
50 connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
51 connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
54 MainWindow::~MainWindow()
60 void MainWindow::setOrientation(ScreenOrientation orientation)
62 #if defined(Q_OS_SYMBIAN)
63 // If the version of Qt on the device is < 4.7.2, that attribute won't work
64 if (orientation != ScreenOrientationAuto) {
65 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
66 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
67 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
71 #endif // Q_OS_SYMBIAN
73 Qt::WidgetAttribute attribute;
74 switch (orientation) {
75 #if QT_VERSION < 0x040702
76 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
77 case ScreenOrientationLockPortrait:
78 attribute = static_cast<Qt::WidgetAttribute>(128);
80 case ScreenOrientationLockLandscape:
81 attribute = static_cast<Qt::WidgetAttribute>(129);
84 case ScreenOrientationAuto:
85 attribute = static_cast<Qt::WidgetAttribute>(130);
87 #else // QT_VERSION < 0x040702
88 case ScreenOrientationLockPortrait:
89 attribute = Qt::WA_LockPortraitOrientation;
91 case ScreenOrientationLockLandscape:
92 attribute = Qt::WA_LockLandscapeOrientation;
95 case ScreenOrientationAuto:
96 attribute = Qt::WA_AutoOrientation;
98 #endif // QT_VERSION < 0x040702
100 setAttribute(attribute, true);
103 void MainWindow::showExpanded()
105 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
107 #elif defined(Q_WS_MAEMO_5)
112 wordinput->setFocus();
115 void MainWindow::initverbiste()
120 void MainWindow::startLookup()
122 QString input = wordinput->text();
124 FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
125 if (lang != FrenchVerbDictionary::FRENCH)
127 // TODO: If lang code is not supported?
130 /* Create verb dictionary, accept non-accent input */
131 freVerbDic = new FrenchVerbDictionary(true);
133 /* Get input word to look up */
134 const std::string word = input.toLower().toUtf8().constData();
137 * For each possible deconjugation, take the infinitive form and
138 * obtain its complete conjugation.
140 std::vector<InflectionDesc> v;
141 bool includePronouns = FALSE; // TODO: Will get this value from external
142 bool isItalian = FALSE; // TODO: Will get this value from external
144 freVerbDic->deconjugate(word, v);
146 std::string prevUTF8Infinitive, prevTemplateName;
147 for (std::vector<InflectionDesc>::const_iterator it = v.begin();
150 const InflectionDesc &d = *it;
152 getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
154 if (conjug.size() == 0 // if no tenses
155 || conjug[0].size() == 0 // if no infinitive tense
156 || conjug[0][0].size() == 0 // if no person in inf. tense
157 || conjug[0][0][0].empty()) // if infinitive string empty
162 std::string utf8Infinitive = conjug[0][0][0];
163 if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName)
164 // This result is duplicated
168 ResultPage *rsp = addResultPage(utf8Infinitive);
169 //QString infVerb = QString::fromUtf8(utf8Infinitive.c_str());
170 //labVerb->setText(infVerb);
172 /* Get modes and tenses of the verb */
174 for (VVVS::const_iterator t = conjug.begin();
175 t != conjug.end(); t++, i++)
181 assert(i >= 0 && i < 16);
186 std::string utf8TenseName = getTenseNameForTableCell(row, col, isItalian);
187 if (utf8TenseName.empty())
191 qDebug() << utf8TenseName.c_str();
193 QVBoxLayout *cell = makeResultCell(*t, utf8TenseName, word, freVerbDic);
194 rsp->grid->addLayout(cell, row, col);
196 qDebug() << "Add cell to " << row << col;
200 prevUTF8Infinitive = utf8Infinitive;
201 prevTemplateName = d.templateName;
205 ResultPage* MainWindow::addResultPage(const std::string &labelText)
207 ResultPage *rp = new ResultPage();
208 QString label = QString::fromUtf8(labelText.c_str());
209 resultPages->addTab(rp->page, label);
213 void MainWindow::clearResults()
218 while (resultPages->count()) {
219 int lastIndex = resultPages->count() - 1;
220 resultPages->widget(lastIndex)->deleteLater();
221 resultPages->removeTab(lastIndex);
223 wordinput->setFocus();
226 QVBoxLayout* MainWindow::makeResultCell(const VVS &tenseIterator,
227 const std::string &tenseName,
228 const std::string &inputWord,
229 FrenchVerbDictionary *verbDict)
231 QLabel *tenseLabel = new QLabel();
232 tenseLabel->setText(QString::fromUtf8(tenseName.c_str()));
233 QVBoxLayout *vbox = new QVBoxLayout();
234 vbox->addWidget(tenseLabel);
235 std::string conjugated = createTableCellText(
241 QLabel *conjResult = new QLabel();
242 conjResult->setText(QString::fromUtf8(conjugated.c_str()));
243 vbox->addWidget(conjResult);
247 /**** For ResultPage class ****/
248 ResultPage::ResultPage()
249 : page(new QScrollArea),
250 grid(new QGridLayout)
254 void ResultPage::packContent()
256 QWidget *immediate = new QWidget();
257 immediate->setLayout(grid);
258 page->setWidget(immediate);