Start to use lib verbiste.
[mverbiste] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3
4 #include <QtCore/QCoreApplication>
5
6 MainWindow::MainWindow(QWidget *parent)
7     : QMainWindow(parent), ui(new Ui::MainWindow)
8 {
9 #ifdef Q_WS_MAEMO_5
10     this->setAttribute(Qt::WA_Maemo5StackedWindow);
11     this->setWindowFlags(Qt::Window);
12 #endif
13     ui->setupUi(this);
14     setupcodedUI();
15     initverbiste();
16 }
17
18 void MainWindow::setupcodedUI()
19 {
20     cent = centralWidget();
21     //mlayout = qobject_cast<QVBoxLayout *>(cent->layout());
22     mlayout = new QVBoxLayout;
23     btlayout = new QHBoxLayout;
24
25     QScrollArea *scrollArea = new QScrollArea;
26     scrollArea->setBackgroundRole(QPalette::Dark);
27     mlayout->addWidget(scrollArea);
28
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);
40
41     mlayout->addLayout(btlayout);
42     cent->setLayout(mlayout);
43
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()));
47
48     QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
49     QObject::connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
50 }
51
52 MainWindow::~MainWindow()
53 {
54     delete ui;
55 }
56
57 void MainWindow::setOrientation(ScreenOrientation orientation)
58 {
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");
65             return;
66         }
67     }
68 #endif // Q_OS_SYMBIAN
69
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);
76         break;
77     case ScreenOrientationLockLandscape:
78         attribute = static_cast<Qt::WidgetAttribute>(129);
79         break;
80     default:
81     case ScreenOrientationAuto:
82         attribute = static_cast<Qt::WidgetAttribute>(130);
83         break;
84 #else // QT_VERSION < 0x040702
85     case ScreenOrientationLockPortrait:
86         attribute = Qt::WA_LockPortraitOrientation;
87         break;
88     case ScreenOrientationLockLandscape:
89         attribute = Qt::WA_LockLandscapeOrientation;
90         break;
91     default:
92     case ScreenOrientationAuto:
93         attribute = Qt::WA_AutoOrientation;
94         break;
95 #endif // QT_VERSION < 0x040702
96     };
97     setAttribute(attribute, true);
98 }
99
100 void MainWindow::showExpanded()
101 {
102 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
103     showFullScreen();
104 #elif defined(Q_WS_MAEMO_5)
105     showMaximized();
106 #else
107     show();
108 #endif
109 }
110
111 void MainWindow::startLookup()
112 {
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)
118     {
119         //wordinput->setText(QString("Fr"));
120     }
121     /*
122     std::string conjFileName, verbsFileName;
123     FrenchVerbDictionary::getXMLFilenames(conjFileName, verbsFileName, lang);
124     */
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)
130        {
131            const std::string &tname = *it;
132
133            FrenchVerbDictionary::getRadical(word, tname);
134        }
135 }
136
137 void  MainWindow::initverbiste()
138 {
139     langCode = "fr";
140 }