|
|
|
@ -26,49 +26,46 @@
@@ -26,49 +26,46 @@
|
|
|
|
|
* exception statement from your version. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "progressbardelegate.h" |
|
|
|
|
#include "progressbarpainter.h" |
|
|
|
|
|
|
|
|
|
#include <QApplication> |
|
|
|
|
#include <QModelIndex> |
|
|
|
|
#include <QPainter> |
|
|
|
|
#include <QPalette> |
|
|
|
|
#include <QStyleOptionProgressBar> |
|
|
|
|
#include <QStyleOptionViewItem> |
|
|
|
|
|
|
|
|
|
#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) |
|
|
|
|
#include <QProxyStyle> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
ProgressBarDelegate::ProgressBarDelegate(const int progressColumn, const int dataRole, QObject *parent) |
|
|
|
|
: QStyledItemDelegate {parent} |
|
|
|
|
, m_progressColumn {progressColumn} |
|
|
|
|
, m_dataRole {dataRole} |
|
|
|
|
ProgressBarPainter::ProgressBarPainter() |
|
|
|
|
{ |
|
|
|
|
#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) |
|
|
|
|
m_dummyProgressBar.setStyle(new QProxyStyle {"fusion"}); |
|
|
|
|
auto *fusionStyle = new QProxyStyle {"fusion"}; |
|
|
|
|
fusionStyle->setParent(&m_dummyProgressBar); |
|
|
|
|
m_dummyProgressBar.setStyle(fusionStyle); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ProgressBarDelegate::initProgressStyleOption(QStyleOptionProgressBar &option, const QModelIndex &index) const |
|
|
|
|
void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress) const |
|
|
|
|
{ |
|
|
|
|
option.text = index.data().toString(); |
|
|
|
|
option.progress = static_cast<int>(index.data(m_dataRole).toReal()); |
|
|
|
|
option.maximum = 100; |
|
|
|
|
option.minimum = 0; |
|
|
|
|
option.textVisible = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ProgressBarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
|
|
|
|
{ |
|
|
|
|
if (index.column() != m_progressColumn) |
|
|
|
|
return QStyledItemDelegate::paint(painter, option, index); |
|
|
|
|
QStyleOptionProgressBar styleOption; |
|
|
|
|
styleOption.initFrom(&m_dummyProgressBar); |
|
|
|
|
// QStyleOptionProgressBar fields
|
|
|
|
|
styleOption.maximum = 100; |
|
|
|
|
styleOption.minimum = 0; |
|
|
|
|
styleOption.progress = progress; |
|
|
|
|
styleOption.text = text; |
|
|
|
|
styleOption.textVisible = true; |
|
|
|
|
// QStyleOption fields
|
|
|
|
|
styleOption.rect = option.rect; |
|
|
|
|
styleOption.state = option.state; |
|
|
|
|
|
|
|
|
|
QStyleOptionProgressBar newopt; |
|
|
|
|
newopt.initFrom(&m_dummyProgressBar); |
|
|
|
|
newopt.rect = option.rect; |
|
|
|
|
newopt.state = option.state; |
|
|
|
|
initProgressStyleOption(newopt, index); |
|
|
|
|
const bool isEnabled = option.state.testFlag(QStyle::State_Enabled); |
|
|
|
|
styleOption.palette.setCurrentColorGroup(isEnabled ? QPalette::Active : QPalette::Disabled); |
|
|
|
|
|
|
|
|
|
painter->save(); |
|
|
|
|
m_dummyProgressBar.style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter); |
|
|
|
|
m_dummyProgressBar.style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter, &m_dummyProgressBar); |
|
|
|
|
const QStyle *style = m_dummyProgressBar.style(); |
|
|
|
|
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter); |
|
|
|
|
style->drawControl(QStyle::CE_ProgressBar, &styleOption, painter, &m_dummyProgressBar); |
|
|
|
|
painter->restore(); |
|
|
|
|
} |