mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-26 15:43:49 +03:00
A little code clean-up, and clarification.
This commit is contained in:
parent
fdc9c5965b
commit
efcd46144a
@ -10,18 +10,21 @@ ProgressItemDelegate::ProgressItemDelegate(QObject *parent) :
|
|||||||
|
|
||||||
void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
QStyleOptionViewItem tempOption = option;
|
||||||
QVariant itemProgress = index.model()->data(index, ProgressRole);
|
QVariant itemProgress = index.model()->data(index, ProgressRole);
|
||||||
QVariant maxProgress = index.model()->data(index, ProgressMaxRole);
|
QVariant maxProgress = index.model()->data(index, ProgressMaxRole);
|
||||||
QVariant formatProgress = index.model()->data(index, ProgressFormatRole);
|
|
||||||
QVariant visible = index.model()->data(index, ProgressVisibleRole);
|
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;
|
QProgressBar renderer;
|
||||||
|
QVariant formatProgress = index.model()->data(index, ProgressFormatRole);
|
||||||
int progressAmnt = itemProgress.toInt();
|
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.setMinimum(0);
|
||||||
renderer.setMaximum( maxProgress.toInt() );
|
renderer.setMaximum( maxProgress.toInt() );
|
||||||
renderer.setValue( progressAmnt );
|
renderer.setValue( progressAmnt );
|
||||||
@ -29,6 +32,7 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||||||
renderer.setFormat( formatProgress.toString() );
|
renderer.setFormat( formatProgress.toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paint progress bar
|
||||||
painter->save();
|
painter->save();
|
||||||
QPoint rect = tempOption.rect.topRight();
|
QPoint rect = tempOption.rect.topRight();
|
||||||
painter->translate( rect );
|
painter->translate( rect );
|
||||||
@ -36,6 +40,7 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paint text
|
||||||
QItemDelegate::paint( painter, dynamic_cast<const QStyleOptionViewItem&>(tempOption), index );
|
QItemDelegate::paint( painter, dynamic_cast<const QStyleOptionViewItem&>(tempOption), index );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -18,6 +18,8 @@ public:
|
|||||||
ProgressFormatRole = Qt::UserRole + 12,
|
ProgressFormatRole = Qt::UserRole + 12,
|
||||||
ProgressVisibleRole = Qt::UserRole + 13
|
ProgressVisibleRole = Qt::UserRole + 13
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
|
static const int progressBarWidth = 150;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user