]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix width issues when un-maximizing Dolphin
authorFelix Ernst <fe.a.ernst@gmail.com>
Sat, 31 Jul 2021 15:01:52 +0000 (17:01 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 1 Aug 2021 21:57:23 +0000 (21:57 +0000)
Before this commit un-maximizing or to be more precise instantly
changing the size of the window by a large amount could potentially
change the width of the sidebars, the viewContainers and the window
itself to unexpected/undesired widths.

This happened because the spacing calculation is triggered when the
primary ViewContainer is resized but at this point in time some of
the other widgets, especially the secondary ViewContainer and the
navigatorsWidget have generally not been resized yet. Therefore the
width and spacing calculations are based on partly updated and
partly outdated values leading to wrong results.

This commit makes it so calculation of spacings is delayed until
all widths have been updated.

Yes, spacing probably should not have the power to resize the
window but unfortunately the spacing can not be set to be less
forceful when taking space because otherwise the UrlNavigators
will take all space they can get with their
QSizePolicy::MinimumExpanding.

BUG: 430521
FIXED-IN: 21.08

src/dolphinnavigatorswidgetaction.cpp
src/dolphinnavigatorswidgetaction.h

index d66125af6c40806899e1c04266d2fe065393ac68..4da5229ff8105b7d3f3ed05ba54937a0086c7179 100644 (file)
@@ -47,6 +47,7 @@ DolphinNavigatorsWidgetAction::DolphinNavigatorsWidgetAction(QWidget *parent) :
 
 void DolphinNavigatorsWidgetAction::adjustSpacing()
 {
+    m_previousWindowWidth = parentWidget()->window()->width();
     auto viewGeometries = m_viewGeometriesHelper.viewGeometries();
     const int widthOfSplitterPrimary = viewGeometries.globalXOfPrimary + viewGeometries.widthOfPrimary - viewGeometries.globalXOfNavigatorsWidget;
     const QList<int> splitterSizes = {widthOfSplitterPrimary,
@@ -310,7 +311,17 @@ DolphinNavigatorsWidgetAction::ViewGeometriesHelper::ViewGeometriesHelper
 bool DolphinNavigatorsWidgetAction::ViewGeometriesHelper::eventFilter(QObject *watched, QEvent *event)
 {
     if (event->type() == QEvent::Resize) {
-        m_navigatorsWidgetAction->adjustSpacing();
+        if (m_navigatorsWidgetAction->parentWidget()->window()->width() != m_navigatorsWidgetAction->m_previousWindowWidth) {
+            // The window is being resized which means not all widgets have gotten their new sizes yet.
+            // Let's wait a bit so the sizes of the navigatorsWidget and the viewContainers have all
+            // had a chance to be updated.
+            m_navigatorsWidgetAction->m_adjustSpacingTimer->start();
+        } else {
+            m_navigatorsWidgetAction->adjustSpacing();
+            // We could always use the m_adjustSpacingTimer instead of calling adjustSpacing() directly
+            // here but then the navigatorsWidget doesn't fluently align with the viewContainers when
+            // the DolphinTabPage::m_expandViewAnimation is animating.
+        }
         return false;
     }
     return QObject::eventFilter(watched, event);
index 6f5f8e7af671c2bd566e17170284ba15b6b46845..3f50728e93778c7e74eb3346b3cc31c26d424e5b 100644 (file)
@@ -216,6 +216,12 @@ private:
     };
 
     ViewGeometriesHelper m_viewGeometriesHelper;
+
+    /**
+     * Used to check if the window has been resized.
+     * @see ViewGeometriesHelper::eventFilter() for why this is needed.
+     */
+    int m_previousWindowWidth = -1;
 };
 
 #endif // DOLPHINNAVIGATORSWIDGETACTION_H