diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 4444944b1..18e644921 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -57,7 +57,7 @@ #include "logger.h" #include "preferences.h" -Preferences* Preferences::m_instance = 0; +Preferences *Preferences::m_instance = 0; Preferences::Preferences() {} @@ -753,7 +753,8 @@ void Preferences::disableRecursiveDownload(bool disable) } #ifdef Q_OS_WIN -namespace { +namespace +{ enum REG_SEARCH_TYPE { USER, @@ -842,7 +843,7 @@ namespace { versions.sort(); bool found = false; - while(!found && !versions.empty()) { + while (!found && !versions.empty()) { const QString version = versions.takeLast() + "\\InstallPath"; LPWSTR lpSubkey = new WCHAR[version.size() + 1]; version.toWCharArray(lpSubkey); @@ -872,7 +873,6 @@ namespace { return path; } - } QString Preferences::getPythonPath() @@ -1163,7 +1163,7 @@ void Preferences::setMainLastDir(const QString &path) setValue("MainWindowLastDir", path); } -QSize Preferences::getPrefSize(const QSize& defaultSize) const +QSize Preferences::getPrefSize(const QSize &defaultSize) const { return value("Preferences/State/size", defaultSize).toSize(); } @@ -1393,7 +1393,7 @@ void Preferences::setTransHeaderState(const QByteArray &state) setValue("TransferList/qt5/HeaderState", state); } -//From old RssSettings class +// From old RssSettings class bool Preferences::isRSSWidgetEnabled() const { return value("GUI/RSSWidget/Enabled", false).toBool(); diff --git a/src/base/preferences.h b/src/base/preferences.h index fe021bc78..e7f2e53e8 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -90,7 +90,7 @@ class Preferences: public QObject const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; void setValue(const QString &key, const QVariant &value); - static Preferences* m_instance; + static Preferences *m_instance; signals: void changed(); @@ -98,7 +98,7 @@ signals: public: static void initInstance(); static void freeInstance(); - static Preferences* instance(); + static Preferences *instance(); // General options QString getLocale() const; @@ -328,7 +328,7 @@ public: int getToolbarTextPosition() const; void setToolbarTextPosition(const int position); - //From old RssSettings class + // From old RssSettings class bool isRSSWidgetEnabled() const; void setRSSWidgetVisible(const bool enabled); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index c17fee4b8..0b891d3c4 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -50,7 +50,7 @@ mainwindow.h messageboxraised.h optionsdlg.h previewlistdelegate.h -previewselect.h +previewselectdialog.h scanfoldersdelegate.h shutdownconfirmdlg.h speedlimitdlg.h @@ -93,7 +93,7 @@ loglistwidget.cpp mainwindow.cpp messageboxraised.cpp optionsdlg.cpp -previewselect.cpp +previewselectdialog.cpp scanfoldersdelegate.cpp shutdownconfirmdlg.cpp speedlimitdlg.cpp @@ -133,7 +133,7 @@ mainwindow.ui about.ui banlistoptions.ui cookiesdialog.ui -preview.ui +previewselectdialog.ui login.ui downloadfromurldlg.ui bandwidth_limit.ui diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 81233251e..581b05c97 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -21,7 +21,6 @@ HEADERS += \ $$PWD/statusbar.h \ $$PWD/speedlimitdlg.h \ $$PWD/about_imp.h \ - $$PWD/previewselect.h \ $$PWD/previewlistdelegate.h \ $$PWD/downloadfromurldlg.h \ $$PWD/trackerlogin.h \ @@ -62,6 +61,7 @@ HEADERS += \ $$PWD/rss/htmlbrowser.h \ $$PWD/fspathedit.h \ $$PWD/fspathedit_p.h \ + $$PWD/previewselectdialog.h \ SOURCES += \ $$PWD/mainwindow.cpp \ @@ -77,7 +77,6 @@ SOURCES += \ $$PWD/torrentcontenttreeview.cpp \ $$PWD/executionlog.cpp \ $$PWD/speedlimitdlg.cpp \ - $$PWD/previewselect.cpp \ $$PWD/guiiconprovider.cpp \ $$PWD/updownratiodlg.cpp \ $$PWD/loglistwidget.cpp \ @@ -114,7 +113,8 @@ SOURCES += \ $$PWD/rss/automatedrssdownloader.cpp \ $$PWD/rss/htmlbrowser.cpp \ $$PWD/fspathedit.cpp \ - $$PWD/fspathedit_p.cpp + $$PWD/fspathedit_p.cpp \ + $$PWD/previewselectdialog.cpp \ win32|macx { HEADERS += $$PWD/programupdater.h @@ -129,7 +129,7 @@ macx { FORMS += \ $$PWD/mainwindow.ui \ $$PWD/about.ui \ - $$PWD/preview.ui \ + $$PWD/previewselectdialog.ui \ $$PWD/login.ui \ $$PWD/downloadfromurldlg.ui \ $$PWD/bandwidth_limit.ui \ diff --git a/src/gui/previewlistdelegate.h b/src/gui/previewlistdelegate.h index 6dfb085ce..9efb1c387 100644 --- a/src/gui/previewlistdelegate.h +++ b/src/gui/previewlistdelegate.h @@ -39,7 +39,7 @@ #include #include "base/utils/misc.h" #include "base/utils/string.h" -#include "previewselect.h" +#include "previewselectdialog.h" #ifdef Q_OS_WIN #include @@ -58,11 +58,11 @@ class PreviewListDelegate: public QItemDelegate { QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); switch(index.column()) { - case PreviewSelect::SIZE: + case PreviewSelectDialog::SIZE: QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; - case PreviewSelect::PROGRESS:{ + case PreviewSelectDialog::PROGRESS:{ QStyleOptionProgressBar newopt; qreal progress = index.data().toDouble()*100.; newopt.rect = opt.rect; diff --git a/src/gui/previewselect.cpp b/src/gui/previewselectdialog.cpp similarity index 78% rename from src/gui/previewselect.cpp rename to src/gui/previewselectdialog.cpp index 763ebeacf..3bd55fd86 100644 --- a/src/gui/previewselect.cpp +++ b/src/gui/previewselectdialog.cpp @@ -26,7 +26,7 @@ * exception statement from your version. */ -#include "previewselect.h" +#include "previewselectdialog.h" #include #include @@ -40,15 +40,19 @@ #include "base/utils/misc.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) , m_torrent(torrent) + , m_storeDialogSize(SETTINGS_KEY("Dimension")) + , m_storeTreeHeaderState(SETTINGS_KEY("HeaderState")) { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); 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); Preferences *const pref = Preferences::instance(); @@ -69,7 +73,6 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t previewList->hideColumn(FILE_INDEX); m_listDelegate = new PreviewListDelegate(this); previewList->setItemDelegate(m_listDelegate); - previewList->header()->resizeSection(0, 200); previewList->setAlternatingRowColors(pref->useAlternatingRowColors()); // Fill list in QVector fp = torrent->filesProgress(); @@ -98,6 +101,9 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t previewList->header()->setSortIndicator(0, Qt::AscendingOrder); previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows); + // Restore dialog state + loadWindowState(); + if (m_previewListModel->rowCount() == 1) { qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); // 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_listDelegate; } - -void PreviewSelect::previewButtonClicked() +void PreviewSelectDialog::previewButtonClicked() { QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX); if (selectedIndexes.size() == 0) return; @@ -135,3 +142,36 @@ void PreviewSelect::previewButtonClicked() 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; + } +} diff --git a/src/gui/previewselect.h b/src/gui/previewselectdialog.h similarity index 76% rename from src/gui/previewselect.h rename to src/gui/previewselectdialog.h index 1a32cd114..4608ab707 100644 --- a/src/gui/previewselect.h +++ b/src/gui/previewselectdialog.h @@ -26,20 +26,21 @@ * exception statement from your version. */ -#ifndef PREVIEWSELECT_H -#define PREVIEWSELECT_H +#ifndef PREVIEWSELECTDIALOG_H +#define PREVIEWSELECTDIALOG_H #include #include #include "base/bittorrent/torrenthandle.h" -#include "ui_preview.h" +#include "base/settingvalue.h" +#include "ui_previewselectdialog.h" class QStandardItemModel; class PreviewListDelegate; -class PreviewSelect : public QDialog, private Ui::preview +class PreviewSelectDialog : public QDialog, private Ui::preview { Q_OBJECT @@ -54,19 +55,30 @@ public: NB_COLUMNS }; - PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const torrent); - ~PreviewSelect(); + PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent); + ~PreviewSelectDialog(); signals: void readyToPreviewFile(QString) const; +protected: + void showEvent(QShowEvent *event) override; + private slots: void previewButtonClicked(); private: + void loadWindowState(); + void saveWindowState(); + QStandardItemModel *m_previewListModel; PreviewListDelegate *m_listDelegate; BitTorrent::TorrentHandle *const m_torrent; + bool m_headerStateInitialized = false; + + // Settings + CachedSettingValue m_storeDialogSize; + CachedSettingValue m_storeTreeHeaderState; }; -#endif // PREVIEWSELECT_H +#endif // PREVIEWSELECTDIALOG_H diff --git a/src/gui/preview.ui b/src/gui/previewselectdialog.ui similarity index 100% rename from src/gui/preview.ui rename to src/gui/previewselectdialog.ui diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 84e919574..53f1913b3 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -54,7 +54,7 @@ #include "guiiconprovider.h" #include "mainwindow.h" #include "optionsdlg.h" -#include "previewselect.h" +#include "previewselectdialog.h" #include "speedlimitdlg.h" #include "torrentmodel.h" #include "transferlistdelegate.h" @@ -563,7 +563,7 @@ void TransferListWidget::previewSelectedTorrents() { foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { if (torrent->hasMetadata()) - new PreviewSelect(this, torrent); + new PreviewSelectDialog(this, torrent); } }