Browse Source

Persist size and treeview header state in preview dialog

- renamed variable m_headerState
 - renamed PreviewSelect class to PreviewSelectDialog
 - renamed previewselect files to previewselectdialog
adaptive-webui-19844
silver 7 years ago
parent
commit
3b4fd35dde
No known key found for this signature in database
GPG Key ID: 7AF60D549724DEEF
  1. 14
      src/base/preferences.cpp
  2. 6
      src/base/preferences.h
  3. 6
      src/gui/CMakeLists.txt
  4. 8
      src/gui/gui.pri
  5. 6
      src/gui/previewlistdelegate.h
  6. 54
      src/gui/previewselectdialog.cpp
  7. 26
      src/gui/previewselectdialog.h
  8. 0
      src/gui/previewselectdialog.ui
  9. 4
      src/gui/transferlistwidget.cpp

14
src/base/preferences.cpp

@ -59,9 +59,7 @@
Preferences *Preferences::m_instance = 0; Preferences *Preferences::m_instance = 0;
Preferences::Preferences() Preferences::Preferences() {}
{
}
Preferences *Preferences::instance() Preferences *Preferences::instance()
{ {
@ -195,7 +193,6 @@ void Preferences::setCloseToTray(bool b)
{ {
setValue("Preferences/General/CloseToTray", b); setValue("Preferences/General/CloseToTray", b);
} }
#endif #endif
bool Preferences::isToolbarDisplayed() const bool Preferences::isToolbarDisplayed() const
@ -267,7 +264,6 @@ void Preferences::setWinStartup(bool b)
settings.remove("qBittorrent"); settings.remove("qBittorrent");
} }
} }
#endif #endif
// Downloads // Downloads
@ -744,7 +740,6 @@ void Preferences::useSystemIconTheme(bool enabled)
{ {
setValue("Preferences/Advanced/useSystemIconTheme", enabled); setValue("Preferences/Advanced/useSystemIconTheme", enabled);
} }
#endif #endif
bool Preferences::recursiveDownloadDisabled() const bool Preferences::recursiveDownloadDisabled() const
@ -983,7 +978,6 @@ void Preferences::setMagnetLinkAssoc(bool set)
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
} }
#endif #endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -1040,7 +1034,6 @@ void Preferences::setMagnetLinkAssoc()
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId); LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId);
} }
#endif #endif
int Preferences::getTrackerPort() const int Preferences::getTrackerPort() const
@ -1063,7 +1056,6 @@ void Preferences::setUpdateCheckEnabled(bool enabled)
{ {
setValue("Preferences/Advanced/updateCheck", enabled); setValue("Preferences/Advanced/updateCheck", enabled);
} }
#endif #endif
bool Preferences::confirmTorrentDeletion() const bool Preferences::confirmTorrentDeletion() const
@ -1106,7 +1098,6 @@ void Preferences::setTrayIconStyle(TrayIcon::Style style)
{ {
setValue("Preferences/Advanced/TrayIconStyle", style); setValue("Preferences/Advanced/TrayIconStyle", style);
} }
#endif #endif
// Stuff that don't appear in the Options GUI but are saved // Stuff that don't appear in the Options GUI but are saved
@ -1468,9 +1459,10 @@ void Preferences::upgrade()
QStringList labels = value("TransferListFilters/customLabels").toStringList(); QStringList labels = value("TransferListFilters/customLabels").toStringList();
if (!labels.isEmpty()) { if (!labels.isEmpty()) {
QVariantMap categories = value("BitTorrent/Session/Categories").toMap(); QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
foreach (const QString &label, labels) foreach (const QString &label, labels) {
if (!categories.contains(label)) if (!categories.contains(label))
categories[label] = ""; categories[label] = "";
}
setValue("BitTorrent/Session/Categories", categories); setValue("BitTorrent/Session/Categories", categories);
SettingsStorage::instance()->removeValue("TransferListFilters/customLabels"); SettingsStorage::instance()->removeValue("TransferListFilters/customLabels");
} }

6
src/base/preferences.h

@ -90,7 +90,7 @@ class Preferences: public QObject
const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
void setValue(const QString &key, const QVariant &value); void setValue(const QString &key, const QVariant &value);
static Preferences* m_instance; static Preferences *m_instance;
signals: signals:
void changed(); void changed();
@ -98,7 +98,7 @@ signals:
public: public:
static void initInstance(); static void initInstance();
static void freeInstance(); static void freeInstance();
static Preferences* instance(); static Preferences *instance();
// General options // General options
QString getLocale() const; QString getLocale() const;
@ -328,7 +328,7 @@ public:
int getToolbarTextPosition() const; int getToolbarTextPosition() const;
void setToolbarTextPosition(const int position); void setToolbarTextPosition(const int position);
//From old RssSettings class // From old RssSettings class
bool isRSSWidgetEnabled() const; bool isRSSWidgetEnabled() const;
void setRSSWidgetVisible(const bool enabled); void setRSSWidgetVisible(const bool enabled);

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