Polish Preview window. Closes #908.

This commit is contained in:
sledgehammer999
2013-09-14 15:17:50 +03:00
parent 0f298397b3
commit e7c27c9b8b
4 changed files with 32 additions and 10 deletions

View File

@@ -36,11 +36,14 @@
#include <QStyleOptionViewItemV2>
#include <QModelIndex>
#include <QPainter>
#include <QProgressBar>
#include <QApplication>
#include "misc.h"
#include "previewselect.h"
#ifdef Q_WS_WIN
#include <QPlastiqueStyle>
#endif
class PreviewListDelegate: public QItemDelegate {
Q_OBJECT
@@ -59,16 +62,24 @@ class PreviewListDelegate: public QItemDelegate {
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
break;
case PreviewSelect::PROGRESS:{
qreal progress = index.data().toDouble()*100.;
QStyleOptionProgressBarV2 newopt;
qreal progress = index.data().toDouble()*100.;
newopt.rect = opt.rect;
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
newopt.text = QString::number((int)(progress*10)/10.0, 'f', 1)+"%";
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true;
#ifndef Q_WS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else
// XXX: To avoid having the progress text on the right of the bar
QPlastiqueStyle st;
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif
break;
}
default: