1 #include <QtCore/QCoreApplication>
4 #include <mce/dbus-names.h>
5 #include <mce/mode-names.h>
8 #include "mainwindow.h"
15 extern int angle_step;
21 static QDBusConnection dBusConnection = QDBusConnection::systemBus();
24 MainWindow::MainWindow(QWidget *parent)
27 QMenuBar *bar = menuBar();
29 QSettings settings("igorinov", "ameter", this);
31 g_n = settings.value("g", g_n).toDouble();
32 a_max = settings.value("max", a_max).toDouble();
33 divisions = settings.value("divisions", divisions).toInt();
34 angle_step = settings.value("angle_step", angle_step).toInt();
35 smoothing = settings.value("smoothing", smoothing).toInt();
36 data_rate = settings.value("rate", data_rate).toInt();
38 awidget = new AMeterWidget(this);
39 setCentralWidget(awidget);
40 action = bar->addAction("&About");
41 connect(action, SIGNAL(triggered()), this, SLOT(showAbout()));
42 action = bar->addAction("&Settings");
43 connect(action, SIGNAL(triggered()), this, SLOT(showSettings()));
44 accelerometer = new QAccelerometer(this);
45 accelerometer->setProperty("alwaysOn", true);
46 accelerometer->addFilter(awidget);
47 accelerometer->setDataRate(data_rate);
48 accelerometer->start();
51 dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
52 MCE_REQUEST_IF, dBusConnection, this);
54 dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
55 MCE_DISPLAY_SIG, this, SLOT(screenChange(const QDBusMessage &)));
59 MainWindow::~MainWindow()
65 void MainWindow::showAbout()
67 AboutDialog dialog(this);
72 void MainWindow::showSettings()
74 SettingsDialog dialog(this);
75 QSettings settings("igorinov", "ameter", this);
78 accelerometer->stop();
80 accelerometer->start();
81 if (code != QDialog::Accepted)
86 settings.setValue("g", g_n);
87 settings.setValue("max", a_max);
88 settings.setValue("divisions", divisions);
89 settings.setValue("angle_step", angle_step);
90 settings.setValue("rate", data_rate);
92 awidget->setGravity(g_n);
93 accelerometer->setDataRate(data_rate);
96 void MainWindow::setOrientation(ScreenOrientation orientation)
98 Qt::WidgetAttribute attribute;
99 switch (orientation) {
100 #if QT_VERSION < 0x040702
101 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
102 case ScreenOrientationLockPortrait:
103 attribute = static_cast<Qt::WidgetAttribute>(128);
105 case ScreenOrientationLockLandscape:
106 attribute = static_cast<Qt::WidgetAttribute>(129);
109 case ScreenOrientationAuto:
110 attribute = static_cast<Qt::WidgetAttribute>(130);
112 #else // QT_VERSION < 0x040702
113 case ScreenOrientationLockPortrait:
114 attribute = Qt::WA_LockPortraitOrientation;
116 case ScreenOrientationLockLandscape:
117 attribute = Qt::WA_LockLandscapeOrientation;
120 case ScreenOrientationAuto:
121 attribute = Qt::WA_AutoOrientation;
123 #endif // QT_VERSION < 0x040702
125 setAttribute(attribute, true);
128 void MainWindow::showExpanded()
132 #elif defined(Q_WS_MAEMO_5)
140 void MainWindow::screenChange(const QDBusMessage &message)
142 QString state = message.arguments().at(0).toString();
143 if (!state.isEmpty()) {
144 if (state == MCE_DISPLAY_OFF_STRING)
145 accelerometer->stop();
146 if (state == MCE_DISPLAY_ON_STRING)
147 accelerometer->start();