mainwindow.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. * This component and the accompanying materials are made available
  5. * under the terms of "Eclipse Public License v1.0"
  6. * which accompanies this distribution, and is available
  7. * at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. *
  9. * Initial Contributors:
  10. * Nokia Corporation - initial contribution.
  11. *
  12. * Contributors:
  13. *
  14. * Description: Part of Qt NFC Setting sample application.
  15. */
  16. // checksum 0xa193 version 0x30001
  17. /*
  18. This file was generated by the Mobile Qt Application wizard of Qt Creator.
  19. MainWindow is a convenience class containing mobile device specific code
  20. such as screen orientation handling.
  21. It is recommended not to modify this file, since newer versions of Qt Creator
  22. may offer an updated version of it.
  23. */
  24. #include "mainwindow.h"
  25. #include "ui_mainwindow.h"
  26. #include <QtCore/QCoreApplication>
  27. MainWindow::MainWindow(QWidget *parent)
  28. : QMainWindow(parent), ui(new Ui::MainWindow)
  29. {
  30. ui->setupUi(this);
  31. }
  32. MainWindow::~MainWindow()
  33. {
  34. delete ui;
  35. }
  36. void MainWindow::setOrientation(ScreenOrientation orientation)
  37. {
  38. #if defined(Q_OS_SYMBIAN)
  39. // If the version of Qt on the device is < 4.7.2, that attribute won't work
  40. if (orientation != ScreenOrientationAuto) {
  41. const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
  42. if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
  43. qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
  44. return;
  45. }
  46. }
  47. #endif // Q_OS_SYMBIAN
  48. Qt::WidgetAttribute attribute;
  49. switch (orientation) {
  50. #if QT_VERSION < 0x040702
  51. // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
  52. case ScreenOrientationLockPortrait:
  53. attribute = static_cast<Qt::WidgetAttribute>(128);
  54. break;
  55. case ScreenOrientationLockLandscape:
  56. attribute = static_cast<Qt::WidgetAttribute>(129);
  57. break;
  58. default:
  59. case ScreenOrientationAuto:
  60. attribute = static_cast<Qt::WidgetAttribute>(130);
  61. break;
  62. #else // QT_VERSION < 0x040702
  63. case ScreenOrientationLockPortrait:
  64. attribute = Qt::WA_LockPortraitOrientation;
  65. break;
  66. case ScreenOrientationLockLandscape:
  67. attribute = Qt::WA_LockLandscapeOrientation;
  68. break;
  69. default:
  70. case ScreenOrientationAuto:
  71. attribute = Qt::WA_AutoOrientation;
  72. break;
  73. #endif // QT_VERSION < 0x040702
  74. };
  75. setAttribute(attribute, true);
  76. }
  77. void MainWindow::showExpanded()
  78. {
  79. #ifdef Q_OS_SYMBIAN
  80. showFullScreen();
  81. #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
  82. showMaximized();
  83. #else
  84. show();
  85. #endif
  86. }