diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
| commit | 368f5331a7641772aa7e0cd1feea57d09a394a36 (patch) | |
| tree | b421ac60cc6eb726896ea268ea24e47fc4ce7c88 /SampleDownloader/DirectoryDelegate.cpp | |
| parent | 71c717edc92fa771c857b3c2e5ed65f523f68f90 (diff) | |
| parent | 37f727ac0746fd85504aa46c1f023c09b3eff33a (diff) | |
Update upstream source from tag 'upstream/1.8.0+repack'
Update to upstream version '1.8.0+repack'
with Debian dir a83ef78cb70a32d1211871fdc08f3ffa295e45a8
Diffstat (limited to 'SampleDownloader/DirectoryDelegate.cpp')
| -rw-r--r-- | SampleDownloader/DirectoryDelegate.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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 <QApplication> +#include <QVariant> +#include <QString> +#include <QStyle> +#include <QModelIndex> +#include <QPainter> +#include <QStyleOptionViewItem> +#include <QStyleOptionProgressBar> + +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); + } +} |
