mirror of
https://git.wownero.com/wowlet/wowlet.git
synced 2024-08-15 01:03:14 +00:00
133700160a
Co-Authored-By: tobtoht <thotbot@protonmail.com>
40 lines
No EOL
1.4 KiB
C++
40 lines
No EOL
1.4 KiB
C++
// SPDX-License-Identifier: BSD-3-Clause
|
|
// Copyright (c) 2020, The Monero Project.
|
|
|
|
#include "cssprogressdelegate.h"
|
|
|
|
#include <QApplication>
|
|
|
|
CCSProgressDelegate::CCSProgressDelegate(CCSModel *model, QWidget *parent)
|
|
: m_model(model)
|
|
, QStyledItemDelegate(parent)
|
|
{
|
|
|
|
}
|
|
|
|
void CCSProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
const QModelIndex &index) const {
|
|
|
|
if (index.column() != CCSModel::Progress) {
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
return;
|
|
}
|
|
|
|
QStyleOptionProgressBar progressBarOption;
|
|
progressBarOption.state = QStyle::State_Enabled;
|
|
progressBarOption.direction = QApplication::layoutDirection();
|
|
progressBarOption.rect = option.rect;
|
|
progressBarOption.fontMetrics = QApplication::fontMetrics();
|
|
progressBarOption.minimum = 0;
|
|
progressBarOption.maximum = 100;
|
|
progressBarOption.textAlignment = Qt::AlignCenter;
|
|
progressBarOption.textVisible = true;
|
|
|
|
QSharedPointer<CCSEntry> entry = m_model->entry(index.row());
|
|
auto target = QString("%1/%2 XMR").arg(entry->raised_amount).arg(entry->target_amount);
|
|
auto progress = (int)entry->percentage_funded;
|
|
progressBarOption.progress = progress < 0 ? 0 : progress;
|
|
progressBarOption.text = target;
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter); // Draw the progress bar onto the view.
|
|
} |