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

6
src/base/preferences.h

@ -90,7 +90,7 @@ class Preferences: public QObject @@ -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: @@ -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: @@ -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);

6
src/gui/CMakeLists.txt

@ -50,7 +50,7 @@ mainwindow.h @@ -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 @@ -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 @@ -133,7 +133,7 @@ mainwindow.ui
about.ui
banlistoptions.ui
cookiesdialog.ui
preview.ui
previewselectdialog.ui
login.ui
downloadfromurldlg.ui
bandwidth_limit.ui

8
src/gui/gui.pri

@ -21,7 +21,6 @@ HEADERS += \ @@ -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 += \ @@ -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 += \ @@ -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 += \ @@ -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 { @@ -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 \

6
src/gui/previewlistdelegate.h

@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
#include <QApplication>
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "previewselect.h"
#include "previewselectdialog.h"
#ifdef Q_OS_WIN
#include <QProxyStyle>
@ -58,11 +58,11 @@ class PreviewListDelegate: public QItemDelegate { @@ -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;

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

@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
* exception statement from your version.
*/
#include "previewselect.h"
#include "previewselectdialog.h"
#include <QFile>
#include <QHeaderView>
@ -40,15 +40,19 @@ @@ -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 @@ -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<qreal> fp = torrent->filesProgress();
@ -98,6 +101,9 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t @@ -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 @@ -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() @@ -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;
}
}

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

@ -26,20 +26,21 @@ @@ -26,20 +26,21 @@
* exception statement from your version.
*/
#ifndef PREVIEWSELECT_H
#define PREVIEWSELECT_H
#ifndef PREVIEWSELECTDIALOG_H
#define PREVIEWSELECTDIALOG_H
#include <QDialog>
#include <QList>
#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: @@ -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<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 @@ @@ -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() @@ -563,7 +563,7 @@ void TransferListWidget::previewSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
if (torrent->hasMetadata())
new PreviewSelect(this, torrent);
new PreviewSelectDialog(this, torrent);
}
}

Loading…
Cancel
Save