Commit 6d3f235f authored by David Redondo's avatar David Redondo 🏎 Committed by Nate Graham
Browse files

Move QMainWindow contentMargins setting to polish

Never mutate a widget while painting! This causes recursive repaints and makes
prorgams crash. There is a reason why const_casts are discouraged.
BUG:432246
FIXED-IN: 5.21


(cherry picked from commit 0deecb4d)
parent f6a9d492
......@@ -391,7 +391,13 @@ namespace Breeze
} else if ( qobject_cast<QMainWindow*> (widget) ) {
widget->setAttribute(Qt::WA_StyledBackground);
const QRect toolsAreaRect = _toolsAreaManager->toolsAreaRect(static_cast<QMainWindow*>(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<QDialog*> (widget) ) {
widget->setAttribute(Qt::WA_StyledBackground);
......
......@@ -53,25 +53,16 @@ namespace Breeze {
configUpdated();
}
QRect ToolsAreaManager::toolsAreaRect(const QMainWindow *window)
QRect ToolsAreaManager::toolsAreaRect(const QMainWindow *window) const
{
Q_ASSERT(window);
int itemHeight = window->menuWidget() ? window->menuWidget()->height() : 0;
for (auto item : _windows[const_cast<QMainWindow*>(window)]) {
for (auto item : _windows[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<QMainWindow*>(window);
win->setContentsMargins(0, 1, 0, 0);
} else {
auto win = const_cast<QMainWindow*>(window);
win->setContentsMargins(0, 0, 0, 0);
}
return QRect(0, 0, window->width(), itemHeight);
}
......
......@@ -31,7 +31,7 @@ namespace Breeze {
private:
Helper* _helper;
QHash<QMainWindow*,QVector<QPointer<QToolBar>>> _windows;
QHash<const QMainWindow*,QVector<QPointer<QToolBar>>> _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);
QRect toolsAreaRect(const QMainWindow *window) const;
bool hasHeaderColors();
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment