mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 12:07:00 -04:00
Cleaner download control button drawing primitives
This commit is contained in:
parent
553568ddc8
commit
ec89f87d55
@ -24,13 +24,16 @@ ContentManagerDelegate::ContentManagerDelegate(QObject *parent)
|
|||||||
placeholderIconFile.save(&buffer, "png");
|
placeholderIconFile.save(&buffer, "png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void createPauseSymbol(QPainter *painter, int x, int y)
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
void createPauseSymbol(QPainter *painter, const QRect& buttonRect)
|
||||||
{
|
{
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidth(3);
|
pen.setWidth(3);
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
x += 12.5;
|
const int x = buttonRect.left() + 12.5;
|
||||||
y += 10;
|
const int y = buttonRect.top() + 10;
|
||||||
pen.setColor("#3366cc");
|
pen.setColor("#3366cc");
|
||||||
path.moveTo(x, y);
|
path.moveTo(x, y);
|
||||||
path.lineTo(x, y + 10);
|
path.lineTo(x, y + 10);
|
||||||
@ -40,13 +43,13 @@ void createPauseSymbol(QPainter *painter, int x, int y)
|
|||||||
painter->strokePath(path, pen);
|
painter->strokePath(path, pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createResumeSymbol(QPainter *painter, int x, int y)
|
void createResumeSymbol(QPainter *painter, const QRect& buttonRect)
|
||||||
{
|
{
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidth(3);
|
pen.setWidth(3);
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
x += 12.5;
|
const int x = buttonRect.left() + 12.5;
|
||||||
y += 8;
|
const int y = buttonRect.top() + 8;
|
||||||
pen.setColor("#3366cc");
|
pen.setColor("#3366cc");
|
||||||
path.moveTo(x, y);
|
path.moveTo(x, y);
|
||||||
path.lineTo(x, y + 15);
|
path.lineTo(x, y + 15);
|
||||||
@ -69,20 +72,18 @@ void createArc(QPainter *painter, int startAngle, int spanAngle, QRect rectangle
|
|||||||
painter->strokePath(path, pen);
|
painter->strokePath(path, pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createCancelSymbol(QPainter *painter, int x, int y, int w, int h)
|
void createCancelButton(QPainter *painter, const QRect& r)
|
||||||
{
|
{
|
||||||
QPen p;
|
QPen p;
|
||||||
p.setWidth(3);
|
p.setWidth(3);
|
||||||
p.setColor("#dd3333");
|
p.setColor("#dd3333");
|
||||||
QRect r(x, y, w, h);
|
|
||||||
createArc(painter, 0, 360, r, p);
|
createArc(painter, 0, 360, r, p);
|
||||||
painter->setPen(p);
|
painter->setPen(p);
|
||||||
QRect nRect(x, y, w, h);
|
|
||||||
auto oldFont = painter->font();
|
auto oldFont = painter->font();
|
||||||
auto bFont = oldFont;
|
auto bFont = oldFont;
|
||||||
bFont.setBold(true);
|
bFont.setBold(true);
|
||||||
painter->setFont(bFont);
|
painter->setFont(bFont);
|
||||||
painter->drawText(nRect, Qt::AlignCenter | Qt::AlignJustify, "X");
|
painter->drawText(r, Qt::AlignCenter | Qt::AlignJustify, "X");
|
||||||
painter->setFont(oldFont);
|
painter->setFont(oldFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,18 +107,16 @@ void createDownloadStats(QPainter *painter, QRect box, QString downloadSpeed, QS
|
|||||||
|
|
||||||
void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& downloadInfo)
|
void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& downloadInfo)
|
||||||
{
|
{
|
||||||
int x,y,w,h;
|
const int x = box.left();
|
||||||
x = box.left();
|
const int y = box.top();
|
||||||
y = box.top();
|
const int w = box.width();
|
||||||
w = box.width();
|
const int h = box.height();
|
||||||
h = box.height();
|
|
||||||
|
|
||||||
int arcX = x + w/2 + 20;
|
const int buttonW = w - 90;
|
||||||
int arcY = y + 20;
|
const int buttonH = h - 40;
|
||||||
int arcW = w - 90;
|
|
||||||
int arcH = h - 40;
|
|
||||||
|
|
||||||
QRect pauseResumeButtonRect(arcX, arcY, arcW, arcH);
|
QRect pauseResumeButtonRect(x + w/2 + 20, y + 20, buttonW, buttonH);
|
||||||
|
QRect cancelButtonRect (x + w/2 - 20, y + 20, buttonW, buttonH);
|
||||||
|
|
||||||
double progress = (double) (downloadInfo.progress) / 100;
|
double progress = (double) (downloadInfo.progress) / 100;
|
||||||
progress = -progress;
|
progress = -progress;
|
||||||
@ -125,10 +124,10 @@ void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& dow
|
|||||||
auto downloadSpeed = downloadInfo.downloadSpeed;
|
auto downloadSpeed = downloadInfo.downloadSpeed;
|
||||||
|
|
||||||
if (downloadInfo.paused) {
|
if (downloadInfo.paused) {
|
||||||
createResumeSymbol(painter, arcX, arcY);
|
createResumeSymbol(painter, pauseResumeButtonRect);
|
||||||
createCancelSymbol(painter, x + w/2 - 20, arcY, arcW, arcH);
|
createCancelButton(painter, cancelButtonRect);
|
||||||
} else {
|
} else {
|
||||||
createPauseSymbol(painter, arcX, arcY);
|
createPauseSymbol(painter, pauseResumeButtonRect);
|
||||||
createDownloadStats(painter, box, downloadSpeed, completedLength);
|
createDownloadStats(painter, box, downloadSpeed, completedLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +145,8 @@ void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& dow
|
|||||||
createArc(painter, startAngle, spanAngle, pauseResumeButtonRect, pen);
|
createArc(painter, startAngle, spanAngle, pauseResumeButtonRect, pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
void ContentManagerDelegate::paintButton(QPainter *p, const QRect &r, QString t) const
|
void ContentManagerDelegate::paintButton(QPainter *p, const QRect &r, QString t) const
|
||||||
{
|
{
|
||||||
QStyleOptionButton button;
|
QStyleOptionButton button;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user