Gui: Remove unnecessary scrollbars from Preferences
This commit is contained in:
@@ -287,9 +287,19 @@ PreferencePage* DlgPreferencesImp::createPreferencePage(const std::string& pageN
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto resetMargins = [](QWidget* widget) {
|
||||
widget->setContentsMargins(0, 0, 0, 0);
|
||||
widget->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
};
|
||||
|
||||
// settings layout already takes care for margins, we need to reset everything to 0
|
||||
page->setContentsMargins(0, 0, 0, 0);
|
||||
page->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
resetMargins(page);
|
||||
|
||||
// special handling for PreferenceUiForm to reset margins for forms too
|
||||
if (auto uiFormPage = qobject_cast<PreferenceUiForm*>(page)) {
|
||||
resetMargins(uiFormPage->form());
|
||||
}
|
||||
|
||||
page->setProperty(GroupNameProperty, QString::fromStdString(groupName));
|
||||
page->setProperty(PageNameProperty, QString::fromStdString(pageName));
|
||||
|
||||
@@ -352,15 +362,20 @@ int DlgPreferencesImp::minimumPageWidth() const
|
||||
|
||||
int DlgPreferencesImp::minimumDialogWidth(int pageWidth) const
|
||||
{
|
||||
// this is additional safety spacing to ensure that everything fits with scrollbar etc.
|
||||
const auto additionalMargin = style()->pixelMetric(QStyle::PM_ScrollBarExtent) + 8;
|
||||
|
||||
QSize size = ui->groupWidgetStack->sizeHint();
|
||||
|
||||
int diff = pageWidth - size.width();
|
||||
int dw = width();
|
||||
|
||||
if (diff > 0) {
|
||||
const int offset = 2;
|
||||
dw += diff + offset;
|
||||
}
|
||||
|
||||
return dw;
|
||||
return dw + additionalMargin;
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::updatePageDependentWidgets()
|
||||
|
||||
@@ -124,19 +124,19 @@ void PreferencePage::requireRestart()
|
||||
|
||||
PreferenceUiForm::PreferenceUiForm(const QString& fn, QWidget* parent)
|
||||
: PreferencePage(parent)
|
||||
, form(nullptr)
|
||||
, _form(nullptr)
|
||||
{
|
||||
auto loader = UiLoader::newInstance();
|
||||
loader->setWorkingDirectory(QFileInfo(fn).absolutePath());
|
||||
QFile file(fn);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
form = loader->load(&file, this);
|
||||
_form = loader->load(&file, this);
|
||||
}
|
||||
file.close();
|
||||
if (form) {
|
||||
this->setWindowTitle(form->windowTitle());
|
||||
if (_form) {
|
||||
this->setWindowTitle(_form->windowTitle());
|
||||
auto layout = new QVBoxLayout;
|
||||
layout->addWidget(form);
|
||||
layout->addWidget(_form);
|
||||
setLayout(layout);
|
||||
}
|
||||
else {
|
||||
@@ -155,7 +155,7 @@ void PreferenceUiForm::changeEvent(QEvent *e)
|
||||
template <typename PW>
|
||||
void PreferenceUiForm::loadPrefWidgets()
|
||||
{
|
||||
QList<PW> pw = form->findChildren<PW>();
|
||||
QList<PW> pw = _form->findChildren<PW>();
|
||||
for (typename QList<PW>::iterator it = pw.begin(); it != pw.end(); ++it)
|
||||
(*it)->onRestore();
|
||||
}
|
||||
@@ -163,14 +163,14 @@ void PreferenceUiForm::loadPrefWidgets()
|
||||
template <typename PW>
|
||||
void PreferenceUiForm::savePrefWidgets()
|
||||
{
|
||||
QList<PW> pw = form->findChildren<PW>();
|
||||
QList<PW> pw = _form->findChildren<PW>();
|
||||
for (typename QList<PW>::iterator it = pw.begin(); it != pw.end(); ++it)
|
||||
(*it)->onSave();
|
||||
}
|
||||
|
||||
void PreferenceUiForm::loadSettings()
|
||||
{
|
||||
if (!form)
|
||||
if (!_form)
|
||||
return;
|
||||
|
||||
// search for all pref widgets to restore their settings
|
||||
@@ -191,7 +191,7 @@ void PreferenceUiForm::loadSettings()
|
||||
|
||||
void PreferenceUiForm::saveSettings()
|
||||
{
|
||||
if (!form)
|
||||
if (!_form)
|
||||
return;
|
||||
|
||||
// search for all pref widgets to save their settings
|
||||
@@ -210,6 +210,11 @@ void PreferenceUiForm::saveSettings()
|
||||
savePrefWidgets<Gui::PrefQuantitySpinBox*>();
|
||||
}
|
||||
|
||||
QWidget* Gui::Dialog::PreferenceUiForm::form()
|
||||
{
|
||||
return _form;
|
||||
}
|
||||
|
||||
void PreferencePage::resetSettingsToDefaults()
|
||||
{
|
||||
auto prefs = this->findChildren<QObject*>();
|
||||
|
||||
@@ -75,6 +75,10 @@ public:
|
||||
|
||||
bool isRestartRequired() const;
|
||||
void requireRestart();
|
||||
|
||||
// this fixes issue with wordWrap on labels affecting size hints:
|
||||
// https://stackoverflow.com/questions/78276854/layout-ignoring-sizehints-when-qlabel-with-text-wrap-is-present
|
||||
bool hasHeightForWidth() const override { return false; }
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void loadSettings()=0;
|
||||
@@ -102,6 +106,8 @@ public:
|
||||
void loadSettings() override;
|
||||
void saveSettings() override;
|
||||
|
||||
QWidget* form();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e) override;
|
||||
|
||||
@@ -112,7 +118,7 @@ private:
|
||||
void savePrefWidgets();
|
||||
|
||||
private:
|
||||
QWidget* form;
|
||||
QWidget* _form;
|
||||
};
|
||||
|
||||
/** Base class for custom pages.
|
||||
|
||||
Reference in New Issue
Block a user