60 #include "QtFlapBox.hh" 72 QtFlapBox::QtFlapBox( QWidget * _parent, Qt::WindowFlags )
73 : QScrollArea( _parent )
75 setBackgroundRole(QPalette::Dark);
77 QSizePolicy sp = sizePolicy();
78 sp.setHorizontalPolicy( QSizePolicy::MinimumExpanding );
79 sp.setVerticalPolicy( QSizePolicy::Preferred );
80 sp.setHorizontalStretch( 1 );
81 sp.setVerticalStretch( 0 );
85 container =
new QWidget;
86 container->setBackgroundRole( QPalette::Button );
90 boxlayout =
new QVBoxLayout( container );
91 boxlayout->setMargin(0);
92 boxlayout->setSpacing(0);
95 setWidget( container );
104 QtFlapBox::~QtFlapBox()
113 QtFlapBox::addItem( QWidget * _widget,
115 const QString & _text )
117 return insertItem( -1, _widget, _icon, _text );
125 QtFlapBox::addItem( QWidget * _widget,
const QString & _text )
127 return insertItem( -1, _widget, QIcon(), _text);
135 QtFlapBox::count()
const 137 return flapList.count();
145 QtFlapBox::indexOf( QWidget * _widget )
const 147 Flap * f = flap( _widget );
148 return ( f ? flapList.indexOf( *f ) : -1 );
156 QtFlapBox::insertItem(
int _index,
159 const QString & _text )
164 connect( _widget, SIGNAL( destroyed( QObject * ) ),
165 this, SLOT( widgetDestroyed( QObject * ) ) );
168 f.button =
new QPushButton;
170 connect( f.button, SIGNAL( clicked() ),
171 this, SLOT( buttonClicked() ) );
174 f.widget->setParent( container );
180 if ( _index < 0 || _index >= flapList.count() )
182 _index = flapList.count();
183 flapList.append( f );
184 boxlayout->addWidget( f.button );
185 boxlayout->addWidget( f.widget );
190 flapList.insert( _index, f );
209 QtFlapBox::insertItem(
int _index,
211 const QString & _text )
213 return insertItem( _index, _widget, QIcon(), _text );
221 QtFlapBox::isItemEnabled(
int _index )
const 223 const Flap * f = flap( _index );
224 return f && f->button->isEnabled();
232 QtFlapBox::itemIcon(
int _index )
const 234 const Flap * f = flap( _index );
235 return ( f ? f->icon() : QIcon() );
242 QtFlapBox::itemText(
int _index )
const 244 const Flap * f = flap( _index );
245 return ( f ? f->text() : QString() );
253 QtFlapBox::itemToolTip(
int _index )
const 255 const Flap * f = flap( _index );
256 return ( f ? f->toolTip() : QString() );
264 QtFlapBox::removeItem(
int _index )
266 if ( QWidget * w = widget( _index ) )
268 disconnect( w, SIGNAL( destroyed( QObject * ) ),
269 this, SLOT( widgetDestroyed( QObject * ) ) );
270 w->setParent(
this );
272 widgetDestroyed( w );
282 QtFlapBox::setItemEnabled(
int _index,
bool _enabled )
284 Flap * f = flap( _index );
288 f->button->setEnabled( _enabled );
296 QtFlapBox::setItemIcon(
int _index,
const QIcon & _icon )
298 Flap * f = flap( _index );
308 QtFlapBox::setItemText(
int _index,
const QString & _text )
310 Flap * f = flap( _index );
320 QtFlapBox::setItemToolTip(
int _index,
const QString & _tip )
322 Flap * f = flap( _index );
324 f->setToolTip( _tip );
332 QtFlapBox::widget(
int _index )
const 334 if ( _index < 0 || _index >= (
int) flapList.size() )
337 return flapList.at( _index ).widget;
345 QtFlapBox::isItemHidden(
int _index )
const 347 const Flap * f = flap( _index );
352 return f->widget->isHidden();
360 QtFlapBox::setItemHidden(
int _index,
bool _hidden )
362 Flap * f = flap( _index );
366 f->widget->setHidden( _hidden );
374 QtFlapBox::sizeHint()
const 379 for ( FlapList::ConstIterator i = flapList.constBegin();
380 i != flapList.constEnd(); ++i)
382 QWidget * w = i->widget;
383 QSize ws = w->sizeHint();
385 QPushButton * b = i->button;
386 QSize bs = b->sizeHint();
388 if ( bs.width() > width_hint )
389 width_hint = bs.width();
391 if ( ! w->isHidden() )
393 height_hint += ws.height();
394 if ( ws.width() > width_hint )
395 width_hint = ws.width();
398 height_hint += bs.height();
402 QSize sz( width_hint + verticalScrollBar()->sizeHint().width()
414 QtFlapBox::flap( QWidget * _widget )
const 419 for ( FlapList::ConstIterator i = flapList.constBegin();
420 i != flapList.constEnd(); ++i )
421 if ( (*i).widget == _widget )
422 return (Flap*) &(*i);
431 const QtFlapBox::Flap *
432 QtFlapBox::flap(
int _index )
const 434 if ( _index >= 0 && _index < flapList.size() )
435 return &flapList.at( _index );
444 QtFlapBox::flap(
int _index )
446 if ( _index >= 0 && _index < flapList.size() )
447 return &flapList[ _index ];
482 QtFlapBox::relayout()
485 boxlayout =
new QVBoxLayout;
486 boxlayout->setMargin(0);
487 boxlayout->setSpacing(0);
489 for ( FlapList::ConstIterator i = flapList.constBegin();
490 i != flapList.constEnd(); ++i )
492 boxlayout->addWidget( (*i).button );
493 boxlayout->addWidget( (*i).widget );
496 container->setLayout( boxlayout );
498 QSize area_size = size();
499 QSize cont_size = container->sizeHint();
501 s.setWidth( area_size.width() );
502 s.setHeight( cont_size.height() );
504 container->resize( s );
515 QtFlapBox::buttonClicked()
517 QPushButton * b = ::qobject_cast< QPushButton * >( sender() );
519 for ( FlapList::ConstIterator i = flapList.constBegin();
520 i != flapList.constEnd(); ++i)
521 if ( i->button == b )
523 QWidget * w = i->widget;
541 QtFlapBox::widgetDestroyed( QObject * _object )
544 QWidget * p = ( QWidget * ) _object;
546 Flap * f = flap( p );
551 boxlayout->removeWidget( f->widget );
552 boxlayout->removeWidget( f->button );
555 flapList.removeAll( *f );
563 QtFlapBox::resizeEvent( QResizeEvent * _event )
565 QSize container_size = container->size();
567 container_size.setWidth( _event->size().width() );
569 container->resize( container_size );
571 QScrollArea::resizeEvent( _event );
Namespace providing different geometric functions concerning angles.