KDEUI
khbox.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 , 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"