1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
4 #include <QtCore/QCoreApplication>
6 MainWindow::MainWindow(QWidget *parent)
7 : QMainWindow(parent), ui(new Ui::MainWindow)
10 this->setAttribute(Qt::WA_Maemo5StackedWindow);
11 this->setWindowFlags(Qt::Window);
18 void MainWindow::setupcodedUI()
20 cent = centralWidget();
21 //mlayout = qobject_cast<QVBoxLayout *>(cent->layout());
22 mlayout = new QVBoxLayout;
23 btlayout = new QHBoxLayout;
25 QScrollArea *scrollArea = new QScrollArea;
26 scrollArea->setBackgroundRole(QPalette::Dark);
27 mlayout->addWidget(scrollArea);
29 btnClear = new QPushButton;
30 btnClear->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_delete.png"));
31 wordinput = new QLineEdit;
32 labVerb = new QLabel();
33 labVerb->setMinimumWidth(250);
34 btlayout->addWidget(btnClear);
35 btlayout->addWidget(labVerb);
36 btlayout->addWidget(wordinput);
37 btnLookup = new QPushButton; // Lookup button
38 btnLookup->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_search.png"));
39 btlayout->addWidget(btnLookup);
41 mlayout->addLayout(btlayout);
42 cent->setLayout(mlayout);
44 // Clear the word input when Clear button is tapped
45 QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(clear()));
46 QObject::connect(btnClear, SIGNAL(clicked()), labVerb, SLOT(clear()));
48 QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
49 QObject::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)
111 void MainWindow::startLookup()
113 const std::set<std::string> *templateSet = NULL;
114 QString input = wordinput->text();
115 labVerb->setText(input);
116 FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode);
117 if (lang != FrenchVerbDictionary::FRENCH)
119 //wordinput->setText(QString("Fr"));
122 std::string conjFileName, verbsFileName;
123 FrenchVerbDictionary::getXMLFilenames(conjFileName, verbsFileName, lang);
125 freVerbDic = new FrenchVerbDictionary(false);
126 const std::string word = input.toUtf8().constData();
127 templateSet = &freVerbDic->getVerbTemplateSet(word);
128 for (std::set<std::string>::const_iterator it = templateSet->begin();
129 it != templateSet->end(); ++it)
131 const std::string &tname = *it;
133 FrenchVerbDictionary::getRadical(word, tname);
137 void MainWindow::initverbiste()