From 27b42322570852785a3050fdeaaf756f20a8e1d2 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Thu, 28 Jan 2021 13:04:08 -0500 Subject: [PATCH] Revert "Move QMainWindow contentMargins setting to polish" This reverts commit 0deecb4d57aef085b8eb0b8b24e916201bfa1f2c. This commit caused many regressions in regards to how the tools area handles changing toolbars at runtime, and doesn't even properly handle most cases where there are no changes after application initialisation, as you cannot assume the widget tree is fully complete at ::polish time. --- kstyle/breezestyle.cpp | 6 ------ kstyle/breezetoolsareamanager.cpp | 13 +++++++++++-- kstyle/breezetoolsareamanager.h | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 09caa672..66829b05 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -391,13 +391,7 @@ namespace Breeze } else if ( qobject_cast (widget) ) { widget->setAttribute(Qt::WA_StyledBackground); - const QRect toolsAreaRect = _toolsAreaManager->toolsAreaRect(static_cast(widget)); - if (toolsAreaRect.height() == 0 && !(widget->property(PropertyNames::noSeparator).toBool())) { - const QMargins margins = widget->contentsMargins(); - widget->setContentsMargins(margins.left(), qMax(margins.top(), 1), margins.right(), margins.bottom()); - } } - else if ( qobject_cast (widget) ) { widget->setAttribute(Qt::WA_StyledBackground); diff --git a/kstyle/breezetoolsareamanager.cpp b/kstyle/breezetoolsareamanager.cpp index 49aea63b..b480edaf 100644 --- a/kstyle/breezetoolsareamanager.cpp +++ b/kstyle/breezetoolsareamanager.cpp @@ -53,16 +53,25 @@ namespace Breeze { configUpdated(); } - QRect ToolsAreaManager::toolsAreaRect(const QMainWindow *window) const + QRect ToolsAreaManager::toolsAreaRect(const QMainWindow *window) { Q_ASSERT(window); int itemHeight = window->menuWidget() ? window->menuWidget()->height() : 0; - for (auto item : _windows[window]) { + for (auto item : _windows[const_cast(window)]) { if (!item.isNull() && item->isVisible() && window->toolBarArea(item) == Qt::TopToolBarArea) { itemHeight = qMax(item->mapTo(window, item->rect().bottomLeft()).y(), itemHeight); } } + + if (itemHeight == 0 && !(window->property(PropertyNames::noSeparator).toBool())) { + auto win = const_cast(window); + win->setContentsMargins(0, 1, 0, 0); + } else { + auto win = const_cast(window); + win->setContentsMargins(0, 0, 0, 0); + } + return QRect(0, 0, window->width(), itemHeight); } diff --git a/kstyle/breezetoolsareamanager.h b/kstyle/breezetoolsareamanager.h index c9530084..c3d64c8c 100644 --- a/kstyle/breezetoolsareamanager.h +++ b/kstyle/breezetoolsareamanager.h @@ -31,7 +31,7 @@ namespace Breeze { private: Helper* _helper; - QHash>> _windows; + QHash>> _windows; KSharedConfigPtr _config; KConfigWatcher::Ptr _watcher; QPalette _palette = QPalette(); @@ -57,7 +57,7 @@ namespace Breeze { void registerWidget(QWidget *widget); void unregisterWidget(QWidget *widget); - QRect toolsAreaRect(const QMainWindow *window) const; + QRect toolsAreaRect(const QMainWindow *window); bool hasHeaderColors(); };