Advertisement
Guest User

Untitled

a guest
May 14th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.83 KB | None | 0 0
  1. import QtQuick 2.5
  2. import QtMultimedia 5.0
  3.  
  4. Item {
  5.     id: root
  6.     width: 800
  7.     height: 600
  8.  
  9.     property real pressX: 0
  10.     property real pressY: 0
  11.     property real releaseX: 0
  12.     property real releaseY: 0
  13.  
  14.     anchors.fill: parent
  15.     Rectangle {
  16.         id: rect
  17.         anchors.fill: parent
  18.         color: "black"
  19.  
  20.         MouseArea {
  21.             id: playArea
  22.             anchors.fill: parent
  23.             onPressed: {
  24.                 root.pressX = mouse.x
  25.                 root.pressY = mouse.y
  26.             }
  27.  
  28.             onReleased: {
  29.                 root.releaseX = mouse.x
  30.                 root.releaseY = mouse.y
  31.                 root.doSomething();
  32.             }
  33.         }
  34.     }
  35.  
  36.     Component {
  37.         id: highlightComponent;
  38.         Rectangle {
  39.             color: "transparent";
  40.             border.color: "black"
  41.             border.width: 2
  42.             property alias text:t1.text;
  43.             property alias ss: image.source;
  44.  
  45.             Text {
  46.                 id: t1
  47.                 text: "click"
  48.                 anchors.centerIn: parent
  49.                 width: 5
  50.             }
  51.  
  52.             Image {
  53.                 id:image
  54.                 anchors.centerIn: parent
  55.             }
  56.         }
  57.  
  58.     }
  59.     function doSomething(){
  60.         var direction_flag = 0
  61.         var dir;
  62.         if((pressX - releaseX) > 0){
  63.             dir= "images/left.png";
  64.         }else if((pressX - releaseX) < 0){
  65.             dir="images/right.png";
  66.         }
  67.         highlightComponent.incubateObject (
  68.                     rect, {
  69.                         "x" : pressX,
  70.                         "y":pressY,
  71.                         width:releaseX - pressX,
  72.                         height: releaseY - pressY,
  73.                         text:"Some text",
  74.                         ss:dir
  75.                     });
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement