mainwindow.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QtCore/QCoreApplication>
  4. MainWindow::MainWindow(QWidget *parent)
  5. : QMainWindow(parent), ui(new Ui::MainWindow)
  6. {
  7. ui->setupUi(this);
  8. m_timer.setInterval( 1000 * 60 );
  9. connect( &m_timer, SIGNAL(timeout()), this, SLOT(UpdateTime()) );
  10. connect( ui->dial_h, SIGNAL(valueChanged(int)), this, SLOT(UpdateTime()));
  11. connect( ui->dial_m, SIGNAL(valueChanged(int)), this, SLOT(UpdateTime()));
  12. m_timer.start();
  13. UpdateTime();
  14. }
  15. MainWindow::~MainWindow()
  16. {
  17. delete ui;
  18. }
  19. void MainWindow::UpdateTime()
  20. {
  21. QTime cur = QTime::currentTime();
  22. ui->timeEdit_mobile->setTime( cur );
  23. QTime tm( ui->spinBox_h->value(), ui->spinBox_m->value() );
  24. int tt = QTime().secsTo( tm );
  25. ui->timeEdit_result->setTime( cur.addSecs( tt ) );
  26. }
  27. void MainWindow::setOrientation(ScreenOrientation orientation)
  28. {
  29. #if defined(Q_OS_SYMBIAN)
  30. // If the version of Qt on the device is < 4.7.2, that attribute won't work
  31. if (orientation != ScreenOrientationAuto) {
  32. const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
  33. if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
  34. qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
  35. return;
  36. }
  37. }
  38. #endif // Q_OS_SYMBIAN
  39. Qt::WidgetAttribute attribute;
  40. switch (orientation) {
  41. #if QT_VERSION < 0x040702
  42. // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
  43. case ScreenOrientationLockPortrait:
  44. attribute = static_cast<Qt::WidgetAttribute>(128);
  45. break;
  46. case ScreenOrientationLockLandscape:
  47. attribute = static_cast<Qt::WidgetAttribute>(129);
  48. break;
  49. default:
  50. case ScreenOrientationAuto:
  51. attribute = static_cast<Qt::WidgetAttribute>(130);
  52. break;
  53. #else // QT_VERSION < 0x040702
  54. case ScreenOrientationLockPortrait:
  55. attribute = Qt::WA_LockPortraitOrientation;
  56. break;
  57. case ScreenOrientationLockLandscape:
  58. attribute = Qt::WA_LockLandscapeOrientation;
  59. break;
  60. default:
  61. case ScreenOrientationAuto:
  62. attribute = Qt::WA_AutoOrientation;
  63. break;
  64. #endif // QT_VERSION < 0x040702
  65. };
  66. setAttribute(attribute, true);
  67. }
  68. void MainWindow::showExpanded()
  69. {
  70. #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
  71. showFullScreen();
  72. #elif defined(Q_WS_MAEMO_5)
  73. showMaximized();
  74. #else
  75. show();
  76. #endif
  77. }