54 #include "QtFlapBox.hh" 66 QtFlapBox::QtFlapBox( QWidget * _parent, Qt::WindowFlags )
67 : QScrollArea( _parent )
69 setBackgroundRole(QPalette::Dark);
71 QSizePolicy sp = sizePolicy();
72 sp.setHorizontalPolicy( QSizePolicy::MinimumExpanding );
73 sp.setVerticalPolicy( QSizePolicy::Preferred );
74 sp.setHorizontalStretch( 1 );
75 sp.setVerticalStretch( 0 );
79 container =
new QWidget;
80 container->setBackgroundRole( QPalette::Button );
84 boxlayout =
new QVBoxLayout( container );
85 boxlayout->setMargin(0);
86 boxlayout->setSpacing(0);
89 setWidget( container );
98 QtFlapBox::~QtFlapBox()
107 QtFlapBox::addItem( QWidget * _widget,
109 const QString & _text )
111 return insertItem( -1, _widget, _icon, _text );
119 QtFlapBox::addItem( QWidget * _widget,
const QString & _text )
121 return insertItem( -1, _widget, QIcon(), _text);
129 QtFlapBox::count()
const 131 return flapList.count();
139 QtFlapBox::indexOf( QWidget * _widget )
const 141 Flap * f = flap( _widget );
142 return ( f ? flapList.indexOf( *f ) : -1 );
150 QtFlapBox::insertItem(
int _index,
153 const QString & _text )
158 connect( _widget, SIGNAL( destroyed( QObject * ) ),
159 this, SLOT( widgetDestroyed( QObject * ) ) );
162 f.button =
new QPushButton;
164 connect( f.button, SIGNAL( clicked() ),
165 this, SLOT( buttonClicked() ) );
168 f.widget->setParent( container );
174 if ( _index < 0 || _index >= flapList.count() )
176 _index = flapList.count();
177 flapList.append( f );
178 boxlayout->addWidget( f.button );
179 boxlayout->addWidget( f.widget );
184 flapList.insert( _index, f );
203 QtFlapBox::insertItem(
int _index,
205 const QString & _text )
207 return insertItem( _index, _widget, QIcon(), _text );
215 QtFlapBox::isItemEnabled(
int _index )
const 217 const Flap * f = flap( _index );
218 return f && f->button->isEnabled();
226 QtFlapBox::itemIcon(
int _index )
const 228 const Flap * f = flap( _index );
229 return ( f ? f->icon() : QIcon() );
236 QtFlapBox::itemText(
int _index )
const 238 const Flap * f = flap( _index );
239 return ( f ? f->text() : QString() );
247 QtFlapBox::itemToolTip(
int _index )
const 249 const Flap * f = flap( _index );
250 return ( f ? f->toolTip() : QString() );
258 QtFlapBox::removeItem(
int _index )
260 if ( QWidget * w = widget( _index ) )
262 disconnect( w, SIGNAL( destroyed( QObject * ) ),
263 this, SLOT( widgetDestroyed( QObject * ) ) );
264 w->setParent(
this );
266 widgetDestroyed( w );
276 QtFlapBox::setItemEnabled(
int _index,
bool _enabled )
278 Flap * f = flap( _index );
282 f->button->setEnabled( _enabled );
290 QtFlapBox::setItemIcon(
int _index,
const QIcon & _icon )
292 Flap * f = flap( _index );
302 QtFlapBox::setItemText(
int _index,
const QString & _text )
304 Flap * f = flap( _index );
314 QtFlapBox::setItemToolTip(
int _index,
const QString & _tip )
316 Flap * f = flap( _index );
318 f->setToolTip( _tip );
326 QtFlapBox::widget(
int _index )
const 328 if ( _index < 0 || _index >= (
int) flapList.size() )
331 return flapList.at( _index ).widget;
339 QtFlapBox::isItemHidden(
int _index )
const 341 const Flap * f = flap( _index );
346 return f->widget->isHidden();
354 QtFlapBox::setItemHidden(
int _index,
bool _hidden )
356 Flap * f = flap( _index );
360 f->widget->setHidden( _hidden );
368 QtFlapBox::sizeHint()
const 373 for ( FlapList::ConstIterator i = flapList.constBegin();
374 i != flapList.constEnd(); ++i)
376 QWidget * w = i->widget;
377 QSize ws = w->sizeHint();
379 QPushButton * b = i->button;
380 QSize bs = b->sizeHint();
382 if ( bs.width() > width_hint )
383 width_hint = bs.width();
385 if ( ! w->isHidden() )
387 height_hint += ws.height();
388 if ( ws.width() > width_hint )
389 width_hint = ws.width();
392 height_hint += bs.height();
396 QSize sz( width_hint + verticalScrollBar()->sizeHint().width()
408 QtFlapBox::flap( QWidget * _widget )
const 413 for ( FlapList::ConstIterator i = flapList.constBegin();
414 i != flapList.constEnd(); ++i )
415 if ( (*i).widget == _widget )
416 return (Flap*) &(*i);
425 const QtFlapBox::Flap *
426 QtFlapBox::flap(
int _index )
const 428 if ( _index >= 0 && _index < flapList.size() )
429 return &flapList.at( _index );
438 QtFlapBox::flap(
int _index )
440 if ( _index >= 0 && _index < flapList.size() )
441 return &flapList[ _index ];
476 QtFlapBox::relayout()
479 boxlayout =
new QVBoxLayout;
480 boxlayout->setMargin(0);
481 boxlayout->setSpacing(0);
483 for ( FlapList::ConstIterator i = flapList.constBegin();
484 i != flapList.constEnd(); ++i )
486 boxlayout->addWidget( (*i).button );
487 boxlayout->addWidget( (*i).widget );
490 container->setLayout( boxlayout );
492 QSize area_size = size();
493 QSize cont_size = container->sizeHint();
495 s.setWidth( area_size.width() );
496 s.setHeight( cont_size.height() );
498 container->resize( s );
509 QtFlapBox::buttonClicked()
511 QPushButton * b = ::qobject_cast< QPushButton * >( sender() );
513 for ( FlapList::ConstIterator i = flapList.constBegin();
514 i != flapList.constEnd(); ++i)
515 if ( i->button == b )
517 QWidget * w = i->widget;
535 QtFlapBox::widgetDestroyed( QObject * _object )
538 QWidget * p = ( QWidget * ) _object;
540 Flap * f = flap( p );
545 boxlayout->removeWidget( f->widget );
546 boxlayout->removeWidget( f->button );
549 flapList.removeAll( *f );
557 QtFlapBox::resizeEvent( QResizeEvent * _event )
559 QSize container_size = container->size();
561 container_size.setWidth( _event->size().width() );
563 container->resize( container_size );
565 QScrollArea::resizeEvent( _event );
Namespace providing different geometric functions concerning angles.