Chinaunix首页 | 论坛 | 博客
  • 博客访问: 276373
  • 博文数量: 28
  • 博客积分: 290
  • 博客等级: 二等列兵
  • 技术积分: 326
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-10 12:12
文章分类

全部博文(28)

文章存档

2020年(1)

2018年(1)

2017年(3)

2015年(7)

2014年(9)

2010年(3)

2006年(4)

我的朋友

分类: Android平台

2014-12-31 18:08:31

这是 MultiPointTouchArea 的示例

点击(此处)折叠或打开

  1. import QtQuick 2.0

  2. Rectangle {
  3.     id: main
  4.     color: "#11262B"
  5.     width: 800
  6.     height: 600

  7.     // Blocks shown when touch points exists
  8.     Column {
  9.         Repeater {
  10.             model: multiArea.maximumTouchPoints

  11.             Rectangle {
  12.                 width: multiArea.width
  13.                 height: multiArea.height / multiArea.maximumTouchPoints
  14.                 visible: multiArea.points.length > index
  15.                 onVisibleChanged: {
  16.                     color = Qt.rgba(Math.random(),
  17.                              Math.random(), Math.random(), 1);
  18.                 }
  19.                 opacity: 0.3
  20.             }
  21.         }
  22.     }

  23.     // Visual presentation of the touch points
  24.     Repeater {
  25.         id: touchBalls
  26.         model: multiArea.points

  27.         Item {
  28.             x: modelData.x
  29.             y: modelData.y

  30.             Rectangle {
  31.                 anchors.centerIn: parent
  32.                 color: "white"
  33.                 opacity: 0.1
  34.                 width: 1000 * modelData.pressure
  35.                 height: width
  36.                 radius: width / 2
  37.             }

  38.             Rectangle {
  39.                 anchors.centerIn: parent
  40.                 color: "#20cc2c"
  41.                 opacity: modelData.pressure * 10
  42.                 width: 100
  43.                 height: width
  44.                 radius: width / 2
  45.             }
  46.         }
  47.     }

  48.     // Text presentation of the touch points
  49.     Column {
  50.         spacing: 10

  51.         Repeater {
  52.             model: multiArea.points
  53.             Text {
  54.                 font.pointSize: 12
  55.                 color: "snow"
  56.                 text: "{ x: " + modelData.x + ", y: " + modelData.y +
  57.                       ", pressure: " + modelData.pressure + " }"
  58.             }
  59.         }
  60.     }

  61.     //
  62.     MultiPointTouchArea {
  63.         id: multiArea

  64.         property variant points: []
  65.         /*
  66.         [
  67.             {x: 300, y: 120, pressure: 0.6},
  68.             {x: 200, y: 420, pressure: 0.9}
  69.         ]
  70.         */

  71.         enabled: true
  72.         anchors.fill: parent

  73.         minimumTouchPoints: 1
  74.         maximumTouchPoints: 5

  75.         // Each of the event handlers have "touchPoints" available
  76.         //
  77.         onCanceled: {
  78.             console.log("multiArea onCanceled.")
  79.             points = touchPoints;
  80.         }
  81.         onGestureStarted: {
  82.             console.log("multiArea onGestureStarted.")
  83.             points = touchPoints;
  84.         }
  85.         onPressed: {
  86.             console.log("multiArea onPressed.")
  87.             points = touchPoints;
  88.         }
  89.         onReleased: {
  90.             console.log("multiArea onReleased.")
  91.             points = touchPoints;
  92.         }
  93.         onTouchUpdated: {
  94.             console.log("multiArea onTouchUpdated.")
  95.             points = touchPoints;
  96.         }
  97.         onUpdated: {
  98.             console.log("multiArea onUpdated.")
  99.             points = touchPoints;
  100.         }
  101.     }

  102. }

阅读(5189) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~