mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Introduced DownloadControlLayout
This commit is contained in:
parent
ec89f87d55
commit
42d5e78dc0
@ -105,7 +105,13 @@ void createDownloadStats(QPainter *painter, QRect box, QString downloadSpeed, QS
|
|||||||
painter->setFont(oldFont);
|
painter->setFont(oldFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& downloadInfo)
|
struct DownloadControlLayout
|
||||||
|
{
|
||||||
|
QRect pauseResumeButtonRect;
|
||||||
|
QRect cancelButtonRect;
|
||||||
|
};
|
||||||
|
|
||||||
|
DownloadControlLayout getDownloadControlLayout(QRect box)
|
||||||
{
|
{
|
||||||
const int x = box.left();
|
const int x = box.left();
|
||||||
const int y = box.top();
|
const int y = box.top();
|
||||||
@ -115,19 +121,25 @@ void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& dow
|
|||||||
const int buttonW = w - 90;
|
const int buttonW = w - 90;
|
||||||
const int buttonH = h - 40;
|
const int buttonH = h - 40;
|
||||||
|
|
||||||
QRect pauseResumeButtonRect(x + w/2 + 20, y + 20, buttonW, buttonH);
|
DownloadControlLayout dcl;
|
||||||
QRect cancelButtonRect (x + w/2 - 20, y + 20, buttonW, buttonH);
|
dcl.pauseResumeButtonRect = QRect(x + w/2 + 20, y + 20, buttonW, buttonH);
|
||||||
|
dcl.cancelButtonRect = QRect(x + w/2 - 20, y + 20, buttonW, buttonH);
|
||||||
|
return dcl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& downloadInfo)
|
||||||
|
{
|
||||||
|
const DownloadControlLayout dcl = getDownloadControlLayout(box);
|
||||||
double progress = (double) (downloadInfo.progress) / 100;
|
double progress = (double) (downloadInfo.progress) / 100;
|
||||||
progress = -progress;
|
progress = -progress;
|
||||||
auto completedLength = downloadInfo.completedLength;
|
auto completedLength = downloadInfo.completedLength;
|
||||||
auto downloadSpeed = downloadInfo.downloadSpeed;
|
auto downloadSpeed = downloadInfo.downloadSpeed;
|
||||||
|
|
||||||
if (downloadInfo.paused) {
|
if (downloadInfo.paused) {
|
||||||
createResumeSymbol(painter, pauseResumeButtonRect);
|
createResumeSymbol(painter, dcl.pauseResumeButtonRect);
|
||||||
createCancelButton(painter, cancelButtonRect);
|
createCancelButton(painter, dcl.cancelButtonRect);
|
||||||
} else {
|
} else {
|
||||||
createPauseSymbol(painter, pauseResumeButtonRect);
|
createPauseSymbol(painter, dcl.pauseResumeButtonRect);
|
||||||
createDownloadStats(painter, box, downloadSpeed, completedLength);
|
createDownloadStats(painter, box, downloadSpeed, completedLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,12 +149,12 @@ void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& dow
|
|||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
pen.setColor("#eaecf0");
|
pen.setColor("#eaecf0");
|
||||||
createArc(painter, 0, 360, pauseResumeButtonRect, pen);
|
createArc(painter, 0, 360, dcl.pauseResumeButtonRect, pen);
|
||||||
|
|
||||||
int startAngle = 0;
|
int startAngle = 0;
|
||||||
int spanAngle = progress * 360;
|
int spanAngle = progress * 360;
|
||||||
pen.setColor("#3366cc");
|
pen.setColor("#3366cc");
|
||||||
createArc(painter, startAngle, spanAngle, pauseResumeButtonRect, pen);
|
createArc(painter, startAngle, spanAngle, dcl.pauseResumeButtonRect, pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user