如何在QML应用中在触屏的时候感知触觉

我们在有些的时候,需要在触屏的时候感知到触觉。那么我们怎么在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})
                }
            }
        }
    }
}

这里我们使用了Haptics.play()来完成相应的功能。当我们触控“Press me”时,我们会感觉到屏幕的触动。当然这也依赖于我们在“系统设置”中的设置。我们也可以通过改变Haptics.play()其中的参数来完成不同时间长度及震动大小的触觉。




整个项目的源码在: https://github.com/liu-xiao-guo/haptics


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值