2010-11-01 17:03:46 +01:00
|
|
|
/*
|
|
|
|
|
This file was generated by the Mobile Qt Application wizard of Qt Creator.
|
|
|
|
|
MainWindow is a convenience class containing mobile device specific code
|
|
|
|
|
such as screen orientation handling.
|
|
|
|
|
It is recommended not to modify this file, since newer versions of Qt Creator
|
|
|
|
|
may offer an updated version of it.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-09-13 11:20:13 +02:00
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 17:03:46 +01:00
|
|
|
void MainWindow::setOrientation(ScreenOrientation orientation)
|
2010-09-13 11:20:13 +02:00
|
|
|
{
|
2011-02-02 13:41:22 +01:00
|
|
|
#if defined(Q_OS_SYMBIAN)
|
|
|
|
|
// If the version of Qt on the device is < 4.7.2, that attribute won't work
|
2010-11-01 17:03:46 +01:00
|
|
|
if (orientation != ScreenOrientationAuto) {
|
2011-02-02 13:41:22 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2010-09-13 11:20:13 +02:00
|
|
|
}
|
2011-02-02 13:41:22 +01:00
|
|
|
#endif // Q_OS_SYMBIAN
|
|
|
|
|
|
2010-09-13 11:20:13 +02:00
|
|
|
Qt::WidgetAttribute attribute;
|
|
|
|
|
switch (orientation) {
|
2011-02-02 13:41:22 +01:00
|
|
|
#if QT_VERSION < 0x040702
|
|
|
|
|
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationLockPortrait:
|
2011-02-02 13:41:22 +01:00
|
|
|
attribute = static_cast<Qt::WidgetAttribute>(128);
|
2010-09-13 11:20:13 +02:00
|
|
|
break;
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationLockLandscape:
|
2011-02-02 13:41:22 +01:00
|
|
|
attribute = static_cast<Qt::WidgetAttribute>(129);
|
2010-09-13 11:20:13 +02:00
|
|
|
break;
|
2011-02-02 13:41:22 +01:00
|
|
|
default:
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationAuto:
|
2011-02-02 13:41:22 +01:00
|
|
|
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;
|
2010-09-13 11:20:13 +02:00
|
|
|
default:
|
2011-02-02 13:41:22 +01:00
|
|
|
case ScreenOrientationAuto:
|
|
|
|
|
attribute = Qt::WA_AutoOrientation;
|
2010-09-13 11:20:13 +02:00
|
|
|
break;
|
2011-02-02 13:41:22 +01:00
|
|
|
#endif // QT_VERSION < 0x040702
|
|
|
|
|
};
|
2010-09-13 11:20:13 +02:00
|
|
|
setAttribute(attribute, true);
|
|
|
|
|
}
|
2010-11-01 19:19:32 +01:00
|
|
|
|
|
|
|
|
void MainWindow::showExpanded()
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_SYMBIAN
|
|
|
|
|
showFullScreen();
|
2011-01-14 15:45:53 +01:00
|
|
|
#elif defined(Q_WS_MAEMO_5)
|
2010-11-01 19:19:32 +01:00
|
|
|
showMaximized();
|
|
|
|
|
#else
|
|
|
|
|
show();
|
|
|
|
|
#endif
|
|
|
|
|
}
|