QML horizon component for camera apps
This article explains how to use QML horizon line component
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.
Start copying horizon.cpp and horizon.h into your project source directory. In the main.cpp file include the .h:
then register the component:
qmlRegisterType<Horizon>("Horizon", 1, 0, "Horizon");
In you qml file you can now declare Horizon component:
} // 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.