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()));
49 QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
50 QObject::connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
53 MainWindow::~MainWindow()
58 void MainWindow::setOrientation(ScreenOrientation orientation)
60 #if defined(Q_OS_SYMBIAN)
61 // If the version of Qt on the device is < 4.7.2, that attribute won't work
62 if (orientation != ScreenOrientationAuto) {
63 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
64 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
65 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
69 #endif // Q_OS_SYMBIAN
71 Qt::WidgetAttribute attribute;
72 switch (orientation) {
73 #if QT_VERSION < 0x040702
74 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
75 case ScreenOrientationLockPortrait:
76 attribute = static_cast<Qt::WidgetAttribute>(128);
78 case ScreenOrientationLockLandscape:
79 attribute = static_cast<Qt::WidgetAttribute>(129);
82 case ScreenOrientationAuto:
83 attribute = static_cast<Qt::WidgetAttribute>(130);
85 #else // QT_VERSION < 0x040702
86 case ScreenOrientationLockPortrait:
87 attribute = Qt::WA_LockPortraitOrientation;
89 case ScreenOrientationLockLandscape:
90 attribute = Qt::WA_LockLandscapeOrientation;
93 case ScreenOrientationAuto:
94 attribute = Qt::WA_AutoOrientation;
96 #endif // QT_VERSION < 0x040702
98 setAttribute(attribute, true);
101 void MainWindow::showExpanded()
103 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
105 #elif defined(Q_WS_MAEMO_5)
112 void MainWindow::startLookup()
114 QString input = wordinput->text();
116 FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
117 if (lang != FrenchVerbDictionary::FRENCH)
119 // TODO: If lang code is not supported?
122 /* Create verb dictionary, accept non-accent input */
123 freVerbDic = new FrenchVerbDictionary(true);
125 /* Get input word to look up */
126 const std::string word = input.toLower().toUtf8().constData();
129 * For each possible deconjugation, take the infinitive form and
130 * obtain its complete conjugation.
132 std::vector<InflectionDesc> v;
133 bool includePronouns = FALSE; // TODO: Will get this value from external
135 freVerbDic->deconjugate(word, v);
137 std::string prevUTF8Infinitive, prevTemplateName;
138 for (std::vector<InflectionDesc>::const_iterator it = v.begin();
141 const InflectionDesc &d = *it;
143 getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns);
145 if (conjug.size() == 0 // if no tenses
146 || conjug[0].size() == 0 // if no infinitive tense
147 || conjug[0][0].size() == 0 // if no person in inf. tense
148 || conjug[0][0][0].empty()) // if infinitive string empty
153 std::string utf8Infinitive = conjug[0][0][0];
154 if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName)
155 // This result is duplicated
159 labVerb->setText(QString::fromUtf8(utf8Infinitive.c_str()));
163 void MainWindow::initverbiste()