From efcd46144ac50d740297c2743d25b5c5380b02af Mon Sep 17 00:00:00 2001 From: MichaelBeeu Date: Sat, 21 Dec 2013 03:17:21 -0600 Subject: [PATCH] A little code clean-up, and clarification. --- zeal/progressitemdelegate.cpp | 15 ++++++++++----- zeal/progressitemdelegate.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/zeal/progressitemdelegate.cpp b/zeal/progressitemdelegate.cpp index 674e516..69df6c0 100644 --- a/zeal/progressitemdelegate.cpp +++ b/zeal/progressitemdelegate.cpp @@ -10,18 +10,21 @@ ProgressItemDelegate::ProgressItemDelegate(QObject *parent) : void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { + QStyleOptionViewItem tempOption = option; QVariant itemProgress = index.model()->data(index, ProgressRole); QVariant maxProgress = index.model()->data(index, ProgressMaxRole); - QVariant formatProgress = index.model()->data(index, ProgressFormatRole); QVariant visible = index.model()->data(index, ProgressVisibleRole); - QStyleOptionViewItem tempOption = option; - if( itemProgress.isValid() && maxProgress.isValid() && (visible.isValid() && visible.toBool()) ){ - tempOption.rect.setRight( tempOption.rect.right() - 150 ); + if( itemProgress.isValid() && maxProgress.isValid() && (visible.isValid() && visible.toBool()) ){ QProgressBar renderer; + QVariant formatProgress = index.model()->data(index, ProgressFormatRole); int progressAmnt = itemProgress.toInt(); - renderer.resize( QSize( 150, tempOption.rect.height() )); + // Adjust maximum text width + tempOption.rect.setRight( tempOption.rect.right() - progressBarWidth); + + // Size progress bar + renderer.resize( QSize( progressBarWidth, tempOption.rect.height() )); renderer.setMinimum(0); renderer.setMaximum( maxProgress.toInt() ); renderer.setValue( progressAmnt ); @@ -29,6 +32,7 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & renderer.setFormat( formatProgress.toString() ); } + // Paint progress bar painter->save(); QPoint rect = tempOption.rect.topRight(); painter->translate( rect ); @@ -36,6 +40,7 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & painter->restore(); } + // Paint text QItemDelegate::paint( painter, dynamic_cast(tempOption), index ); return; diff --git a/zeal/progressitemdelegate.h b/zeal/progressitemdelegate.h index 0e9cfee..9a4e61f 100644 --- a/zeal/progressitemdelegate.h +++ b/zeal/progressitemdelegate.h @@ -18,6 +18,8 @@ public: ProgressFormatRole = Qt::UserRole + 12, ProgressVisibleRole = Qt::UserRole + 13 }; +private: + static const int progressBarWidth = 150; signals: