Guest User

Untitled

a guest
Apr 20th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 3.09 KB | None | 0 0
  1. import QtQuick 2.0
  2. import Sailfish.Silica 1.0
  3.  
  4. Item {
  5.     id: speechBubble
  6.     width: parent.width
  7.     height: words.text.length > 90 ? parent.height / 1.5 : parent.height / 2
  8.  
  9.     property string post: "I have nothing to say."
  10.     property alias _words: words
  11.     property QtObject target
  12.     property alias defaultButton: defaultBtn
  13.  
  14.     Image {
  15.         id: bubbleImage
  16.         source: "img/speech-bubble.png"
  17.         anchors.fill: parent
  18.         sourceSize.width: width
  19.         sourceSize.height: height
  20.         rotation: {
  21.             if (verticalFlip) return 180
  22.             else return 0
  23.         }
  24.         mirror: {
  25.             if (horizontalFlip) return true
  26.             else false
  27.         }
  28.     }
  29.  
  30.     Label {
  31.         id: words
  32.         anchors.horizontalCenter: parent.horizontalCenter
  33.         anchors.top: parent.top
  34.         anchors.topMargin: verticalFlip ? parent.height/2.45 :Theme.paddingLarge * 4  // roughly 3/4 is the bubble itself
  35.  
  36.         width: parent.width * 0.75
  37. //        height: bubbleImage.height * 2/8
  38.         text: post
  39.         wrapMode: Text.Wrap
  40.         truncationMode: TruncationMode.Fade
  41.         color: "black"
  42.     }
  43.  
  44.     Button {  // Why is that not clickable ?
  45.         id: defaultBtn
  46.         text: "Test"
  47.         anchors.top: words.bottom
  48.         anchors.topMargin: Theme.paddingMedium
  49.         anchors.horizontalCenter: parent.horizontalCenter
  50.         color: "black"
  51.         onClicked: {
  52.             console.debug("defaultBtn clicked")
  53.             words.text = "defaultBtn clicked"
  54.         }
  55.     }
  56.  
  57.     property bool horizontalFlip: {
  58.         if (rotationSensor.reading.orientation == 1 || rotationSensor.reading.orientation == 2) {
  59.             if (!verticalFlip) {
  60.                 if (target.x + (target.width/2) > parent.width / 2) return true
  61.                 else return false
  62.             }
  63.             else {
  64.                 if (target.x + (target.width/2) > parent.width / 2) return false
  65.                 else return true
  66.             }
  67.         }
  68.         else {
  69.             if (!verticalFlip) {
  70.                 if (target.y + (target.width/2) > parent.height / 2) return false
  71.                 else return true
  72.             }
  73.             else {
  74.                 if (target.y + (target.width/2) > parent.height / 2) return true
  75.                 else return false
  76.             }
  77.         }
  78.     }
  79.     property bool verticalFlip: {
  80.         if (rotationSensor.reading.orientation == 1 || rotationSensor.reading.orientation == 2) {
  81.             if (target.y - height > 0) return false
  82.             else return true
  83.         }
  84.         else
  85.         {
  86.             if (target.x - width/2 > 0) return false
  87.             else return true
  88.         }
  89.     }
  90.     y: {
  91.         if (rotationSensor.reading.orientation == 1 || rotationSensor.reading.orientation == 2) {
  92.             if (target.y - height > 0) return target.y - height
  93.             else return target.y + target.height
  94.         }
  95.         else
  96.         {
  97.             if (target.y - (height/1.12) > 0) return target.y - height
  98.             else return target.y + target.height
  99.         }
  100.     }
  101. }
Add Comment
Please, Sign In to add comment