Namespaces
Variants
Actions
Revision as of 22:50, 7 May 2012 by lildeimos (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

QML horizon component for camera apps

Jump to: navigation, search

This article explains how to use QML horizon line component

Article Metadata

Tested with
SDK: Nokia Qt SDK 1.2.0
Devices(s): Nokia C7-00, Nokia N950

Compatibility
Platform(s): Symbian^3 and later, Harmattan
Device(s): All* (must have internal Accelerometer senso)

Article
Keywords: Horizon, QDeclarativeItem, QAccelerometer
Created: lildeimos (08 May 2012)
Last edited: lildeimos (07 May 2012)

Introduction

This QML component draws a overlay horizon line on top of the parent Item. horizon in portrait horizon in landscape

Overview

While developing this component, I chosen to use QAccelerometer sensor intead QRotationSensor. The reson is that some devices doesn't support Z -axis and for example my Nokia C7 has a step of 15° deg of values. Should not be a big deal to replace the current accelerometer with the rotation sensor. Another problem I have encountered, is that the sensors are not calibrated all the same. To resolve this problem, I added 6 calibration properties (min and max values for each axis). The calibration properties in the example, are taken asking to the user to put the device in 3 different orientation. The drawback is that values are lost the next time the application run. A solution could be store those with QSettings as done in the OMCcam project.

Usage

Start copying horizon.cpp and horizon.h into your project source directory. In the main.cpp file include the .h:

#include "horizon.h"

then register the component:

qmlRegisterType<Horizon>("Horizon", 1, 0, "Horizon");

In you qml file you can now declare Horizon component:

Rectangle {
id: mainRect
Horizon {
id: horizon
anchors.fill: parent
clip: true
active: true
penWidth: 3
color: "black"
} // Horizon
}

active property will activate the accelerometer sensor to display the line on top of mainRect with a black color and a penWidth of 3 pixels.

959 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved