Skip to content

Commit

Permalink
A little code clean-up, and clarification.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBeeu committed Dec 21, 2013
1 parent fdc9c59 commit efcd461
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions zeal/progressitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,37 @@ 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 );
if( formatProgress.isValid() ){
renderer.setFormat( formatProgress.toString() );
}

// Paint progress bar
painter->save();
QPoint rect = tempOption.rect.topRight();
painter->translate( rect );
renderer.render( painter );
painter->restore();
}

// Paint text
QItemDelegate::paint( painter, dynamic_cast<const QStyleOptionViewItem&>(tempOption), index );

return;
Expand Down
2 changes: 2 additions & 0 deletions zeal/progressitemdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ProgressItemDelegate : public QItemDelegate
ProgressFormatRole = Qt::UserRole + 12,
ProgressVisibleRole = Qt::UserRole + 13
};
private:
static const int progressBarWidth = 150;

signals:

Expand Down

0 comments on commit efcd461

Please sign in to comment.