From 8d57bfb1aef3b71557bc408154ee028751fd688e Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 14 Jun 2021 19:09:53 +0200 Subject: First commit There was history before but now there is no more. --- util.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 util.js (limited to 'util.js') diff --git a/util.js b/util.js new file mode 100644 index 0000000..61f70e4 --- /dev/null +++ b/util.js @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: Unlicense + +// If text contains key, make it stand out; otherwise, append [key] to text. +function addShortcut(text, key) { + if (!key) + return text + else if (text.indexOf(key) < 0) + return `${text} [${key}]` + else + return text.replace(new RegExp('\(' + key + '\)'), '$1') +} + +// Set alpha value for color. +function alphize(color, alpha) { + return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha) +} + +// Return the last event in list with property not greater than value. +function find(list, property, value) { + var low = 0 + var high = list.count - 1 + while (low <= high) { + var mid = Math.floor((low + high) / 2) + if (list.get(mid)[property] <= value) + low = mid + 1 + else + high = mid - 1 + } + return low +} -- cgit v1.3