Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  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), deviceInfo(NULL)
  8. {
  9. ui->setupUi(this);
  10. setupGeneral();
  11. }
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void MainWindow::setOrientation(ScreenOrientation orientation)
  19. {
  20. #if defined(Q_OS_SYMBIAN)
  21. // If the version of Qt on the device is < 4.7.2, that attribute won't work
  22. if (orientation != ScreenOrientationAuto) {
  23. const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
  24. if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
  25. qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
  26. return;
  27. }
  28. }
  29. #endif // Q_OS_SYMBIAN
  30.  
  31. Qt::WidgetAttribute attribute;
  32. switch (orientation) {
  33. #if QT_VERSION < 0x040702
  34. // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
  35. case ScreenOrientationLockPortrait:
  36. attribute = static_cast<Qt::WidgetAttribute>(128);
  37. break;
  38. case ScreenOrientationLockLandscape:
  39. attribute = static_cast<Qt::WidgetAttribute>(129);
  40. break;
  41. default:
  42. case ScreenOrientationAuto:
  43. attribute = static_cast<Qt::WidgetAttribute>(130);
  44. break;
  45. #else // QT_VERSION < 0x040702
  46. case ScreenOrientationLockPortrait:
  47. attribute = Qt::WA_LockPortraitOrientation;
  48. break;
  49. case ScreenOrientationLockLandscape:
  50. attribute = Qt::WA_LockLandscapeOrientation;
  51. break;
  52. default:
  53. case ScreenOrientationAuto:
  54. attribute = Qt::WA_AutoOrientation;
  55. break;
  56. #endif // QT_VERSION < 0x040702
  57. };
  58. setAttribute(attribute, true);
  59. }
  60.  
  61. void MainWindow::showExpanded()
  62. {
  63. #ifdef Q_OS_SYMBIAN
  64. showFullScreen();
  65. #elif defined(Q_WS_MAEMO_5)
  66. showMaximized();
  67. #else
  68. show();
  69. #endif
  70. }
  71.  
  72. void MainWindow::setupGeneral()
  73. {
  74. deviceInfo = new QSystemDeviceInfo(this);
  75. ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
  76. connect(deviceInfo, SIGNAL(batteryLevelChanged(int)), ui->batteryLevelBar, SLOT(setValue(int)));
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement