Browse Source

Revise store/load state operations of Options Dialog

adaptive-webui-19844
Chocobo1 4 years ago
parent
commit
bdf1fb6db8
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 20
      src/base/preferences.cpp
  2. 4
      src/base/preferences.h
  3. 49
      src/gui/optionsdialog.cpp
  4. 14
      src/gui/optionsdialog.h

20
src/base/preferences.cpp

@ -1241,26 +1241,6 @@ void Preferences::setMainLastDir(const QString &path) @@ -1241,26 +1241,6 @@ void Preferences::setMainLastDir(const QString &path)
setValue("MainWindowLastDir", path);
}
QSize Preferences::getPrefSize() const
{
return value("Preferences/State/size").toSize();
}
void Preferences::setPrefSize(const QSize &size)
{
setValue("Preferences/State/size", size);
}
QStringList Preferences::getPrefHSplitterSizes() const
{
return value("Preferences/State/hSplitterSizes").toStringList();
}
void Preferences::setPrefHSplitterSizes(const QStringList &sizes)
{
setValue("Preferences/State/hSplitterSizes", sizes);
}
QByteArray Preferences::getPeerListState() const
{
return value("TorrentProperties/Peers/qt5/PeerListState").toByteArray();

4
src/base/preferences.h

@ -329,10 +329,6 @@ public: @@ -329,10 +329,6 @@ public:
void setMainVSplitterState(const QByteArray &state);
QString getMainLastDir() const;
void setMainLastDir(const QString &path);
QSize getPrefSize() const;
void setPrefSize(const QSize &size);
QStringList getPrefHSplitterSizes() const;
void setPrefHSplitterSizes(const QStringList &sizes);
QByteArray getPeerListState() const;
void setPeerListState(const QByteArray &state);
QString getPropSplitterSizes() const;

49
src/gui/optionsdialog.cpp

@ -68,6 +68,8 @@ @@ -68,6 +68,8 @@
#include "uithememanager.h"
#include "utils.h"
#define SETTINGS_KEY(name) "OptionsDialog/" name
namespace
{
QStringList translatedWeekdayNames()
@ -169,9 +171,10 @@ private: @@ -169,9 +171,10 @@ private:
// Constructor
OptionsDialog::OptionsDialog(QWidget *parent)
: QDialog(parent)
, m_refreshingIpFilter(false)
, m_ui(new Ui::OptionsDialog)
: QDialog {parent}
, m_ui {new Ui::OptionsDialog}
, m_storeDialogSize {SETTINGS_KEY("Size")}
, m_storeHSplitterSize {SETTINGS_KEY("HorizontalSplitterSizes")}
{
qDebug("-> Constructing Options");
m_ui->setupUi(this);
@ -565,7 +568,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -565,7 +568,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
for (QSpinBox *widget : asConst(findChildren<QSpinBox *>()))
widget->installEventFilter(wheelEventEater);
loadWindowState();
Utils::Gui::resize(this, m_storeDialogSize);
show();
// Have to be called after show(), because splitter width needed
loadSplitterState();
@ -606,7 +609,13 @@ OptionsDialog::~OptionsDialog() @@ -606,7 +609,13 @@ OptionsDialog::~OptionsDialog()
{
qDebug("-> destructing Options");
saveWindowState();
// save dialog states
m_storeDialogSize = size();
QStringList hSplitterSizes;
for (const int size : asConst(m_ui->hsplitter->sizes()))
hSplitterSizes.append(QString::number(size));
m_storeHSplitterSize = hSplitterSizes;
for (const QString &path : asConst(m_addedScanDirs))
ScanFoldersModel::instance()->removePath(path);
@ -621,38 +630,18 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo @@ -621,38 +630,18 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo
m_ui->tabOption->setCurrentIndex(m_ui->tabSelection->row(current));
}
void OptionsDialog::loadWindowState()
{
Utils::Gui::resize(this, Preferences::instance()->getPrefSize());
}
void OptionsDialog::loadSplitterState()
{
const QStringList sizesStr = Preferences::instance()->getPrefHSplitterSizes();
// width has been modified, use height as width reference instead
const int width = Utils::Gui::scaledSize(this
, (m_ui->tabSelection->item(TAB_UI)->sizeHint().height() * 2));
QList<int> sizes {width, (m_ui->hsplitter->width() - width)};
if (sizesStr.size() == 2)
sizes = {sizesStr.first().toInt(), sizesStr.last().toInt()};
m_ui->hsplitter->setSizes(sizes);
}
void OptionsDialog::saveWindowState() const
{
Preferences *const pref = Preferences::instance();
const QStringList defaultSizes = {QString::number(width), QString::number(m_ui->hsplitter->width() - width)};
// window size
pref->setPrefSize(size());
QList<int> splitterSizes;
for (const QString &string : asConst(m_storeHSplitterSize.get(defaultSizes)))
splitterSizes.append(string.toInt());
// Splitter size
const QStringList sizesStr =
{
QString::number(m_ui->hsplitter->sizes().first()),
QString::number(m_ui->hsplitter->sizes().last())
};
pref->setPrefHSplitterSizes(sizesStr);
m_ui->hsplitter->setSizes(splitterSizes);
}
void OptionsDialog::saveOptions()

14
src/gui/optionsdialog.h

@ -30,6 +30,8 @@ @@ -30,6 +30,8 @@
#include <QDialog>
#include "base/settingvalue.h"
class QAbstractButton;
class QCloseEvent;
class QListWidgetItem;
@ -58,6 +60,8 @@ namespace Ui @@ -58,6 +60,8 @@ namespace Ui
class OptionsDialog final : public QDialog
{
Q_OBJECT
Q_DISABLE_COPY(OptionsDialog)
using ThisType = OptionsDialog;
enum Tabs
@ -95,9 +99,7 @@ private slots: @@ -95,9 +99,7 @@ private slots:
void enableApplyButton();
void toggleComboRatioLimitAct();
void changePage(QListWidgetItem *, QListWidgetItem *);
void loadWindowState();
void loadSplitterState();
void saveWindowState() const;
void handleScanFolderViewSelectionChanged();
void on_IpFilterRefreshBtn_clicked();
void handleIPFilterParsed(bool error, int ruleCount);
@ -161,7 +163,6 @@ private: @@ -161,7 +163,6 @@ private:
// IP Filter
bool isIPFilteringEnabled() const;
QString getFilter() const;
bool m_refreshingIpFilter;
// Queueing system
bool isQueueingSystemEnabled() const;
int getMaxActiveDownloads() const;
@ -177,8 +178,15 @@ private: @@ -177,8 +178,15 @@ private:
bool schedTimesOk();
Ui::OptionsDialog *m_ui;
SettingValue<QSize> m_storeDialogSize;
SettingValue<QStringList> m_storeHSplitterSize;
QAbstractButton *m_applyButton;
AdvancedSettings *m_advancedSettings;
QList<QString> m_addedScanDirs;
QList<QString> m_removedScanDirs;
bool m_refreshingIpFilter = false;
};

Loading…
Cancel
Save