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