Skip to content

Commit

Permalink
Merge pull request FreeCAD#15652 from kadet1090/ui-fixes
Browse files Browse the repository at this point in the history
Gui: Cosmetic Fixes
  • Loading branch information
chennes authored Jul 29, 2024
2 parents 233fcd1 + d927cfc commit fe70234
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 587 deletions.
21 changes: 18 additions & 3 deletions src/Gui/DlgPreferencesImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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()
Expand Down
46 changes: 19 additions & 27 deletions src/Gui/PreferencePages/DlgSettingsNavigation.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>516</width>
<height>687</height>
<width>548</width>
<height>762</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -65,7 +65,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>91</width>
<width>20</width>
<height>20</height>
</size>
</property>
Expand Down Expand Up @@ -217,6 +217,9 @@
<property name="toolTip">
<string>Opacity of the navigation cube when not focused</string>
</property>
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="minimum">
<number>1</number>
</property>
Expand All @@ -226,9 +229,6 @@
<property name="value">
<number>50</number>
</property>
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>InactiveOpacity</cstring>
</property>
Expand All @@ -249,7 +249,7 @@
<property name="toolTip">
<string>Base color for all elements</string>
</property>
<property name="color">
<property name="color" stdset="0">
<color alpha="128">
<red>226</red>
<green>232</green>
Expand Down Expand Up @@ -305,16 +305,16 @@
<number>1</number>
</property>
<property name="minimum">
<double>1.0</double>
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>100.0</double>
<double>100.000000000000000</double>
</property>
<property name="singleStep">
<double>0.5</double>
<double>0.500000000000000</double>
</property>
<property name="value">
<double>5.0</double>
<double>5.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>RotationCenterSize</cstring>
Expand Down Expand Up @@ -566,19 +566,7 @@ Free Turntable: the part will be rotated around the z-axis.</string>
</widget>
</item>
<item row="4" column="2">
<widget class="PrefUnitSpinBox" name="qspinNewDocScale" native="true">
<property name="minimumSize">
<size>
<width>120</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<widget class="Gui::PrefUnitSpinBox" name="qspinNewDocScale">
<property name="toolTip">
<string>Sets camera zoom for new documents.
The value is the diameter of the sphere to fit on the screen.</string>
Expand Down Expand Up @@ -831,6 +819,11 @@ Mouse tilting is not disabled by this setting.</string>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
<customwidget>
<class>Gui::ColorButton</class>
<extends>QPushButton</extends>
Expand Down Expand Up @@ -862,10 +855,9 @@ Mouse tilting is not disabled by this setting.</string>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>PrefUnitSpinBox</class>
<extends>QWidget</extends>
<class>Gui::PrefUnitSpinBox</class>
<extends>Gui::QuantitySpinBox</extends>
<header>Gui/PrefWidgets.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
Expand Down
23 changes: 14 additions & 9 deletions src/Gui/PropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -155,22 +155,22 @@ 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();
}

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
Expand All @@ -191,7 +191,7 @@ void PreferenceUiForm::loadSettings()

void PreferenceUiForm::saveSettings()
{
if (!form)
if (!_form)
return;

// search for all pref widgets to save their settings
Expand All @@ -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*>();
Expand Down
8 changes: 7 additions & 1 deletion src/Gui/PropertyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class GuiExport PreferencePage : public QWidget

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;
Expand Down Expand Up @@ -102,6 +106,8 @@ class GuiExport PreferenceUiForm : public PreferencePage
void loadSettings() override;
void saveSettings() override;

QWidget* form();

protected:
void changeEvent(QEvent *e) override;

Expand All @@ -112,7 +118,7 @@ class GuiExport PreferenceUiForm : public PreferencePage
void savePrefWidgets();

private:
QWidget* form;
QWidget* _form;
};

/** Base class for custom pages.
Expand Down
16 changes: 10 additions & 6 deletions src/Gui/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ static bool isVisibilityIconEnabled() {
return TreeParams::getVisibilityIcon();
}

static bool isOnlyNameColumnDisplayed() {
return TreeParams::getHideInternalNames()
&& TreeParams::getHideColumn();
}

static bool isSelectionCheckBoxesEnabled() {
return TreeParams::getCheckBoxesSelection();
}
Expand Down Expand Up @@ -478,19 +483,18 @@ void TreeWidgetItemDelegate::paint(QPainter *painter,
auto tree = static_cast<TreeWidget*>(parent());
auto style = tree->style();

// If the second column is not shown, we'll trim the color background when
// If only the first column is shown, we'll trim the color background when
// rendering as transparent overlay.

bool trimBG = TreeParams::getHideColumn() || TreeParams::getHideInternalNames();
bool trimColumnSize = isOnlyNameColumnDisplayed();

if (index.column() == 0) {
if (tree->testAttribute(Qt::WA_NoSystemBackground)
&& (trimBG || (opt.backgroundBrush.style() == Qt::NoBrush
&& (trimColumnSize || (opt.backgroundBrush.style() == Qt::NoBrush
&& _TreeItemBackground.style() != Qt::NoBrush)))
{
QRect rect = calculateItemRect(option);

if (trimBG && opt.backgroundBrush.style() == Qt::NoBrush) {
if (trimColumnSize && opt.backgroundBrush.style() == Qt::NoBrush) {
painter->fillRect(rect, _TreeItemBackground);
} else if (!opt.state.testFlag(QStyle::State_Selected)) {
painter->fillRect(rect, _TreeItemBackground);
Expand Down Expand Up @@ -527,7 +531,7 @@ void TreeWidgetItemDelegate::initStyleOption(QStyleOptionViewItem *option,
);
}

if (TreeParams::getHideColumn()) {
if (isOnlyNameColumnDisplayed()) {
option->rect = calculateItemRect(*option);

// we need to extend this shape a bit, 3px on each side
Expand Down
17 changes: 7 additions & 10 deletions src/Mod/AddonManager/AddonManagerOptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
<x>0</x>
<y>0</y>
<width>757</width>
<height>621</height>
<height>783</height>
</rect>
</property>
<property name="windowTitle">
<string>Addon manager options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="Gui::PrefCheckBox" name="guiprefcheckboxcheckupdates">
<property name="toolTip">
Expand Down Expand Up @@ -298,12 +301,6 @@ installed addons will be checked for available updates</string>
</item>
<item>
<widget class="Gui::PrefLineEdit" name="guipreflineedituserproxy">
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="prefEntry" stdset="0">
<cstring>ProxyUrl</cstring>
</property>
Expand Down Expand Up @@ -332,15 +329,15 @@ installed addons will be checked for available updates</string>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The URL for the Addon Score data (see Addon Manager wiki page for formatting and hosting details).</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>AddonsScoreURL</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Addons</cstring>
</property>
<property name="toolTip">
<string>The URL for the Addon Score data (see Addon Manager wiki page for formatting and hosting details).</string>
</property>
</widget>
</item>
</layout>
Expand Down
11 changes: 1 addition & 10 deletions src/Mod/BIM/Resources/ui/preferences-ifc-export.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>9</number>
</property>
<item>
Expand Down
11 changes: 1 addition & 10 deletions src/Mod/BIM/Resources/ui/preferences-ifc.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>9</number>
</property>
<item>
Expand Down
Loading

0 comments on commit fe70234

Please sign in to comment.