diff --git a/src/preview.ui b/src/preview.ui
index fa0d015ff..84e5fc248 100644
--- a/src/preview.ui
+++ b/src/preview.ui
@@ -51,15 +51,22 @@
- The following files support previewing, <br>please select one of them:
+ The following files support previewing, please select one of them:
Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft
+
+ true
+
-
-
+
+
+ true
+
+
-
diff --git a/src/previewlistdelegate.h b/src/previewlistdelegate.h
index 6315bf8c1..65db98865 100644
--- a/src/previewlistdelegate.h
+++ b/src/previewlistdelegate.h
@@ -36,11 +36,14 @@
#include
#include
#include
-#include
#include
#include "misc.h"
#include "previewselect.h"
+#ifdef Q_WS_WIN
+ #include
+#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:
diff --git a/src/previewselect.cpp b/src/previewselect.cpp
index 888653ae0..3d4eaa491 100644
--- a/src/previewselect.cpp
+++ b/src/previewselect.cpp
@@ -40,12 +40,14 @@
#include "previewlistdelegate.h"
#include "previewselect.h"
#include "fs_utils.h"
+#include "preferences.h"
PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h) {
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
+ Preferences pref;
// Preview list
- previewListModel = new QStandardItemModel(0, 3);
+ previewListModel = new QStandardItemModel(0, NB_COLUMNS);
previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name"));
previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
@@ -53,6 +55,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent)
listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(listDelegate);
previewList->header()->resizeSection(0, 200);
+ previewList->setAlternatingRowColors(pref.useAlternatingRowColors());
// Fill list in
std::vector fp;
h.file_progress(fp);
@@ -71,14 +74,15 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent)
indexes << i;
}
}
- previewList->selectionModel()->select(previewListModel->index(0, NAME), QItemSelectionModel::Select);
- previewList->selectionModel()->select(previewListModel->index(0, SIZE), QItemSelectionModel::Select);
- previewList->selectionModel()->select(previewListModel->index(0, PROGRESS), QItemSelectionModel::Select);
+
if (!previewListModel->rowCount()) {
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
close();
}
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString)));
+ previewListModel->sort(NAME);
+ previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
+
if (previewListModel->rowCount() == 1) {
qDebug("Torrent file only contains one file, no need to display selection dialog before preview");
// Only one file : no choice
diff --git a/src/previewselect.h b/src/previewselect.h
index 998f4aa91..2aed5e734 100644
--- a/src/previewselect.h
+++ b/src/previewselect.h
@@ -46,7 +46,7 @@ class PreviewSelect: public QDialog, private Ui::preview {
Q_OBJECT
public:
- enum PreviewColumn { NAME, SIZE, PROGRESS };
+ enum PreviewColumn { NAME, SIZE, PROGRESS, NB_COLUMNS };
public:
PreviewSelect(QWidget* parent, QTorrentHandle h);