我们在有些的时候,需要在触屏的时候感知到触觉。那么我们怎么在QML应用是实现这个功能呢?
在Ubuntu 15.04的Ubuntu.Component 1.2模块中,我们有如下的一个API:
https://developer.ubuntu.com/api/apps/qml/sdk-15.04/Ubuntu.Components.Haptics/
具体的描述可以参阅相应的API文档。这里我们只简单地把我们的测试程序列出来:
import QtQuick 2.0 import Ubuntu.Components 1.2 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "haptics.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. // useDeprecatedToolbar: false width: units.gu(100) height: units.gu(75) Page { title: i18n.tr("Haptics") Column { Item { implicitWidth: units.gu(20) implicitHeight: units.gu(5) Label { text: "Press me" anchors.fill: parent horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } MouseArea { anchors.fill: parent onClicked: Haptics.play() } } Item { implicitWidth: units.gu(25) implicitHeight: units.gu(5) Label { text: "Press me again" anchors.fill: parent horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } MouseArea { anchors.fill: parent onClicked: Haptics.play({duration: 25, attackIntensity: 0.7}) } } } } }
整个项目的源码在: git clone https://gitcafe.com/ubuntu/haptics.git