Warning, /education/gcompris/external/qml-box2d/examples/monera/SpeciesInfo.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.0
0002 import Box2D 2.0
0003 import "../shared"
0004 
0005 PhysicsItem {
0006     id: speciesInfo
0007 
0008     property string speciesName: ""
0009     property alias descriptionText: descriptionText.text
0010     property alias photoUrl: image.source
0011     property bool expanded: false
0012     property real radius: 50
0013 
0014     signal selected()
0015 
0016         width: 100
0017         height: 100
0018 
0019     world: physicsWorld
0020     linearDamping: 0.3
0021     angularDamping: 0.2
0022         bodyType: Body.Dynamic
0023 
0024     fixtures: Circle {
0025         radius: speciesInfo.radius
0026         density: 0.2
0027         friction: 0.3
0028         restitution: 0.2
0029     }
0030 
0031     function toBinomialFormat(speciesName) {
0032         var subnames = speciesName.split(' ');
0033         if (subnames.length >= 2)
0034             return subnames[0] + ' <b>' + subnames[1] + '</b>';
0035         else
0036             return ""
0037     }
0038 
0039     Image {
0040         id: image
0041         anchors.centerIn: parent
0042         fillMode: Image.PreserveAspectFit
0043         height: parent.radius * 2
0044         width: parent.radius * 2
0045 
0046         MouseArea {
0047             anchors.fill: parent
0048             hoverEnabled: true
0049             rotation: -speciesInfo.rotation
0050 
0051             onEntered: {
0052                 var dx = mouseX - image.width / 2;
0053                 var dy = mouseY - image.height / 2;
0054                 var abs = Math.sqrt(dx * dx + dy * dy)
0055                 var point = Qt.point(speciesInfo.x, speciesInfo.y);
0056                 var force = Qt.point(-3 * dx / abs, -3 * dy / abs);
0057                 speciesInfo.body.applyLinearImpulse(force, point);
0058                 speciesInfo.angularVelocity = 0;
0059                 speciesInfo.selected();
0060             }
0061         }
0062     }
0063 
0064     Item {
0065         id: fixed
0066         anchors.centerIn: parent
0067         rotation: -parent.rotation
0068         width: 0
0069         height: 0
0070         Item {
0071             id: info
0072             anchors {
0073                 verticalCenter: parent.verticalCenter
0074                 left: parent.left
0075                 leftMargin: speciesInfo.radius + 10
0076             }
0077             height: speciesInfo.radius * 3
0078             width: height * 3
0079             transformOrigin: Item.Left
0080 
0081             Behavior on opacity { NumberAnimation { duration: 200 } }
0082             Behavior on scale { NumberAnimation { duration: 200 } }
0083 
0084             Rectangle {
0085                 anchors.fill: parent
0086                 color: "gray"
0087                 opacity: 0.2
0088                 radius: 10
0089             }
0090 
0091             Text {
0092                 id: speciesText
0093                 anchors {
0094                     top: parent.top
0095                     left: parent.left
0096                     right: parent.right
0097                     topMargin: 5
0098                     leftMargin: 20
0099                 }
0100                 color: "white"
0101                 font.pixelSize: 32
0102                 font.family: "Nokia Sans"
0103                 font.italic: true
0104 
0105                 text: toBinomialFormat(speciesName);
0106             }
0107 
0108             Text {
0109                 id: descriptionText
0110                 anchors {
0111                     top: speciesText.bottom
0112                     bottom: parent.bottom
0113                     left: parent.left
0114                     right: parent.right
0115                     topMargin: 10
0116                     leftMargin: 25
0117                     rightMargin: 25
0118                 }
0119                 font.pixelSize: 20
0120                 font.family: "Nokia Sans"
0121                 color: "white"
0122                 wrapMode: Text.WordWrap
0123             }
0124         }
0125     }
0126 
0127     states: [
0128         State {
0129             name: "expanded"
0130             when: expanded
0131             PropertyChanges {
0132                 target: info
0133                 opacity: 1.0
0134                 scale: 1.0
0135             }
0136         },
0137         State {
0138             name: "retracted"
0139             when: !expanded
0140             PropertyChanges {
0141                 target: info
0142                 opacity: 0.0
0143                 scale: 0.3
0144             }
0145         }
0146     ]
0147 }