diff --git a/kdevplatform/sublime/idealbuttonbarwidget.cpp b/kdevplatform/sublime/idealbuttonbarwidget.cpp --- a/kdevplatform/sublime/idealbuttonbarwidget.cpp +++ b/kdevplatform/sublime/idealbuttonbarwidget.cpp @@ -113,8 +113,6 @@ { QBoxLayout *statusLayout = new QBoxLayout(QBoxLayout::RightToLeft, this); statusLayout->setMargin(0); - statusLayout->setSpacing(IDEAL_LAYOUT_SPACING); - statusLayout->setContentsMargins(0, IDEAL_LAYOUT_MARGIN, 0, IDEAL_LAYOUT_MARGIN); IdealButtonBarLayout *l = new IdealButtonBarLayout(orientation()); statusLayout->addLayout(l); diff --git a/kdevplatform/sublime/ideallayout.h b/kdevplatform/sublime/ideallayout.h --- a/kdevplatform/sublime/ideallayout.h +++ b/kdevplatform/sublime/ideallayout.h @@ -26,9 +26,6 @@ #include "sublimedefs.h" -#define IDEAL_LAYOUT_MARGIN 0 -#define IDEAL_LAYOUT_SPACING 2 - namespace Sublime { class IdealButtonBarLayout: public QLayout @@ -67,6 +64,8 @@ int doHorizontalLayout(const QRect &rect, bool updateGeometry = true) const; + int buttonSpacing() const; + private: QList _items; Qt::Orientation _orientation; diff --git a/kdevplatform/sublime/ideallayout.cpp b/kdevplatform/sublime/ideallayout.cpp --- a/kdevplatform/sublime/ideallayout.cpp +++ b/kdevplatform/sublime/ideallayout.cpp @@ -22,19 +22,18 @@ #include "ideallayout.h" +#include +#include + using namespace Sublime; IdealButtonBarLayout::IdealButtonBarLayout(Qt::Orientation orientation, QWidget *parent) : QLayout(parent) , _orientation(orientation) , _height(0) { - if (orientation == Qt::Vertical) - setContentsMargins(IDEAL_LAYOUT_MARGIN, 0, IDEAL_LAYOUT_MARGIN, 0); - else - setContentsMargins(0, IDEAL_LAYOUT_MARGIN, 0, IDEAL_LAYOUT_MARGIN); - setSpacing(IDEAL_LAYOUT_SPACING); + setContentsMargins(0, 0, 0, 0); invalidate(); } @@ -93,6 +92,8 @@ QSize IdealButtonBarLayout::sizeHint() const { if (m_sizeHintDirty) { + const int buttonSpacing = this->buttonSpacing(); + int orientationSize = 0; int crossSize = 0; @@ -119,7 +120,7 @@ } else { - orientationSize += spacing(); + orientationSize += buttonSpacing; } orientationSize += orientationSizeHere; first = false; @@ -178,8 +179,17 @@ return _items.count(); } +int IdealButtonBarLayout::buttonSpacing() const +{ + auto pw = parentWidget(); + return pw ? pw->style()->pixelMetric(QStyle::PM_ToolBarItemSpacing) : 0; +} + + int IdealButtonBarLayout::doVerticalLayout(const QRect &rect, bool updateGeometry) const { + const int buttonSpacing = this->buttonSpacing(); + int l, t, r, b; getContentsMargins(&l, &t, &r, &b); int x = rect.x() + l; @@ -189,10 +199,10 @@ foreach (QLayoutItem *item, _items) { const QSize itemSizeHint = item->sizeHint(); if (y + itemSizeHint.height() + b > rect.height()) { - int newX = x + currentLineWidth + spacing(); + int newX = x + currentLineWidth + buttonSpacing; if (newX + itemSizeHint.width() + r <= rect.width()) { - x += currentLineWidth + spacing(); + x += currentLineWidth + buttonSpacing; y = rect.y() + t; } } @@ -202,7 +212,7 @@ currentLineWidth = qMax(currentLineWidth, itemSizeHint.width()); - y += itemSizeHint.height() + spacing(); + y += itemSizeHint.height() + buttonSpacing; } m_layoutDirty = updateGeometry; @@ -212,6 +222,8 @@ int IdealButtonBarLayout::doHorizontalLayout(const QRect &rect, bool updateGeometry) const { + const int buttonSpacing = this->buttonSpacing(); + int l, t, r, b; getContentsMargins(&l, &t, &r, &b); int x = rect.x() + l; @@ -223,7 +235,7 @@ if (x + itemSizeHint.width() + r > rect.width()) { // Run out of horizontal space. Try to move button to another // row. - int newY = y + currentLineHeight + spacing(); + int newY = y + currentLineHeight + buttonSpacing; if (newY + itemSizeHint.height() + b <= rect.height()) { y = newY; @@ -237,7 +249,7 @@ currentLineHeight = qMax(currentLineHeight, itemSizeHint.height()); - x += itemSizeHint.width() + spacing(); + x += itemSizeHint.width() + buttonSpacing; } m_layoutDirty = updateGeometry;