1 #include "mainwindow.h"
11 #include <QtCore/QCoreApplication>
13 MainWindow::MainWindow(QWidget *parent)
16 QMenuBar *bar = menuBar();
18 QSettings settings("igorinov", "ameter", this);
20 g_n = settings.value("g", g_n).toDouble();
21 a_max = settings.value("max", a_max).toDouble();
22 divisions = settings.value("divisions", divisions).toInt();
23 angle_step = settings.value("angle_step", angle_step).toInt();
24 data_rate = settings.value("rate", data_rate).toInt();
26 awidget = new AMeterWidget(this);
27 setCentralWidget(awidget);
28 action = bar->addAction("&About");
29 action = bar->addAction("&Settings");
30 connect(action, SIGNAL(triggered()), this, SLOT(changeSettings()));
31 accelerometer = new QAccelerometer(this);
32 accelerometer->setProperty("alwaysOn", true);
33 accelerometer->addFilter(awidget);
34 accelerometer->setDataRate(data_rate);
35 accelerometer->start();
39 MainWindow::~MainWindow()
45 void MainWindow::changeSettings()
47 SettingsDialog dialog(this);
48 QSettings settings("igorinov", "ameter", this);
50 if (dialog.exec() != QDialog::Accepted)
55 settings.setValue("g", g_n);
56 settings.setValue("max", a_max);
57 settings.setValue("divisions", divisions);
58 settings.setValue("angle_step", angle_step);
59 settings.setValue("rate", data_rate);
61 awidget->setGravity(g_n);
62 accelerometer->stop();
63 accelerometer->setDataRate(data_rate);
64 accelerometer->start();
67 void MainWindow::setOrientation(ScreenOrientation orientation)
69 #if defined(Q_OS_SYMBIAN)
70 // If the version of Qt on the device is < 4.7.2, that attribute won't work
71 if (orientation != ScreenOrientationAuto) {
72 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
73 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
74 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
78 #endif // Q_OS_SYMBIAN
80 Qt::WidgetAttribute attribute;
81 switch (orientation) {
82 #if QT_VERSION < 0x040702
83 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
84 case ScreenOrientationLockPortrait:
85 attribute = static_cast<Qt::WidgetAttribute>(128);
87 case ScreenOrientationLockLandscape:
88 attribute = static_cast<Qt::WidgetAttribute>(129);
91 case ScreenOrientationAuto:
92 attribute = static_cast<Qt::WidgetAttribute>(130);
94 #else // QT_VERSION < 0x040702
95 case ScreenOrientationLockPortrait:
96 attribute = Qt::WA_LockPortraitOrientation;
98 case ScreenOrientationLockLandscape:
99 attribute = Qt::WA_LockLandscapeOrientation;
102 case ScreenOrientationAuto:
103 attribute = Qt::WA_AutoOrientation;
105 #endif // QT_VERSION < 0x040702
107 setAttribute(attribute, true);
110 void MainWindow::showExpanded()
114 #elif defined(Q_WS_MAEMO_5)