2015-09-08 17:05:59 +02:00
|
|
|
#include "./progressbaritemdelegate.h"
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
#include "../network/download.h"
|
2015-09-08 17:05:59 +02:00
|
|
|
|
2015-04-22 19:32:04 +02:00
|
|
|
#include "../model/downloadmodel.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
ProgressBarItemDelegate::ProgressBarItemDelegate(QObject *parent)
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
void ProgressBarItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
// set up a QStyleOptionProgressBar to precisely mimic the
|
|
|
|
// environment of a progress bar.
|
|
|
|
QStyleOptionProgressBar progressBarOption;
|
|
|
|
progressBarOption.state = QStyle::State_Enabled;
|
|
|
|
progressBarOption.direction = QApplication::layoutDirection();
|
|
|
|
progressBarOption.rect = option.rect;
|
|
|
|
progressBarOption.textAlignment = Qt::AlignCenter;
|
|
|
|
progressBarOption.textVisible = true;
|
|
|
|
progressBarOption.progress = index.model()->data(index, DownloadModel::ProgressPercentageRole).toInt();
|
|
|
|
progressBarOption.minimum = 0;
|
|
|
|
progressBarOption.maximum = 100;
|
|
|
|
progressBarOption.text = index.model()->data(index, Qt::DisplayRole).toString();
|
|
|
|
// draw the progress bar onto the view.
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
|
|
|
|
}
|
2019-07-20 20:20:58 +02:00
|
|
|
} // namespace QtGui
|