mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-04 09:08:42 +00:00
Progress indicators
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
#include <QApplication>
|
||||
#include <QtCore/qmath.h>
|
||||
|
||||
#include "CategorizedView.h"
|
||||
|
||||
// Origin: Qt
|
||||
static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height,
|
||||
qreal &widthUsed)
|
||||
@@ -85,6 +87,26 @@ void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, cons
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
}
|
||||
|
||||
// TODO this can be made a lot prettier
|
||||
void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option, const int value, const int maximum)
|
||||
{
|
||||
if (maximum == 0 || value == maximum)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
|
||||
qreal percent = (qreal)value / (qreal)maximum;
|
||||
QColor color = option.palette.color(QPalette::Dark);
|
||||
color.setAlphaF(0.70f);
|
||||
painter->setBrush(color);
|
||||
painter->setPen(QPen(QBrush(), 0));
|
||||
painter->drawPie(option.rect, 90 * 16, -percent * 360 * 60);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
static QSize viewItemTextSize(const QStyleOptionViewItemV4 *option)
|
||||
{
|
||||
QStyle *style = option->widget ? option->widget->style() : QApplication::style();
|
||||
@@ -229,6 +251,9 @@ void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||
line.draw(painter, position);
|
||||
}
|
||||
|
||||
drawProgressOverlay(painter, opt, index.data(CategorizedViewRoles::ProgressValueRole).toInt(),
|
||||
index.data(CategorizedViewRoles::ProgressMaximumRole).toInt());
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user