Browse Source

Polish Preview window. Closes #908.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
e7c27c9b8b
  1. 11
      src/preview.ui
  2. 17
      src/previewlistdelegate.h
  3. 12
      src/previewselect.cpp
  4. 2
      src/previewselect.h

11
src/preview.ui

@ -51,15 +51,22 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>The following files support previewing, &lt;br&gt;please select one of them:</string> <string>The following files support previewing, please select one of them:</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set> <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property> </property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTreeView" name="previewList"/> <widget class="QTreeView" name="previewList">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">

17
src/previewlistdelegate.h

@ -36,11 +36,14 @@
#include <QStyleOptionViewItemV2> #include <QStyleOptionViewItemV2>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>
#include <QProgressBar>
#include <QApplication> #include <QApplication>
#include "misc.h" #include "misc.h"
#include "previewselect.h" #include "previewselect.h"
#ifdef Q_WS_WIN
#include <QPlastiqueStyle>
#endif
class PreviewListDelegate: public QItemDelegate { class PreviewListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT
@ -59,16 +62,24 @@ class PreviewListDelegate: public QItemDelegate {
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
break; break;
case PreviewSelect::PROGRESS:{ case PreviewSelect::PROGRESS:{
qreal progress = index.data().toDouble()*100.;
QStyleOptionProgressBarV2 newopt; QStyleOptionProgressBarV2 newopt;
qreal progress = index.data().toDouble()*100.;
newopt.rect = opt.rect; 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.progress = (int)progress;
newopt.maximum = 100; newopt.maximum = 100;
newopt.minimum = 0; newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled; newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true; newopt.textVisible = true;
#ifndef Q_WS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); 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; break;
} }
default: default:

12
src/previewselect.cpp

@ -40,12 +40,14 @@
#include "previewlistdelegate.h" #include "previewlistdelegate.h"
#include "previewselect.h" #include "previewselect.h"
#include "fs_utils.h" #include "fs_utils.h"
#include "preferences.h"
PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h) { PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h) {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
Preferences pref;
// Preview list // Preview list
previewListModel = new QStandardItemModel(0, 3); previewListModel = new QStandardItemModel(0, NB_COLUMNS);
previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name")); previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name"));
previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
@ -53,6 +55,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent)
listDelegate = new PreviewListDelegate(this); listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(listDelegate); previewList->setItemDelegate(listDelegate);
previewList->header()->resizeSection(0, 200); previewList->header()->resizeSection(0, 200);
previewList->setAlternatingRowColors(pref.useAlternatingRowColors());
// Fill list in // Fill list in
std::vector<libtorrent::size_type> fp; std::vector<libtorrent::size_type> fp;
h.file_progress(fp); h.file_progress(fp);
@ -71,14 +74,15 @@ PreviewSelect::PreviewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent)
indexes << i; 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()) { if (!previewListModel->rowCount()) {
QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file")); QMessageBox::critical(0, tr("Preview impossible"), tr("Sorry, we can't preview this file"));
close(); close();
} }
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString))); connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString)));
previewListModel->sort(NAME);
previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
if (previewListModel->rowCount() == 1) { if (previewListModel->rowCount() == 1) {
qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); qDebug("Torrent file only contains one file, no need to display selection dialog before preview");
// Only one file : no choice // Only one file : no choice

2
src/previewselect.h

@ -46,7 +46,7 @@ class PreviewSelect: public QDialog, private Ui::preview {
Q_OBJECT Q_OBJECT
public: public:
enum PreviewColumn { NAME, SIZE, PROGRESS }; enum PreviewColumn { NAME, SIZE, PROGRESS, NB_COLUMNS };
public: public:
PreviewSelect(QWidget* parent, QTorrentHandle h); PreviewSelect(QWidget* parent, QTorrentHandle h);

Loading…
Cancel
Save