File indexing completed on 2024-05-12 16:02:13
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2005 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "KoVBox.h" 0008 0009 #include <QEvent> 0010 #include <QApplication> 0011 #include <QVBoxLayout> 0012 0013 KoVBox::KoVBox(QWidget *parent) 0014 : QFrame(parent), 0015 d(0) 0016 { 0017 QVBoxLayout *layout = new QVBoxLayout(this); 0018 layout->setSpacing(0); 0019 layout->setMargin(0); 0020 } 0021 0022 KoVBox::~KoVBox() 0023 { 0024 } 0025 0026 void KoVBox::childEvent(QChildEvent *event) 0027 { 0028 switch (event->type()) { 0029 case QEvent::ChildAdded: { 0030 QChildEvent *childEvent = static_cast<QChildEvent *>(event); 0031 if (childEvent->child()->isWidgetType()) { 0032 QWidget *widget = static_cast<QWidget *>(childEvent->child()); 0033 static_cast<QBoxLayout *>(layout())->addWidget(widget); 0034 } 0035 0036 break; 0037 } 0038 case QEvent::ChildRemoved: { 0039 QChildEvent *childEvent = static_cast<QChildEvent *>(event); 0040 if (childEvent->child()->isWidgetType()) { 0041 QWidget *widget = static_cast<QWidget *>(childEvent->child()); 0042 static_cast<QBoxLayout *>(layout())->removeWidget(widget); 0043 } 0044 0045 break; 0046 } 0047 default: 0048 break; 0049 } 0050 QFrame::childEvent(event); 0051 } 0052 0053 QSize KoVBox::sizeHint() const 0054 { 0055 KoVBox *that = const_cast<KoVBox *>(this); 0056 QApplication::sendPostedEvents(that, QEvent::ChildAdded); 0057 0058 return QFrame::sizeHint(); 0059 } 0060 0061 QSize KoVBox::minimumSizeHint() const 0062 { 0063 KoVBox *that = const_cast<KoVBox *>(this); 0064 QApplication::sendPostedEvents(that, QEvent::ChildAdded); 0065 0066 return QFrame::minimumSizeHint(); 0067 } 0068 0069 void KoVBox::setSpacing(int spacing) 0070 { 0071 layout()->setSpacing(spacing); 0072 } 0073 0074 void KoVBox::setStretchFactor(QWidget *widget, int stretch) 0075 { 0076 static_cast<QBoxLayout *>(layout())->setStretchFactor(widget, stretch); 0077 } 0078 0079 void KoVBox::setMargin(int margin) 0080 { 0081 layout()->setMargin(margin); 0082 } 0083