Guest User

Untitled

a guest
Feb 26th, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. import QtQuick 2.4
  2.  
  3. //https://dribbble.com/shots/1853526-Download
  4.  
  5. Rectangle {
  6. id: root;
  7.  
  8. property color bar_color : "#1B445D";
  9. property color bg_color : "#45B0F3";
  10. property color text_color : "#8696A5";
  11. property int step_index : 0;
  12. property int completed: 0;
  13. property int indicator_x: root.width/2;
  14. property int script : 0;
  15. property int duration : 0;
  16. property var start_callback : null;
  17. property var stop_callback : null;
  18.  
  19. width: 800;
  20. height: 600;
  21. color: bg_color;
  22.  
  23. function choose_script()
  24. {
  25. //if (script == 0) {
  26. sucess_script();
  27. //}
  28. //script++;
  29. }
  30.  
  31. function sucess_script()
  32. {
  33. var i = 0;
  34. var amount = [ 18, 10, 15, 57 ];//insert -1 to cause failure
  35. //var time = [ 100, 100, 100, 100 ]; //tests
  36. var time = [ 800, 1200, 500, 1200 ]; //ms
  37.  
  38. completed = 0;
  39. indicator_x = root.width/2;
  40. tilt.easing.overshoot = 1.0;
  41. indicator.x = Qt.binding(function() { return indicator_x - indicator.width/2; });
  42. text.color = text_color;
  43. text.text = Qt.binding(function() { return "%" + ((indicator.x - main_bar.x + indicator.width/2)/main_bar.width * 100).toFixed(0);});
  44. load_bar.width = Qt.binding(function() { return root.completed/100 * main_bar.width; });
  45. function step() {
  46. if (root.completed < 100) {
  47. if (amount[i] < 0) {
  48. failure();
  49. return;
  50. }
  51. root.duration = time[i];
  52. forward.step = amount[i];
  53.  
  54. forward.start();
  55. tilt.easing.overshoot = 9;//amount[i]/time[i]*400;
  56. tilt.to = -(amount[i]/2);
  57. //cap tilt angle to 15;
  58. if( tilt.to < -15 ) tilt.to = -15;
  59. tilt.start();
  60. }
  61. else {
  62. //Finish scesss script
  63. rotate_info.color = "green";
  64. rotate_info.text = "done";
  65. root.stop_callback = finish;
  66. load_bar.width = load_bar.width;
  67. rotate_info.start();
  68. }
  69. i++;
  70. }
  71.  
  72. function failure() {
  73. rotate_info.color = "red";
  74. rotate_info.text = "failed";
  75. root.stop_callback = finish;
  76. load_bar.width = load_bar.width;
  77. rotate_info.start();
  78. }
  79.  
  80. function finish() {
  81. reset.start();
  82. }
  83.  
  84. root.duration = 500;
  85. root.stop_callback = step;
  86. rewind.start();
  87. }
  88.  
  89.  
  90. Rectangle {
  91. id: main_bar;
  92. color: bar_color;
  93. width: root.width * 0.15;
  94. height: root.height * 0.2;
  95. radius: 5;
  96. anchors.horizontalCenter: parent.horizontalCenter;
  97. y: parent.height/2 - height/2;
  98.  
  99.  
  100. ParallelAnimation {
  101. id: into_loadbar;
  102. running: false;
  103. NumberAnimation { target: main_bar; property: "width"; to: root.width * 0.7; duration: 450;
  104. easing.type: Easing.OutBack;
  105. easing.overshoot: 4;
  106. }
  107. NumberAnimation { target: main_bar; property: "height"; to: 7; duration: 150; }
  108.  
  109. onStopped : {
  110.  
  111. }
  112. }
  113.  
  114. MouseArea {
  115. anchors.fill: parent;
  116. onClicked :{
  117. into_loadbar.start();
  118. indicator_shrink.start();
  119. mouse.accepted = true;
  120. }
  121. }
  122. }
  123.  
  124. Rectangle {
  125. id: load_bar;
  126. color: "white";
  127. x: main_bar.x;
  128. y: main_bar.y;
  129. height: main_bar.height;
  130. radius: 5;
  131. width: root.completed/100 * main_bar.width;
  132.  
  133. Behavior on width { NumberAnimation{ duration: forward.duration; easing.type: forward.easing.type; }}
  134. }
  135.  
  136. Canvas {
  137. id: arrow;
  138. contextType: "2d";
  139. anchors.top: indicator.bottom; anchors.topMargin: -height*0.22;
  140. anchors.horizontalCenter: indicator.horizontalCenter;
  141. width: root.width * 0.08;
  142. height: width;
  143. Path {
  144. id: tpath;
  145. startX: 0; startY: 0;
  146. PathLine { relativeX: arrow.width/2; relativeY: arrow.height/2; }
  147. PathLine { relativeX: arrow.width/2; relativeY: -arrow.height/2; }
  148. }
  149.  
  150. onPaint : {
  151. context.fillStyle = Qt.rgba(1.0, 1.0, 1.0);
  152. context.path = tpath;
  153. context.fill();
  154. }
  155. }
  156.  
  157. Rectangle {
  158. id: indicator;
  159. color: "white";
  160. width: root.width * 0.04;
  161. height: root.height * 0.08;
  162. radius: 5;
  163. x: indicator_x - width/2;
  164. y: root.height/2 - root.height * 0.05;
  165.  
  166. PropertyAnimation {
  167. id: tilt;
  168. target: indicator;
  169. property: "rotation";
  170. duration: root.duration/5;
  171. to: 0;
  172. easing.type: Easing.InOutBack;
  173. }
  174.  
  175. Timer {
  176. id: pause;
  177. interval: root.duration/5; running: false; repeat: false;
  178.  
  179. onRunningChanged : {
  180. if (running) {
  181. tilt.start();
  182. }
  183. }
  184.  
  185. onTriggered : {
  186. root.stop_callback();
  187. }
  188. }
  189.  
  190. ParallelAnimation {
  191. id: indicator_shrink;
  192. running: false;
  193. NumberAnimation { target: indicator; properties: "height"; to: root.height * 0.045; duration: 400 }
  194. NumberAnimation { target: indicator; properties: "width"; to: root.height * 0.08; duration: 400 }
  195. NumberAnimation {
  196. target: indicator;
  197. property: "y";
  198. to: root.height/2 - root.height * 0.06;//.235;
  199. duration: 300;
  200. easing.overshoot: 100.0;
  201. easing.type: Easing.OutBack;
  202. }
  203. NumberAnimation { target: arrow; properties: "width"; to: root.width * 0.02; duration: 50; }
  204. onStopped : choose_script();
  205. }
  206.  
  207. ParallelAnimation {
  208. id: reset;
  209. running: false;
  210. PathAnimation {
  211. target: indicator;
  212. duration: 680;
  213. easing.type: Easing.InCirc;
  214. path : Path {
  215. startX: indicator.x;
  216. startY: indicator.y;
  217. PathArc { x: (root.width/2 - root.width*0.02);
  218. y: (root.height/2 - root.height*0.05);
  219. direction: (indicator.x > root.width/2) ? PathArc.Counterclockwise : PathArc.Clockwise;
  220. radiusX: 150;
  221. radiusY: 350;
  222. }
  223. }
  224. }
  225. NumberAnimation { target: arrow; properties: "width"; to: root.width * 0.08; duration: 600; easing.type:Easing.InQuad; }
  226. NumberAnimation { target: arrow; properties: "opacity"; to: 1.0; duration: 500; }
  227.  
  228. NumberAnimation { target: indicator; properties: "width"; to: root.width * 0.04; duration: 400;}
  229. NumberAnimation { target: indicator; properties: "height"; to: root.height * 0.08; duration: 400;}
  230.  
  231. NumberAnimation { target: main_bar; properties: "width"; to: root.width * 0.15; duration: 700;
  232. easing.type: Easing.OutQuint;
  233. }
  234. NumberAnimation { target: main_bar; properties: "height"; to: root.height * 0.2; duration : 700;
  235. easing.type: Easing.OutQuint;
  236. }
  237. onStarted: {
  238. root.duration = 100;
  239. root.completed = 0;
  240. }
  241. }
  242.  
  243. SequentialAnimation {
  244. id: rotate_info;
  245. running: false;
  246. property string text: ""
  247. property color color :"green";
  248. ParallelAnimation {
  249. ParallelAnimation {
  250. NumberAnimation { target: load_bar; property: "x"; to: indicator.x; duration: 300; }
  251. NumberAnimation { target: load_bar; property: "width"; to: 0; duration: 315; }
  252. }
  253. NumberAnimation { target: indicator; properties: "width"; to: 0;/*root.width * 0.03*/ duration: 300; }
  254. NumberAnimation { target: arrow; property: "width"; to: 1; duration: 300; }
  255. }
  256. ParallelAnimation {
  257. NumberAnimation { target: indicator; properties: "width"; to: root.height * 0.09; duration: 150; }
  258. NumberAnimation { target: arrow; property: "width"; to: root.width * 0.02; duration: 150; }
  259. }
  260. onStarted : {
  261. text.opacity = 0.0;
  262. }
  263.  
  264. onStopped : {
  265. text.opacity = 1.0;
  266. text.color = "green";
  267. text.text = "done"
  268. indicator.x = indicator.x;
  269. root.duration = 4000;
  270. pause.start();
  271. }
  272. }
  273.  
  274. Text {
  275. id: text;
  276. anchors.centerIn: parent;
  277. visible: (root.completed > 0);
  278. text: "%" + ((indicator.x - main_bar.x + indicator.width/2)/main_bar.width * 100).toFixed(0);
  279. rotation: indicator.rotation;
  280. font.pixelSize: parent.height * 0.5;
  281. color: root.text_color;
  282.  
  283. Behavior on opacity { NumberAnimation{ duration: 100; } }
  284. }
  285. }
  286.  
  287. PropertyAnimation {
  288. id: rewind;
  289. target: root;
  290. property: "indicator_x";
  291. to: main_bar.x;
  292. easing.type: Easing.InOutQuad;
  293.  
  294. onStarted : {
  295. tilt.to = 10;
  296. tilt.start();
  297. }
  298.  
  299. onStopped : {
  300. root.duration = 500;
  301. tilt.to = 0;
  302. pause.start();
  303. }
  304. }
  305.  
  306. PropertyAnimation {
  307. id: forward;
  308. target: root;
  309. property: "indicator_x";
  310. property int step: 0;
  311. to: main_bar.x + (root.completed + step) * main_bar.width/100;
  312. duration: root.duration;
  313. easing.type: Easing.Linear;
  314.  
  315. onStarted : {
  316. root.completed += step;
  317. }
  318.  
  319. onStopped : {
  320. tilt.to = 0;
  321. pause.start();
  322. }
  323. }
  324. }
Advertisement
Add Comment
Please, Sign In to add comment