Commit e0acc209 authored by Andrew Flegg's avatar Andrew Flegg

Initial revision of prototype

parents
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=attitude
Exec=/opt/usr/bin/attitude
Icon=attitude
X-Window-Icon=
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable
# Add more folders to ship with the application, here
folder_01.source = qml/attitude
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
symbian:TARGET.UID3 = 0xE6DA552B
# Allow network access on Symbian
#symbian:TARGET.CAPABILITY += NetworkServices
symbian:TARGET.CAPABILITY =
# Define QMLJSDEBUGGER to allow debugging of QML in debug builds
# (This might significantly increase build time)
# DEFINES += QMLJSDEBUGGER
# If your application uses the Qt Mobility libraries, uncomment
# the following lines and add the respective components to the
# MOBILITY variable.
CONFIG += mobility
MOBILITY += sensors
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()
HEADERS +=
This diff is collapsed.
This diff is collapsed.
#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlapplicationviewer.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewer.engine()->addImportPath(QString("/opt/qtm11/imports"));
#if defined(Q_OS__SYMBIAN)
viewer.engine()->rootContext()->setContextProperty("rotateFudge", -90);
#else
viewer.engine()->rootContext()->setContextProperty("rotateFudge", 0);
#endif
viewer.setMainQmlFile(QLatin1String("qml/attitude/main.qml"));
viewer.showExpanded();
return app.exec();
}
import QtQuick 1.0
import QtMobility.sensors 1.1
/**
* The accelerometer control logic.
*
* The following properties are exposed for external use:
* * dip (double). -1.0 - 1.0 representing tilt of device.
* * angle (double). -180 - 180 representing rotation of device.
*
* The following method is available:
* * calibrate() - consider the current values as centred.
*/
Accelerometer {
id: self
property variant previousDip: [ 0.0, 0.0, 0.0, 0.0, 0.0 ]
property variant previousAngle: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
property variant calibration: [0.0, 0.0]
property double dip: 0.0
property double angle: 0.0
signal movement(double dip, double angle)
/**
* Consider the current position as our default centre.
*/
function calibrate() {
calibration = [dip, angle]
console.log(rotateFudge)
}
/**
* Start receiving values immediately.
*/
Component.onCompleted: start()
/**
* When the reading changes, filter and then expose.
*/
onReadingChanged: {
var rawDip = Math.max(Math.min(reading.z / 9.8, 1), -1)
var rawAngle = rotateFudge + Math.atan2(reading.x, reading.y) * 180/Math.PI
var set = [] // Can't update a list property, but can re-assign it
var mean = rawAngle // Total of values contributing to the next
var count = 1 // How many items we're counting
for (var i = 1; i < previousAngle.length; i++) {
if (Math.abs((rawAngle - previousAngle[i]) / rawAngle) < 0.2) {
mean += previousAngle[i]
count++
}
set[i - 1] = previousAngle[i]
}
set[previousAngle.length - 1] = rawAngle
previousAngle = set
var newAngle = mean / count
set = []
mean = rawDip
count = 1
for (var i = 1; i < previousDip.length; i++) {
if (Math.abs((rawDip - previousDip[i]) / rawDip) < 0.2) {
mean += previousDip[i]
count++
}
set[i - 1] = previousDip[i]
}
set[previousDip.length - 1] = rawDip
previousDip = set
var newDip = mean / count
if (newDip != self.dip || newAngle != self.angle) {
self.dip = newDip
self.angle = newAngle
self.movement(newDip, newAngle)
}
}
}
import QtQuick 1.0
Rectangle {
height: 1
color: "#ffffff"
}
import QtQuick 1.0
Rectangle {
id: window
width: 800
height: 480
/**
* Contains the ground and the sky, and the pivot around which
* we rotate.
*/
Rectangle {
id: world
x: -parent.width
y: -parent.height * 2.5
width: parent.width * 3
height: parent.height * 6
transformOrigin: Item.Center
rotation: 0
Rectangle {
id: view
x: 0
y: 0
width: world.width
height: world.height
Rectangle {
id: sky
anchors.top: view.top
anchors.bottom: view.verticalCenter
anchors.left: view.left
anchors.right: view.right
gradient: Gradient {
GradientStop { position: 0; color: "#006bd6" }
GradientStop { position: 0.66; color: "#1e94ff" }
GradientStop { position: 1; color: "#1e94ff" }
}
}
Rectangle {
id: ground
anchors.top: view.verticalCenter
anchors.bottom: view.bottom
anchors.left: view.left
anchors.right: view.right
gradient: Gradient {
GradientStop { position: 0; color: "#57990a" }
GradientStop { position: 0.66; color: "#007b00" }
GradientStop { position: 1; color: "#007b00" }
}
}
}
Rectangle {
id: horizon
opacity: 0.8
HorizontalLine {
x: (world.width / 2) - 90
y: world.height / 2
width: 50
}
HorizontalLine {
x: (world.width / 2) + 40
y: world.height / 2
width: 50
}
}
Rectangle {
id: heightBars
opacity: 0.8
property int barHeight: world.height / 10
property int barWidth: 30
HorizontalLine {
id: heightBarTop
x: (world.width / 2) - parent.barWidth
y: (world.height / 2) - (parent.barHeight / 2)
width: parent.barWidth
}
Rectangle {
id: heightBarMain
x: world.width / 2
y: heightBarTop.y
width: 1
height: parent.barHeight
color: "#ffffff"
}
HorizontalLine {
id: heightBarBottom
x: heightBarMain.x
y: heightBarMain.y + parent.barHeight
width: parent.barWidth
}
// There *has* to be a better way of doing this, right?
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 2
y: heightBarMain.y + parent.barHeight * 1/10
width: parent.barWidth
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 4
y: heightBarMain.y + parent.barHeight * 2/10
width: parent.barWidth / 2
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 4
y: heightBarMain.y + parent.barHeight * 3/10
width: parent.barWidth / 2
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 4
y: heightBarMain.y + parent.barHeight * 4/10
width: parent.barWidth / 2
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth * 0.9
y: heightBarMain.y + parent.barHeight * 5/10
width: parent.barWidth * 1.8
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 4
y: heightBarMain.y + parent.barHeight * 6/10
width: parent.barWidth / 2
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 4
y: heightBarMain.y + parent.barHeight * 7/10
width: parent.barWidth / 2
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 4
y: heightBarMain.y + parent.barHeight * 8/10
width: parent.barWidth / 2
}
HorizontalLine {
x: heightBarMain.x - parent.barWidth / 2
y: heightBarMain.y + parent.barHeight * 9/10
width: parent.barWidth
}
}
}
/**
* The angle meter in the top-right.
*/
Text {
id: telemetry
text: "-"
font.pointSize: 10 + window.height / 48
x: parent.width - 35
y: 10
color: "#ffffff"
onTextChanged: {
telemetry.x = parent.width - 30 - telemetry.width
}
MouseArea {
anchors.fill: parent
onClicked: accelerometer.calibrate()
}
}
/**
* The accelerometer control logic.
*/
CalibratedAccelerometer {
id: accelerometer
onMovement: {
telemetry.text = Math.round(angle) + "\u00b0"
view.y = -dip * world.height / 3.2
world.rotation = angle
heightBars.y = dip * heightBars.barHeight / 4
}
}
}
// checksum 0x17fa version 0x3000a
/*
This file was generated by the Qt Quick Application wizard of Qt Creator.
QmlApplicationViewer is a convenience class containing mobile device specific
code such as screen orientation handling. Also QML paths and debugging are
handled here.
It is recommended not to modify this file, since newer versions of Qt Creator
may offer an updated version of it.
*/
#include "qmlapplicationviewer.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext>
#if defined(QMLJSDEBUGGER)
#include <qt_private/qdeclarativedebughelper_p.h>
#endif
#if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
#include <jsdebuggeragent.h>
#endif
#if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
#include <qdeclarativeviewobserver.h>
#endif
#if defined(QMLJSDEBUGGER)
// Enable debugging before any QDeclarativeEngine is created
struct QmlJsDebuggingEnabler
{
QmlJsDebuggingEnabler()
{
QDeclarativeDebugHelper::enableDebugging();
}
};
// Execute code in constructor before first QDeclarativeEngine is instantiated
static QmlJsDebuggingEnabler enableDebuggingHelper;
#endif // QMLJSDEBUGGER
class QmlApplicationViewerPrivate
{
QString mainQmlFile;
friend class QmlApplicationViewer;
static QString adjustPath(const QString &path);
};
QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
{
#ifdef Q_OS_UNIX
#ifdef Q_OS_MAC
if (!QDir::isAbsolutePath(path))
return QCoreApplication::applicationDirPath()
+ QLatin1String("/../Resources/") + path;
#else
const QString pathInShareDir = QCoreApplication::applicationDirPath()
+ QLatin1String("/../share/")
+ QFileInfo(QCoreApplication::applicationFilePath()).fileName()
+ QLatin1Char('/') + path;
if (QFileInfo(pathInShareDir).exists())
return pathInShareDir;
#endif
#endif
return path;
}
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
QDeclarativeView(parent),
m_d(new QmlApplicationViewerPrivate)
{
connect(engine(), SIGNAL(quit()), SLOT(close()));
setResizeMode(QDeclarativeView::SizeRootObjectToView);
#if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
new QmlJSDebugger::JSDebuggerAgent(engine());
#endif
#if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
#endif
}
QmlApplicationViewer::~QmlApplicationViewer()
{
delete m_d;
}
void QmlApplicationViewer::setMainQmlFile(const QString &file)
{
m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
}
void QmlApplicationViewer::addImportPath(const QString &path)
{
engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
}
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
{
#if defined(Q_OS_SYMBIAN)
// If the version of Qt on the device is < 4.7.2, that attribute won't work
if (orientation != ScreenOrientationAuto) {
const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
return;
}
}
#endif // Q_OS_SYMBIAN
Qt::WidgetAttribute attribute;
switch (orientation) {
#if QT_VERSION < 0x040702
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
case ScreenOrientationLockPortrait:
attribute = static_cast<Qt::WidgetAttribute>(128);
break;
case ScreenOrientationLockLandscape:
attribute = static_cast<Qt::WidgetAttribute>(129);
break;
default:
case ScreenOrientationAuto:
attribute = static_cast<Qt::WidgetAttribute>(130);
break;
#else // QT_VERSION < 0x040702
case ScreenOrientationLockPortrait:
attribute = Qt::WA_LockPortraitOrientation;
break;
case ScreenOrientationLockLandscape:
attribute = Qt::WA_LockLandscapeOrientation;
break;
default:
case ScreenOrientationAuto:
attribute = Qt::WA_AutoOrientation;
break;
#endif // QT_VERSION < 0x040702
};
setAttribute(attribute, true);
}
void QmlApplicationViewer::showExpanded()
{
#ifdef Q_OS_SYMBIAN
showFullScreen();
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
showMaximized();
#else
show();
#endif
}
// checksum 0x5a59 version 0x3000a
/*
This file was generated by the Qt Quick Application wizard of Qt Creator.
QmlApplicationViewer is a convenience class containing mobile device specific
code such as screen orientation handling. Also QML paths and debugging are
handled here.
It is recommended not to modify this file, since newer versions of Qt Creator
may offer an updated version of it.
*/
#ifndef QMLAPPLICATIONVIEWER_H
#define QMLAPPLICATIONVIEWER_H
#include <QtDeclarative/QDeclarativeView>
class QmlApplicationViewer : public QDeclarativeView
{
Q_OBJECT
public:
enum ScreenOrientation {
ScreenOrientationLockPortrait,
ScreenOrientationLockLandscape,
ScreenOrientationAuto
};
explicit QmlApplicationViewer(QWidget *parent = 0);
virtual ~QmlApplicationViewer();
void setMainQmlFile(const QString &file);
void addImportPath(const QString &path);
void setOrientation(ScreenOrientation orientation);
void showExpanded();
private:
class QmlApplicationViewerPrivate *m_d;
};
#endif // QMLAPPLICATIONVIEWER_H
# checksum 0x8396 version 0x3000a
# This file was generated by the Qt Quick Application wizard of Qt Creator.
# The code below adds the QmlApplicationViewer to the project and handles the
# activation of QML debugging.
# It is recommended not to modify this file, since newer versions of Qt Creator
# may offer an updated version of it.
QT += declarative
SOURCES += $$PWD/qmlapplicationviewer.cpp
HEADERS += $$PWD/qmlapplicationviewer.h
INCLUDEPATH += $$PWD
defineTest(minQtVersion) {
maj = $$1
min = $$2
patch = $$3
isEqual(QT_MAJOR_VERSION, $$maj) {
isEqual(QT_MINOR_VERSION, $$min) {
isEqual(QT_PATCH_VERSION, $$patch) {
return(true)
}
greaterThan(QT_PATCH_VERSION, $$patch) {
return(true)
}
}
greaterThan(QT_MINOR_VERSION, $$min) {
return(true)
}
}
return(false)
}
contains(DEFINES, QMLJSDEBUGGER) {
CONFIG(debug, debug|release) {
!minQtVersion(4, 7, 1) {
warning()
warning("Disabling QML debugging:")
warning()
warning("Debugging QML requires the qmljsdebugger library that ships with Qt Creator.")
warning("This library requires Qt 4.7.1 or newer.")
warning()
DEFINES -= QMLJSDEBUGGER
} else:isEmpty(QMLJSDEBUGGER_PATH) {
warning()
warning("Disabling QML debugging:")
warning()
warning("Debugging QML requires the qmljsdebugger library that ships with Qt Creator.")
warning("Please specify its location on the qmake command line, eg")
warning(" qmake -r QMLJSDEBUGGER_PATH=$CREATORDIR/share/qtcreator/qmljsdebugger")
warning()
DEFINES -= QMLJSDEBUGGER
} else {
include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
}
} else {
DEFINES -= QMLJSDEBUGGER
}
}
# This file was generated by an application wizard of Qt Creator.
# The code below handles deployment to Symbian and Maemo, aswell as copying
# of the application data to shadow build directories on desktop.
# It is recommended not to modify this file, since newer versions of Qt Creator
# may offer an updated version of it.
defineTest(qtcAddDeployment) {
for(deploymentfolder, DEPLOYMENTFOLDERS) {
item = item$${deploymentfolder}
itemsources = $${item}.sources
$$itemsources = $$eval($${deploymentfolder}.source)
itempath = $${item}.path
$$itempath= $$eval($${deploymentfolder}.target)
export($$itemsources)
export($$itempath)
DEPLOYMENT += $$item
}
MAINPROFILEPWD = $$PWD
symbian {
isEmpty(ICON):exists($${TARGET}.svg):ICON = $${TARGET}.svg
isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
} else:win32 {
copyCommand =
for(deploymentfolder, DEPLOYMENTFOLDERS) {
source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source)
source = $$replace(source, /, \\)
sourcePathSegments = $$split(source, \\)
target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments)
target = $$replace(target, /, \\)
!isEqual(source,$$target) {
!isEmpty(copyCommand):copyCommand += &&
copyCommand += $(COPY_DIR) \"$$source\" \"$$target\"
}
}
!isEmpty(copyCommand) {
copyCommand = @echo Copying application data... && $$copyCommand
copydeploymentfolders.commands = $$copyCommand
first.depends = $(first) copydeploymentfolders
export(first.depends)
export(copydeploymentfolders.commands)
QMAKE_EXTRA_TARGETS += first copydeploymentfolders
}
} else:unix {
maemo5 {
installPrefix = /opt/usr
desktopfile.path = /usr/share/applications/hildon
} else {
installPrefix = /usr/local
desktopfile.path = /usr/share/applications
copyCommand =
for(deploymentfolder, DEPLOYMENTFOLDERS) {
source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source)
source = $$replace(source, \\, /)
macx {
target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target)
} else {
target = $$OUT_PWD/$$eval($${deploymentfolder}.target)
}
target = $$replace(target, \\, /)
sourcePathSegments = $$split(source, /)
targetFullPath = $$target/$$last(sourcePathSegments)
!isEqual(source,$$targetFullPath) {
!isEmpty(copyCommand):copyCommand += &&
copyCommand += $(MKDIR) \"$$target\"
copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\"
}
}
!isEmpty(copyCommand) {
copyCommand = @echo Copying application data... && $$copyCommand
copydeploymentfolders.commands = $$copyCommand
first.depends = $(first) copydeploymentfolders
export(first.depends)
export(copydeploymentfolders.commands)
QMAKE_EXTRA_TARGETS += first copydeploymentfolders
}
}
for(deploymentfolder, DEPLOYMENTFOLDERS) {
item = item$${deploymentfolder}
itemfiles = $${item}.files
$$itemfiles = $$eval($${deploymentfolder}.source)
itempath = $${item}.path
$$itempath = $${installPrefix}/share/$${TARGET}/$$eval($${deploymentfolder}.target)
export($$itemfiles)
export($$itempath)
INSTALLS += $$item
}
icon.files = $${TARGET}.png
icon.path = /usr/share/icons/hicolor/64x64/apps
desktopfile.files = $${TARGET}.desktop
target.path = $${installPrefix}/bin
export(icon.files)
export(icon.path)
export(desktopfile.files)
export(desktopfile.path)
export(target.path)
INSTALLS += desktopfile icon target
}
export (ICON)
export (INSTALLS)
export (DEPLOYMENT)
export (TARGET.EPOCHEAPSIZE)
export (TARGET.CAPABILITY)
export (LIBS)
export (QMAKE_EXTRA_TARGETS)
}
The Debian Package attitude
----------------------------
Comments regarding the Package
-- Andrew Flegg <andrew@bleb.org> Sat, 05 Mar 2011 10:48:31 +0000
attitude (0.0.1) unstable; urgency=low
* Initial Release.
-- Andrew Flegg <andrew@bleb.org> Sat, 05 Mar 2011 10:48:31 +0000
Source: attitude
Section: user/hidden
Priority: optional
Maintainer: Andrew Flegg <andrew@bleb.org>