2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2008 Christophe Dumez <chris@qbittorrent.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
31 window
.qBittorrent
??= {};
32 window
.qBittorrent
.ProgressBar
??= (() => {
33 const exports
= () => {
35 ProgressBar
: ProgressBar
40 const ProgressBar
= new Class({
41 initialize
: (value
, parameters
) => {
43 "id": "progressbar_" + (ProgressBars
++),
44 "value": [value
, 0].pick(),
47 "darkbg": "var(--color-background-blue)",
48 "darkfg": "var(--color-text-white)",
49 "lightbg": "var(--color-background-default)",
50 "lightfg": "var(--color-text-default)"
52 if (parameters
&& (typeOf(parameters
) === "object"))
53 Object
.append(vals
, parameters
);
56 const obj
= new Element("div", {
58 "class": "progressbar_wrapper",
60 "border": "1px solid var(--color-border-default)",
61 "box-sizing": "content-box",
63 "height": vals
.height
,
64 "position": "relative",
69 obj
.vals
.value
= [value
, 0].pick();
70 obj
.vals
.dark
= new Element("div", {
71 "id": vals
.id
+ "_dark",
72 "class": "progressbar_dark",
75 "height": vals
.height
,
76 "background": vals
.darkbg
,
77 "box-sizing": "content-box",
79 "position": "absolute",
80 "text-align": "center",
83 "line-height": vals
.height
86 obj
.vals
.light
= new Element("div", {
87 "id": vals
.id
+ "_light",
88 "class": "progressbar_light",
91 "height": vals
.height
,
92 "background": vals
.lightbg
,
93 "box-sizing": "content-box",
94 "color": vals
.lightfg
,
95 "position": "absolute",
96 "text-align": "center",
99 "line-height": vals
.height
102 obj
.appendChild(obj
.vals
.dark
);
103 obj
.appendChild(obj
.vals
.light
);
104 obj
.getValue
= ProgressBar_getValue
;
105 obj
.setValue
= ProgressBar_setValue
;
106 obj
.setWidth
= ProgressBar_setWidth
;
108 obj
.setValue(vals
.value
);
110 setTimeout(ProgressBar_checkForParent
, 0, obj
.id
);
115 function ProgressBar_getValue() {
116 return this.vals
.value
;
119 function ProgressBar_setValue(value
) {
120 value
= parseFloat(value
);
123 value
= Math
.min(Math
.max(value
, 0), 100);
124 this.vals
.value
= value
;
126 const displayedValue
= `${value.round(1).toFixed(1)}%`;
127 this.vals
.dark
.textContent
= displayedValue
;
128 this.vals
.light
.textContent
= displayedValue
;
130 const r
= parseInt((this.vals
.width
* (value
/ 100)), 10);
131 this.vals
.dark
.style
.clipPath
= `inset(0 calc(100% - ${r}px) 0 0)`;
132 this.vals
.light
.style
.clipPath
= `inset(0 0 0 ${r}px)`;
135 function ProgressBar_setWidth(value
) {
136 if (this.vals
.width
!== value
) {
137 this.vals
.width
= value
;
138 this.style
.width
= `${value}px`;
139 this.vals
.dark
.style
.width
= `${value}px`;
140 this.vals
.light
.style
.width
= `${value}px`;
141 this.setValue(this.vals
.value
);
145 const ProgressBar_checkForParent
= (id
) => {
150 return setTimeout(ProgressBar_checkForParent
, 100, id
);
151 obj
.style
.width
= "100%";
152 const w
= obj
.offsetWidth
;
153 obj
.vals
.dark
.style
.width
= `${w}px`;
154 obj
.vals
.light
.style
.width
= `${w}px`;
156 obj
.setValue(obj
.vals
.value
);
161 Object
.freeze(window
.qBittorrent
.ProgressBar
);