diff options
| author | Timotej Lazar <timotej.lazar@araneo.si> | 2021-06-14 19:09:53 +0200 |
|---|---|---|
| committer | Timotej Lazar <timotej.lazar@araneo.si> | 2021-06-14 19:13:14 +0200 |
| commit | 8d57bfb1aef3b71557bc408154ee028751fd688e (patch) | |
| tree | 22ee6eaa22a3cfc7dfd4f938be16a6e28d7eaf1f /util.js | |
First commit
There was history before but now there is no more.
Diffstat (limited to 'util.js')
| -rw-r--r-- | util.js | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -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} [<b>${key}</b>]` + else + return text.replace(new RegExp('\(' + key + '\)'), '<b>$1</b>') +} + +// 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 +} |
