KDEUI
khbox.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005 David Faure <faure@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "khbox.h" 00020 00021 #include <QtCore/QEvent> 00022 #include <QtGui/QApplication> 00023 #include <QtGui/QHBoxLayout> 00024 #include <QtGui/QVBoxLayout> 00025 00026 KHBox::KHBox( QWidget* parent ) 00027 : QFrame( parent ), 00028 d( 0 ) 00029 { 00030 QHBoxLayout* layout = new QHBoxLayout( this ); 00031 layout->setSpacing( 0 ); 00032 layout->setMargin( 0 ); 00033 00034 setLayout( layout ); 00035 } 00036 00037 00038 KHBox::KHBox( bool /*vertical*/, QWidget* parent ) 00039 : QFrame( parent ), 00040 d( 0 ) 00041 { 00042 QVBoxLayout* layout = new QVBoxLayout( this ); 00043 layout->setSpacing( 0 ); 00044 layout->setMargin( 0 ); 00045 00046 setLayout( layout ); 00047 } 00048 00049 KHBox::~KHBox() 00050 { 00051 } 00052 00053 void KHBox::childEvent( QChildEvent* event ) 00054 { 00055 switch ( event->type() ) { 00056 case QEvent::ChildAdded: 00057 { 00058 QChildEvent* childEvent = static_cast<QChildEvent *>( event ); 00059 if ( childEvent->child()->isWidgetType() ) { 00060 QWidget* widget = static_cast<QWidget *>( childEvent->child() ); 00061 static_cast<QBoxLayout *>( layout() )->addWidget( widget ); 00062 } 00063 00064 break; 00065 } 00066 case QEvent::ChildRemoved: 00067 { 00068 QChildEvent* childEvent = static_cast<QChildEvent *>( event ); 00069 if ( childEvent->child()->isWidgetType() ) { 00070 QWidget* widget = static_cast<QWidget *>( childEvent->child() ); 00071 static_cast<QBoxLayout *>( layout() )->removeWidget( widget ); 00072 } 00073 00074 break; 00075 } 00076 default: 00077 break; 00078 } 00079 QFrame::childEvent(event); 00080 } 00081 00082 QSize KHBox::sizeHint() const 00083 { 00084 KHBox* that = const_cast<KHBox *>( this ); 00085 QApplication::sendPostedEvents( that, QEvent::ChildAdded ); 00086 00087 return QFrame::sizeHint(); 00088 } 00089 00090 QSize KHBox::minimumSizeHint() const 00091 { 00092 KHBox* that = const_cast<KHBox *>( this ); 00093 QApplication::sendPostedEvents( that, QEvent::ChildAdded ); 00094 00095 return QFrame::minimumSizeHint(); 00096 } 00097 00098 void KHBox::setSpacing( int spacing ) 00099 { 00100 layout()->setSpacing( spacing ); 00101 } 00102 00103 void KHBox::setStretchFactor( QWidget* widget, int stretch ) 00104 { 00105 static_cast<QBoxLayout *>( layout() )->setStretchFactor( widget, stretch ); 00106 } 00107 00108 void KHBox::setMargin( int margin ) 00109 { 00110 layout()->setMargin( margin ); 00111 } 00112 00113 #include "khbox.moc"