Browse Source

Merge pull request #7429 from silverqx/preview-modal-ux

Improved ux in preview dialog
adaptive-webui-19844
Mike Tzou 7 years ago committed by GitHub
parent
commit
e8250104c8
  1. 4
      src/base/preferences.cpp
  2. 6
      src/gui/CMakeLists.txt
  3. 8
      src/gui/gui.pri
  4. 6
      src/gui/previewlistdelegate.h
  5. 54
      src/gui/previewselectdialog.cpp
  6. 26
      src/gui/previewselectdialog.h
  7. 0
      src/gui/previewselectdialog.ui
  8. 4
      src/gui/transferlistwidget.cpp

4
src/base/preferences.cpp

@ -753,7 +753,8 @@ void Preferences::disableRecursiveDownload(bool disable)
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
namespace { namespace
{
enum REG_SEARCH_TYPE enum REG_SEARCH_TYPE
{ {
USER, USER,
@ -872,7 +873,6 @@ namespace {
return path; return path;
} }
} }
QString Preferences::getPythonPath() QString Preferences::getPythonPath()

6
src/gui/CMakeLists.txt

@ -50,7 +50,7 @@ mainwindow.h
messageboxraised.h messageboxraised.h
optionsdlg.h optionsdlg.h
previewlistdelegate.h previewlistdelegate.h
previewselect.h previewselectdialog.h
scanfoldersdelegate.h scanfoldersdelegate.h
shutdownconfirmdlg.h shutdownconfirmdlg.h
speedlimitdlg.h speedlimitdlg.h
@ -93,7 +93,7 @@ loglistwidget.cpp
mainwindow.cpp mainwindow.cpp
messageboxraised.cpp messageboxraised.cpp
optionsdlg.cpp optionsdlg.cpp
previewselect.cpp previewselectdialog.cpp
scanfoldersdelegate.cpp scanfoldersdelegate.cpp
shutdownconfirmdlg.cpp shutdownconfirmdlg.cpp
speedlimitdlg.cpp speedlimitdlg.cpp
@ -133,7 +133,7 @@ mainwindow.ui
about.ui about.ui
banlistoptions.ui banlistoptions.ui
cookiesdialog.ui cookiesdialog.ui
preview.ui previewselectdialog.ui
login.ui login.ui
downloadfromurldlg.ui downloadfromurldlg.ui
bandwidth_limit.ui bandwidth_limit.ui

8
src/gui/gui.pri

@ -21,7 +21,6 @@ HEADERS += \
$$PWD/statusbar.h \ $$PWD/statusbar.h \
$$PWD/speedlimitdlg.h \ $$PWD/speedlimitdlg.h \
$$PWD/about_imp.h \ $$PWD/about_imp.h \
$$PWD/previewselect.h \
$$PWD/previewlistdelegate.h \ $$PWD/previewlistdelegate.h \
$$PWD/downloadfromurldlg.h \ $$PWD/downloadfromurldlg.h \
$$PWD/trackerlogin.h \ $$PWD/trackerlogin.h \
@ -62,6 +61,7 @@ HEADERS += \
$$PWD/rss/htmlbrowser.h \ $$PWD/rss/htmlbrowser.h \
$$PWD/fspathedit.h \ $$PWD/fspathedit.h \
$$PWD/fspathedit_p.h \ $$PWD/fspathedit_p.h \
$$PWD/previewselectdialog.h \
SOURCES += \ SOURCES += \
$$PWD/mainwindow.cpp \ $$PWD/mainwindow.cpp \
@ -77,7 +77,6 @@ SOURCES += \
$$PWD/torrentcontenttreeview.cpp \ $$PWD/torrentcontenttreeview.cpp \
$$PWD/executionlog.cpp \ $$PWD/executionlog.cpp \
$$PWD/speedlimitdlg.cpp \ $$PWD/speedlimitdlg.cpp \
$$PWD/previewselect.cpp \
$$PWD/guiiconprovider.cpp \ $$PWD/guiiconprovider.cpp \
$$PWD/updownratiodlg.cpp \ $$PWD/updownratiodlg.cpp \
$$PWD/loglistwidget.cpp \ $$PWD/loglistwidget.cpp \
@ -114,7 +113,8 @@ SOURCES += \
$$PWD/rss/automatedrssdownloader.cpp \ $$PWD/rss/automatedrssdownloader.cpp \
$$PWD/rss/htmlbrowser.cpp \ $$PWD/rss/htmlbrowser.cpp \
$$PWD/fspathedit.cpp \ $$PWD/fspathedit.cpp \
$$PWD/fspathedit_p.cpp $$PWD/fspathedit_p.cpp \
$$PWD/previewselectdialog.cpp \
win32|macx { win32|macx {
HEADERS += $$PWD/programupdater.h HEADERS += $$PWD/programupdater.h
@ -129,7 +129,7 @@ macx {
FORMS += \ FORMS += \
$$PWD/mainwindow.ui \ $$PWD/mainwindow.ui \
$$PWD/about.ui \ $$PWD/about.ui \
$$PWD/preview.ui \ $$PWD/previewselectdialog.ui \
$$PWD/login.ui \ $$PWD/login.ui \
$$PWD/downloadfromurldlg.ui \ $$PWD/downloadfromurldlg.ui \
$$PWD/bandwidth_limit.ui \ $$PWD/bandwidth_limit.ui \

6
src/gui/previewlistdelegate.h

@ -39,7 +39,7 @@
#include <QApplication> #include <QApplication>
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "previewselect.h" #include "previewselectdialog.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QProxyStyle> #include <QProxyStyle>
@ -58,11 +58,11 @@ class PreviewListDelegate: public QItemDelegate {
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
switch(index.column()) { switch(index.column()) {
case PreviewSelect::SIZE: case PreviewSelectDialog::SIZE:
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break; break;
case PreviewSelect::PROGRESS:{ case PreviewSelectDialog::PROGRESS:{
QStyleOptionProgressBar newopt; QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble()*100.; qreal progress = index.data().toDouble()*100.;
newopt.rect = opt.rect; newopt.rect = opt.rect;

54
src/gui/previewselect.cpp → src/gui/previewselectdialog.cpp

@ -26,7 +26,7 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "previewselect.h" #include "previewselectdialog.h"
#include <QFile> #include <QFile>
#include <QHeaderView> #include <QHeaderView>
@ -40,15 +40,19 @@
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "previewlistdelegate.h" #include "previewlistdelegate.h"
PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const torrent) #define SETTINGS_KEY(name) "PreviewSelectDialog/" name
PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent)
: QDialog(parent) : QDialog(parent)
, m_torrent(torrent) , m_torrent(torrent)
, m_storeDialogSize(SETTINGS_KEY("Dimension"))
, m_storeTreeHeaderState(SETTINGS_KEY("HeaderState"))
{ {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview")); buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview"));
connect(buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelect::previewButtonClicked); connect(buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelectDialog::previewButtonClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
@ -69,7 +73,6 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t
previewList->hideColumn(FILE_INDEX); previewList->hideColumn(FILE_INDEX);
m_listDelegate = new PreviewListDelegate(this); m_listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(m_listDelegate); previewList->setItemDelegate(m_listDelegate);
previewList->header()->resizeSection(0, 200);
previewList->setAlternatingRowColors(pref->useAlternatingRowColors()); previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
// Fill list in // Fill list in
QVector<qreal> fp = torrent->filesProgress(); QVector<qreal> fp = torrent->filesProgress();
@ -98,6 +101,9 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t
previewList->header()->setSortIndicator(0, Qt::AscendingOrder); previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows); previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows);
// Restore dialog state
loadWindowState();
if (m_previewListModel->rowCount() == 1) { if (m_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
@ -109,14 +115,15 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t
} }
} }
PreviewSelect::~PreviewSelect() PreviewSelectDialog::~PreviewSelectDialog()
{ {
saveWindowState();
delete m_previewListModel; delete m_previewListModel;
delete m_listDelegate; delete m_listDelegate;
} }
void PreviewSelectDialog::previewButtonClicked()
void PreviewSelect::previewButtonClicked()
{ {
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX); QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX);
if (selectedIndexes.size() == 0) return; if (selectedIndexes.size() == 0) return;
@ -135,3 +142,36 @@ void PreviewSelect::previewButtonClicked()
accept(); accept();
} }
void PreviewSelectDialog::saveWindowState()
{
// Persist dialog size
m_storeDialogSize = this->size();
// Persist TreeView Header state
m_storeTreeHeaderState = previewList->header()->saveState();
}
void PreviewSelectDialog::loadWindowState()
{
// Restore dialog size
if (m_storeDialogSize.value().isValid()) {
resize(m_storeDialogSize);
}
// Restore TreeView Header state
if (!m_storeTreeHeaderState.value().isEmpty()) {
m_headerStateInitialized = previewList->header()->restoreState(m_storeTreeHeaderState);
}
}
void PreviewSelectDialog::showEvent(QShowEvent *event)
{
Q_UNUSED(event);
// Default size, have to be called after show(), because width is needed
// Set Name column width to 60% of TreeView
if (!m_headerStateInitialized) {
int nameSize = (previewList->size().width() * 0.6);
previewList->header()->resizeSection(0, nameSize);
m_headerStateInitialized = true;
}
}

26
src/gui/previewselect.h → src/gui/previewselectdialog.h

@ -26,20 +26,21 @@
* exception statement from your version. * exception statement from your version.
*/ */
#ifndef PREVIEWSELECT_H #ifndef PREVIEWSELECTDIALOG_H
#define PREVIEWSELECT_H #define PREVIEWSELECTDIALOG_H
#include <QDialog> #include <QDialog>
#include <QList> #include <QList>
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "ui_preview.h" #include "base/settingvalue.h"
#include "ui_previewselectdialog.h"
class QStandardItemModel; class QStandardItemModel;
class PreviewListDelegate; class PreviewListDelegate;
class PreviewSelect : public QDialog, private Ui::preview class PreviewSelectDialog : public QDialog, private Ui::preview
{ {
Q_OBJECT Q_OBJECT
@ -54,19 +55,30 @@ public:
NB_COLUMNS NB_COLUMNS
}; };
PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const torrent); PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent);
~PreviewSelect(); ~PreviewSelectDialog();
signals: signals:
void readyToPreviewFile(QString) const; void readyToPreviewFile(QString) const;
protected:
void showEvent(QShowEvent *event) override;
private slots: private slots:
void previewButtonClicked(); void previewButtonClicked();
private: private:
void loadWindowState();
void saveWindowState();
QStandardItemModel *m_previewListModel; QStandardItemModel *m_previewListModel;
PreviewListDelegate *m_listDelegate; PreviewListDelegate *m_listDelegate;
BitTorrent::TorrentHandle *const m_torrent; BitTorrent::TorrentHandle *const m_torrent;
bool m_headerStateInitialized = false;
// Settings
CachedSettingValue<QSize> m_storeDialogSize;
CachedSettingValue<QByteArray> m_storeTreeHeaderState;
}; };
#endif // PREVIEWSELECT_H #endif // PREVIEWSELECTDIALOG_H

0
src/gui/preview.ui → src/gui/previewselectdialog.ui

4
src/gui/transferlistwidget.cpp

@ -54,7 +54,7 @@
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "optionsdlg.h" #include "optionsdlg.h"
#include "previewselect.h" #include "previewselectdialog.h"
#include "speedlimitdlg.h" #include "speedlimitdlg.h"
#include "torrentmodel.h" #include "torrentmodel.h"
#include "transferlistdelegate.h" #include "transferlistdelegate.h"
@ -563,7 +563,7 @@ void TransferListWidget::previewSelectedTorrents()
{ {
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
if (torrent->hasMetadata()) if (torrent->hasMetadata())
new PreviewSelect(this, torrent); new PreviewSelectDialog(this, torrent);
} }
} }

Loading…
Cancel
Save