Disable rotation.
[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 }
16
17 void MainWindow::setupcodedUI()
18 {
19     cent = centralWidget();
20     //mlayout = qobject_cast<QVBoxLayout *>(cent->layout());
21     mlayout = new QVBoxLayout;
22     btlayout = new QHBoxLayout;
23
24     QScrollArea *scrollArea = new QScrollArea;
25     scrollArea->setBackgroundRole(QPalette::Dark);
26     mlayout->addWidget(scrollArea);
27
28     btnClear = new QPushButton;
29     btnClear->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_delete.png"));
30     wordinput = new QLineEdit;
31     labVerb = new QLabel();
32     labVerb->setMinimumWidth(250);
33     btlayout->addWidget(btnClear);
34     btlayout->addWidget(labVerb);
35     btlayout->addWidget(wordinput);
36     btnLookup = new QPushButton;  // Lookup button
37     btnLookup->setIcon(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_search.png"));
38     btlayout->addWidget(btnLookup);
39
40     mlayout->addLayout(btlayout);
41     cent->setLayout(mlayout);
42
43     // Clear the word input when Clear button is tapped
44     QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(clear()));
45     QObject::connect(btnClear, SIGNAL(clicked()), labVerb, SLOT(clear()));
46
47     QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup()));
48     QObject::connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup()));
49 }
50
51 MainWindow::~MainWindow()
52 {
53     delete ui;
54 }
55
56 void MainWindow::setOrientation(ScreenOrientation orientation)
57 {
58 #if defined(Q_OS_SYMBIAN)
59     // If the version of Qt on the device is < 4.7.2, that attribute won't work
60     if (orientation != ScreenOrientationAuto) {
61         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
62         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
63             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
64             return;
65         }
66     }
67 #endif // Q_OS_SYMBIAN
68
69     Qt::WidgetAttribute attribute;
70     switch (orientation) {
71 #if QT_VERSION < 0x040702
72     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
73     case ScreenOrientationLockPortrait:
74         attribute = static_cast<Qt::WidgetAttribute>(128);
75         break;
76     case ScreenOrientationLockLandscape:
77         attribute = static_cast<Qt::WidgetAttribute>(129);
78         break;
79     default:
80     case ScreenOrientationAuto:
81         attribute = static_cast<Qt::WidgetAttribute>(130);
82         break;
83 #else // QT_VERSION < 0x040702
84     case ScreenOrientationLockPortrait:
85         attribute = Qt::WA_LockPortraitOrientation;
86         break;
87     case ScreenOrientationLockLandscape:
88         attribute = Qt::WA_LockLandscapeOrientation;
89         break;
90     default:
91     case ScreenOrientationAuto:
92         attribute = Qt::WA_AutoOrientation;
93         break;
94 #endif // QT_VERSION < 0x040702
95     };
96     setAttribute(attribute, true);
97 }
98
99 void MainWindow::showExpanded()
100 {
101 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
102     showFullScreen();
103 #elif defined(Q_WS_MAEMO_5)
104     showMaximized();
105 #else
106     show();
107 #endif
108 }
109
110 void MainWindow::startLookup()
111 {
112     QString text = wordinput->text();
113     labVerb->setText(text);
114 }