From 37f727ac0746fd85504aa46c1f023c09b3eff33a Mon Sep 17 00:00:00 2001 From: hibby Date: Fri, 16 Feb 2018 15:17:14 +0000 Subject: New upstream version 1.8.0+repack --- SampleDownloader/DirectoryDelegate.cpp | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 SampleDownloader/DirectoryDelegate.cpp (limited to 'SampleDownloader/DirectoryDelegate.cpp') diff --git a/SampleDownloader/DirectoryDelegate.cpp b/SampleDownloader/DirectoryDelegate.cpp new file mode 100644 index 00000000..f64e9870 --- /dev/null +++ b/SampleDownloader/DirectoryDelegate.cpp @@ -0,0 +1,44 @@ +#include "DirectoryDelegate.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +void DirectoryDelegate::paint (QPainter * painter, QStyleOptionViewItem const& option + , QModelIndex const& index) const +{ + if (1 == index.column ()) + { + QStyleOptionProgressBar progress_bar_option; + progress_bar_option.rect = option.rect; + progress_bar_option.state = QStyle::State_Enabled; + progress_bar_option.direction = QApplication::layoutDirection (); + progress_bar_option.fontMetrics = QApplication::fontMetrics (); + progress_bar_option.minimum = 0; + progress_bar_option.maximum = 100; + auto progress = index.data ().toLongLong (); + if (progress > 0) + { + auto percent = int (progress * 100 / index.data (Qt::UserRole).toLongLong ()); + progress_bar_option.progress = percent; + progress_bar_option.text = QString::number (percent) + '%'; + progress_bar_option.textVisible = true; + progress_bar_option.textAlignment = Qt::AlignCenter; + } + else + { + // not started + progress_bar_option.progress = -1; + } + QApplication::style ()->drawControl (QStyle::CE_ProgressBar, &progress_bar_option, painter); + } + else + { + QStyledItemDelegate::paint (painter, option, index); + } +} -- cgit v1.2.3