Commit 807e4be44e1bca6356f7b6061f643b6d4140f119

adding orientation example
  
1/*
2 Maemo Orientation Example - main.cpp
3
4 Author(s):
5 Timo Härkönen
6*/
7
8#include <QApplication>
9
10#include "mainwindow.h"
11
12int main(int argc, char *argv[])
13{
14 QApplication app(argc, argv);
15
16 MainWindow mw;
17 mw.show();
18
19 return app.exec();
20}
  
1/*
2 Maemo Orientation Example - mainwindow.cpp
3
4 Author(s):
5 Timo Härkönen
6*/
7
8#include "mainwindow.h"
9
10#include <QPushButton>
11#include <QMenuBar>
12
13using Maemo::Portrait;
14using Maemo::Landscape;
15
16MainWindow::MainWindow(QWidget *parent) :
17 QMainWindow(parent)
18{
19 landscape = true;
20
21 orientation = new Maemo::QOrientationCapability(this, false);
22
23 button = new QPushButton(tr("Click to flip screen"), this);
24
25 connect(button, SIGNAL(clicked()), this, SLOT(flip()));
26
27 createActions();
28 createMenu();
29
30 setCentralWidget(button);
31}
32
33void MainWindow::flip()
34{
35 if(landscape) {
36 orientation->setOrientation(Portrait);
37 landscape = false;
38 }
39 else {
40 orientation->setOrientation(Landscape);
41 landscape = true;
42 }
43}
44
45void MainWindow::toggleOrientationChangeMode()
46{
47 if(orientation->isListeningOrientationChanges()) {
48 orientation->setListeningForOrientationChanges(false);
49 orientationChangeModeAction->setText(tr("Enable automatic orientation changing"));
50 connect(button, SIGNAL(clicked()), this, SLOT(flip()));
51 button->setText(tr("Click to flip screen"));
52 }
53 else {
54 orientation->setListeningForOrientationChanges(true);
55 orientationChangeModeAction->setText(tr("Disable automatic orientation changing"));
56 disconnect(button, SIGNAL(clicked()), this, SLOT(flip()));
57 button->setText(tr("Rotate device to flip screen"));
58 }
59}
60
61void MainWindow::createActions()
62{
63 quitAction = new QAction(tr("Quit"), this);
64 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
65
66 orientationChangeModeAction = new QAction(tr("Enable automatic orientation changing"), this);
67 connect(orientationChangeModeAction, SIGNAL(triggered()), this, SLOT(toggleOrientationChangeMode()));
68}
69
70void MainWindow::createMenu()
71{
72 menu = menuBar()->addMenu("fremantle");
73
74 menu->addAction(orientationChangeModeAction);
75 menu->addAction(quitAction);
76}
  
1/*
2 Maemo Orientation Example - mainwindow.h
3
4 Author(s):
5 Timo Härkönen
6*/
7
8#ifndef MAINWINDOW_H
9#define MAINWINDOW_H
10
11#include <QMainWindow>
12
13#include "../../widgetcapabilities/qorientationcapability.h"
14
15class QPushButton;
16class QMenu;
17
18class MainWindow : public QMainWindow
19{
20 Q_OBJECT
21
22public:
23 MainWindow(QWidget *parent = 0);
24
25public slots:
26 void flip();
27 void toggleOrientationChangeMode();
28
29private:
30 void createMenu();
31 void createActions();
32
33 QPushButton *button;
34 Maemo::QOrientationCapability *orientation;
35 bool landscape;
36 QMenu *menu;
37 QAction *quitAction;
38 QAction *orientationChangeModeAction;
39
40
41};
42#endif
  
1TEMPLATE = app
2TARGET =
3DEPENDPATH += .
4INCLUDEPATH += .
5
6# Input
7HEADERS += mainwindow.h
8SOURCES += main.cpp mainwindow.cpp
9
10LIBS += -lQHildon-WidgetCapabilities