1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include "gui/conjugation.h"
5 #include <QtCore/QCoreApplication>
7 MainWindow::MainWindow(QWidget *parent)
8 : QMainWindow(parent), ui(new Ui::MainWindow)
11 this->setAttribute(Qt::WA_Maemo5StackedWindow);
12 this->setWindowFlags(Qt::Window);
19 void MainWindow::setupcodedUI()
21 cent = centralWidget();
22 //mlayout = qobject_cast<QVBoxLayout *>(cent->layout());
23 mlayout = new QVBoxLayout;
24 btlayout = new QHBoxLayout;
26 QScrollArea *scrollArea = new QScrollArea;
27 scrollArea->setBackgroundRole(QPalette::Dark);
28 mlayout->addWidget(scrollArea);
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 QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(clear()));
47 QObject::connect(btnClear, SIGNAL(clicked()), labVerb, SLOT(clear()));
48 QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(setFocus()));
50 QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
51 QObject::connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
54 MainWindow::~MainWindow()
59 void MainWindow::setOrientation(ScreenOrientation orientation)
61 #if defined(Q_OS_SYMBIAN)
62 // If the version of Qt on the device is < 4.7.2, that attribute won't work
63 if (orientation != ScreenOrientationAuto) {
64 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
65 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
66 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
70 #endif // Q_OS_SYMBIAN
72 Qt::WidgetAttribute attribute;
73 switch (orientation) {
74 #if QT_VERSION < 0x040702
75 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
76 case ScreenOrientationLockPortrait:
77 attribute = static_cast<Qt::WidgetAttribute>(128);
79 case ScreenOrientationLockLandscape:
80 attribute = static_cast<Qt::WidgetAttribute>(129);
83 case ScreenOrientationAuto:
84 attribute = static_cast<Qt::WidgetAttribute>(130);
86 #else // QT_VERSION < 0x040702
87 case ScreenOrientationLockPortrait:
88 attribute = Qt::WA_LockPortraitOrientation;
90 case ScreenOrientationLockLandscape:
91 attribute = Qt::WA_LockLandscapeOrientation;
94 case ScreenOrientationAuto:
95 attribute = Qt::WA_AutoOrientation;
97 #endif // QT_VERSION < 0x040702
99 setAttribute(attribute, true);
102 void MainWindow::showExpanded()
104 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
106 #elif defined(Q_WS_MAEMO_5)
111 wordinput->setFocus();
114 void MainWindow::startLookup()
116 QString input = wordinput->text();
118 FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
119 if (lang != FrenchVerbDictionary::FRENCH)
121 // TODO: If lang code is not supported?
124 /* Create verb dictionary, accept non-accent input */
125 freVerbDic = new FrenchVerbDictionary(true);
127 /* Get input word to look up */
128 const std::string word = input.toLower().toUtf8().constData();
131 * For each possible deconjugation, take the infinitive form and
132 * obtain its complete conjugation.
134 std::vector<InflectionDesc> v;
135 bool includePronouns = FALSE; // TODO: Will get this value from external
137 freVerbDic->deconjugate(word, v);
139 std::string prevUTF8Infinitive, prevTemplateName;
140 for (std::vector<InflectionDesc>::const_iterator it = v.begin();
143 const InflectionDesc &d = *it;
145 getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
147 if (conjug.size() == 0 // if no tenses
148 || conjug[0].size() == 0 // if no infinitive tense
149 || conjug[0][0].size() == 0 // if no person in inf. tense
150 || conjug[0][0][0].empty()) // if infinitive string empty
155 std::string utf8Infinitive = conjug[0][0][0];
156 if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName)
157 // This result is duplicated
161 labVerb->setText(QString::fromUtf8(utf8Infinitive.c_str()));
165 void MainWindow::initverbiste()