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)
setValue("MainWindowLastDir", 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 QByteArray Preferences::getPeerListState() const
{ {
return value("TorrentProperties/Peers/qt5/PeerListState").toByteArray(); return value("TorrentProperties/Peers/qt5/PeerListState").toByteArray();

4
src/base/preferences.h

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

49
src/gui/optionsdialog.cpp

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

14
src/gui/optionsdialog.h

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

Loading…
Cancel
Save