| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
.pragma library |
| 27 |
|
| 28 |
|
| 29 |
var orange = "#DD4814" |
| 30 |
var canonicalAubergine = "#772953" |
| 31 |
var lightAubergine = "#77216F" |
| 32 |
var mediumAubergine = "#5E2750" |
| 33 |
var darkAubergine = "#2C001E" |
| 34 |
var darkAubergineDesaturated = "#2c1625" |
| 35 |
var warmGrey = "#AEA79F" |
| 36 |
var coolGrey = "#333333" |
| 37 |
var MS_PER_HOUR = 1000 * 3600 |
| 38 |
|
| 39 |
|
| 40 |
function convertToCamelCase( name ) { |
| 41 |
var chunksArray = name.split('-') |
| 42 |
var camelName = '' |
| 43 |
for (var i=0; i<chunksArray.length; i++){ |
| 44 |
camelName = camelName + chunksArray[i].charAt(0).toUpperCase() + chunksArray[i].slice(1); |
| 45 |
} |
| 46 |
return camelName |
| 47 |
} |
| 48 |
|
| 49 |
function clamp(x, min, max) { |
| 50 |
return Math.max(Math.min(x, max), min) |
| 51 |
} |
| 52 |
|
| 53 |
function isLeftToRight() { |
| 54 |
return Qt.application.layoutDirection == Qt.LeftToRight |
| 55 |
} |
| 56 |
|
| 57 |
function isRightToLeft() { |
| 58 |
return Qt.application.layoutDirection == Qt.RightToLeft |
| 59 |
} |
| 60 |
|
| 61 |
function switchLeftRightKeys(key) { |
| 62 |
if (isRightToLeft()) { |
| 63 |
switch (key) { |
| 64 |
case Qt.Key_Right: |
| 65 |
return Qt.Key_Left |
| 66 |
case Qt.Key_Left: |
| 67 |
return Qt.Key_Right |
| 68 |
default: |
| 69 |
return key |
| 70 |
} |
| 71 |
} |
| 72 |
return key |
| 73 |
} |
| 74 |
|
| 75 |
function hashEmpty(hash) { |
| 76 |
for (var key in hash) return false; |
| 77 |
return true |
| 78 |
} |
| 79 |
|
| 80 |
function get_human_time_format(time_in_milliseconds) |
| 81 |
{ |
| 82 |
var date = new Date(time_in_milliseconds) |
| 83 |
|
| 84 |
if(date.getUTCHours() == 0) return "mm:ss" |
| 85 |
else return "hh:mm:ss" |
| 86 |
} |
| 87 |
|
| 88 |
function removeExt(uri) { |
| 89 |
return uri.substring(0, uri.lastIndexOf(".")) |
| 90 |
} |
| 91 |
|
| 92 |
function format_time(time_in_milliseconds, formatting) { |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
var zero = new Date(0) |
| 102 |
var offset = zero.getTimezoneOffset()*60*1000 |
| 103 |
var date = new Date(time_in_milliseconds+offset) |
| 104 |
|
| 105 |
return Qt.formatTime(date, formatting) |
| 106 |
} |
| 107 |
|
| 108 |
function fromIso8601(date) { |
| 109 |
var timestamp, struct, minutesOffset = 0; |
| 110 |
var numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ]; |
| 111 |
|
| 112 |
g |
| 113 |
ve |
| 114 |
|
| 115 |
m |
| 116 |
if ((struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(date))) { |
| 117 |
.UTC |
| 118 |
for (var i = 0, k; (k = numericKeys[i]); ++i) { |
| 119 |
struct[k] = +struct[k] || 0; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
struct[2] = (+struct[2] || 1) - 1; |
| 124 |
struct[3] = +struct[3] || 1; |
| 125 |
|
| 126 |
if (struct[8] !== 'Z' && struct[9] !== undefined) { |
| 127 |
minutesOffset = struct[10] * 60 + struct[11]; |
| 128 |
|
| 129 |
if (struct[9] === '+') { |
| 130 |
minutesOffset = 0 - minutesOffset; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
timestamp = Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]); |
| 135 |
return new Date(timestamp); |
| 136 |
} |
| 137 |
else return null; |
| 138 |
} |
| 139 |
|
| 140 |
function isSameDay(date1, date2) { |
| 141 |
return (date1.getFullYear() == date2.getFullYear() && |
| 142 |
date1.getMonth == date2.getMonth && |
| 143 |
date1.getDay() == date2.getDay()) |
| 144 |
} |
| 145 |
|
| 146 |
function pad(text, len, paddingChar) { |
| 147 |
var padding = "" |
| 148 |
for (var i = text.length; i < len; i++) padding += paddingChar |
| 149 |
return padding + text |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
function linearInterpolation(xa, xb, a, b, x) { |
| 154 |
return (clamp(x, xa, xb) - xa)/(xb - xa) * (b - a) + a |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
function segmentsLinearInterpolation(lx, ly, x) { |
| 159 |
|
| 160 |
var cxa, cxb, cya, cyb |
| 161 |
for (var i = 0, len = lx.length; i < len; i++) { |
| 162 |
cxa = lx[i] |
| 163 |
cya = ly[i] |
| 164 |
if (cxa <= x) { |
| 165 |
if (i >= len-1) return cya |
| 166 |
cxb = lx[i+1] |
| 167 |
if (x < cxb) { |
| 168 |
cyb = ly[i+1] |
| 169 |
return linearInterpolation(cxa, cxb, cya, cyb, x) |
| 170 |
} |
| 171 |
} else { |
| 172 |
return cya |
| 173 |
} |
| 174 |
} |
| 175 |
} |