Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 2.6
  2. import QtQuick.Controls.Nemo 1.0
  3.  
  4. Item{
  5.     id: timePicker
  6.     width: 400
  7.     height: width
  8.  
  9.     property date date: new Date();
  10.  
  11.     Rectangle{
  12.         anchors.fill: parent
  13.         color: "black"
  14.     }
  15.  
  16.     Canvas {
  17.         id: canvas
  18.         anchors.fill: parent
  19.         onPaint: {
  20.             var context = getContext("2d");
  21.  
  22.             var centerX = canvas.width / 2
  23.             var centerY = canvas.height / 2
  24.  
  25.             var hour_radius = canvas.width/2*0.8 - 1.5*Theme.itemHeightExtraSmall/4 - Theme.itemHeightExtraSmall/5/2
  26.             var hour_end_angle = getHourAngle()
  27.  
  28.             var minute_radius = canvas.width/2*0.8
  29.             var minute_end_angle = getMinuteAngle();
  30.  
  31. /*Draw hours */
  32.             context.beginPath();
  33.             context.arc(centerX, centerY, hour_radius, -0.5*Math.PI, hour_end_angle, false);
  34.             context.lineWidth = Theme.itemHeightExtraSmall/2;
  35.             context.strokeStyle = Theme.accentColor;
  36.             context.globalAlpha = 1;
  37.             context.stroke();
  38. /*Draw subhours if time AM*/
  39.             context.beginPath();
  40.             context.arc(centerX, centerY, hour_radius, 0, 2 * Math.PI, false);
  41.             context.lineWidth = Theme.itemHeightExtraSmall/2;
  42.             context.strokeStyle = Theme.accentColor;
  43.             context.globalAlpha = 0.5;
  44.             context.stroke();
  45. /*Draw minute*/
  46.             context.beginPath();
  47.             context.arc(centerX, centerY, minute_radius, -0.5*Math.PI, minute_end_angle, false);
  48.             context.lineWidth = Theme.itemHeightExtraSmall/5;
  49.             context.strokeStyle = Theme.accentColor;
  50.             context.globalAlpha = 0.5;
  51.             context.stroke();
  52.         }
  53.     }
  54.  
  55.     Label{
  56.         id: hourLabel
  57.         text: timePicker.date.getHours()
  58.         font.pixelSize: Theme.itemHeightExtraSmall/2
  59.         font.bold: true
  60.         x: canvas.width/2-hourLabel.contentWidth-Theme.itemHeightExtraSmall/10
  61.         y: canvas.height/2-(canvas.width/2*0.8 - 1.5*Theme.itemHeightExtraSmall/4 - Theme.itemHeightExtraSmall/5/2) - Theme.itemHeightExtraSmall/4
  62.     }
  63.  
  64.     Label{
  65.         id: minuteLabel
  66.         text: timePicker.date.getMinutes()
  67.         font.pixelSize: Theme.itemHeightExtraSmall/5
  68.         x: canvas.width/2-minuteLabel.contentWidth-Theme.itemHeightExtraSmall/10
  69.         y: canvas.width/2-canvas.width/2*0.8-Theme.itemHeightExtraSmall/5/2
  70.     }
  71.  
  72.     Component.onCompleted: console.log(date)
  73.  
  74.     function getHourAngle()
  75.     {
  76.         var hour = timePicker.date.getHours();
  77.         if(hour > 12)
  78.         {
  79.             hour = hour-12
  80.         }
  81.         return 2*Math.PI/12*hour-0.5*Math.PI;
  82.     }
  83.  
  84.     function getMinuteAngle()
  85.     {
  86.         var minute = timePicker.date.getMinutes()
  87.         return 2*Math.PI/60*minute-0.5*Math.PI;
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement