mainwindow.cpp 1.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtCore/QCoreApplication>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

17
void MainWindow::setOrientation(ScreenOrientation orientation)
18
{
19
20
#if defined(Q_OS_SYMBIAN)
    // If the version of Qt on the device is < 4.7.2, that attribute won't work
21
    if (orientation != ScreenOrientationAuto) {
22
23
24
25
26
        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
            return;
        }
27
    }
28
29
#endif // Q_OS_SYMBIAN

30
31
    Qt::WidgetAttribute attribute;
    switch (orientation) {
32
33
#if QT_VERSION < 0x040702
    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
34
    case ScreenOrientationLockPortrait:
35
        attribute = static_cast<Qt::WidgetAttribute>(128);
36
        break;
37
    case ScreenOrientationLockLandscape:
38
        attribute = static_cast<Qt::WidgetAttribute>(129);
39
        break;
40
    default:
41
    case ScreenOrientationAuto:
42
43
44
45
46
47
48
49
50
        attribute = static_cast<Qt::WidgetAttribute>(130);
        break;
#else // QT_VERSION < 0x040702
    case ScreenOrientationLockPortrait:
        attribute = Qt::WA_LockPortraitOrientation;
        break;
    case ScreenOrientationLockLandscape:
        attribute = Qt::WA_LockLandscapeOrientation;
        break;
51
    default:
52
53
    case ScreenOrientationAuto:
        attribute = Qt::WA_AutoOrientation;
54
        break;
55
56
#endif // QT_VERSION < 0x040702
    };
57
58
    setAttribute(attribute, true);
}
59
60
61
62
63

void MainWindow::showExpanded()
{
#ifdef Q_OS_SYMBIAN
    showFullScreen();
64
#elif defined(Q_WS_MAEMO_5)
65
66
67
68
69
    showMaximized();
#else
    show();
#endif
}