File indexing completed on 2024-05-19 08:29:16
0001 /* 0002 SPDX-FileCopyrightText: 2007 Roberto Raggi <roberto@kdevelop.org> 0003 SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org> 0004 SPDX-FileCopyrightText: 2008 Vladimir Prus <ghost@cs.msu.su> 0005 0006 SPDX-License-Identifier: LicenseRef-MIT-KDevelop-Ideal 0007 */ 0008 0009 #include "ideallayout.h" 0010 0011 #include <QStyle> 0012 #include <QWidget> 0013 #include <QEvent> 0014 0015 #include <numeric> 0016 0017 using namespace Sublime; 0018 0019 namespace 0020 { 0021 0022 QBoxLayout::Direction toDirection(Qt::Orientation orientation) 0023 { 0024 return orientation == Qt::Horizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom; 0025 } 0026 0027 } 0028 0029 IdealButtonBarLayout::IdealButtonBarLayout(Qt::Orientation orientation, QWidget* styleParent) 0030 : QBoxLayout(toDirection(orientation)) // creating a child layout, styleParent is only saved for style 0031 , m_styleParentWidget(styleParent) 0032 , m_orientation(orientation) 0033 { 0034 if (m_styleParentWidget) { 0035 m_styleParentWidget->installEventFilter(this); 0036 } 0037 0038 setContentsMargins(0, 0, 0, 0); 0039 setSpacing(buttonSpacing()); 0040 } 0041 0042 IdealButtonBarLayout::~IdealButtonBarLayout() = default; 0043 0044 Qt::Orientation IdealButtonBarLayout::orientation() const 0045 { 0046 return m_orientation; 0047 } 0048 0049 Qt::Orientations IdealButtonBarLayout::expandingDirections() const 0050 { 0051 return orientation(); 0052 } 0053 0054 int IdealButtonBarLayout::buttonSpacing() const 0055 { 0056 if (!m_styleParentWidget) { 0057 return 0; 0058 } 0059 return m_styleParentWidget->style()->pixelMetric(QStyle::PM_ToolBarItemSpacing); 0060 } 0061 0062 bool IdealButtonBarLayout::eventFilter(QObject* watched, QEvent* event) 0063 { 0064 if (event->type() == QEvent::StyleChange) { 0065 setSpacing(buttonSpacing()); 0066 } 0067 0068 return QBoxLayout::eventFilter(watched, event); 0069 } 0070 0071 #include "moc_ideallayout.cpp"