File indexing completed on 2024-05-05 04:49:25
0001 /* 0002 * Copyright (C) 2017 Malte Veerman <malte.veerman@gmail.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License along 0015 * with this program; if not, write to the Free Software Foundation, Inc., 0016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0017 * 0018 */ 0019 0020 #include "BoxWidget.h" 0021 0022 #include <QChildEvent> 0023 #include <QHBoxLayout> 0024 #include <QVBoxLayout> 0025 0026 BoxWidget::BoxWidget( bool vertical, QWidget *parent ) : QFrame( parent ) 0027 { 0028 if( vertical ) 0029 setLayout( new QVBoxLayout ); 0030 else 0031 setLayout( new QHBoxLayout ); 0032 0033 layout()->setSpacing( 0 ); 0034 layout()->setMargin( 0 ); 0035 } 0036 0037 QBoxLayout* BoxWidget::layout() const 0038 { 0039 return static_cast<QBoxLayout*>( QWidget::layout() ); 0040 } 0041 0042 void BoxWidget::childEvent(QChildEvent *event) 0043 { 0044 switch ( event->type() ) 0045 { 0046 case QEvent::ChildAdded: 0047 { 0048 if ( event->child()->isWidgetType() ) 0049 { 0050 QWidget *widget = static_cast<QWidget*>( event->child() ); 0051 layout()->addWidget( widget ); 0052 } 0053 break; 0054 } 0055 case QEvent::ChildRemoved: 0056 { 0057 if ( event->child()->isWidgetType() ) 0058 { 0059 QWidget *widget = static_cast<QWidget*>( event->child() ); 0060 layout()->removeWidget( widget ); 0061 } 0062 break; 0063 } 0064 default: 0065 break; 0066 } 0067 QFrame::childEvent( event ); 0068 }