Esempio n. 1
0
KasItem* KasBar::itemAt(const QPoint &p)
{
   KasItem *i;
   QRect cr;

   for (i = items.first(); i; i = items.next()) {
       cr.setTopLeft( i->pos() );
       cr.setSize( QSize( itemExtent(), itemExtent() ) );

       if(cr.contains(p))
	   return i;
   }

   return 0;
}
Esempio n. 2
0
void KasBar::updateLayout()
{
//    kDebug(1345) << "KasBar: updateLayout(), count is " << items.count();
    if ( !isUpdatesEnabled() )
	return;
    bool updates = isUpdatesEnabled();
    setUpdatesEnabled( false );

// This is for testing a rectangular layout
//    boxesPerLine_ = (uint) ceil(sqrt( items.count() ));

   // Work out the number of rows and columns
   unsigned int r=0, c=0;
   if( items.count() > (unsigned int) boxesPerLine_ ) {
      r = items.count()/boxesPerLine_;
      c = boxesPerLine_;
   }
   else{
      r = 1;
      c = items.count();
   }

   if( r*c < items.count() ) // remainders
      ++r;

   QSize sz;
   if ( orient == Qt::Horizontal )
       sz = QSize( c * itemExtent(), r * itemExtent() );
   else
       sz = QSize( r * itemExtent(), c * itemExtent() );

   if ( sz != size() ) {
       resize( sz );
   }

   setUpdatesEnabled( updates );

   QWidget *top = topLevelWidget();
   QRegion mask;

   KasItem *i;
   if ( orient == Qt::Horizontal ) {
       for ( i = items.first(); i; i = items.next() ) {
	   int x = (items.at() % c) * itemExtent();

	   if ( direction_ == QBoxLayout::RightToLeft )
	       x = width() - x - itemExtent();

	   i->setPos( x, (items.at() / c) * itemExtent() );
	   i->update();
	   mask = mask.unite( QRegion( QRect( i->pos(), QSize(itemExtent(),itemExtent()) ) ) );
       }
   }
   else {
       for ( i = items.first(); i; i = items.next() ) {
	   int y = (items.at() / r) * itemExtent();

	   if ( direction_ == QBoxLayout::BottomToTop )
	       y = height() - y - itemExtent();

	   i->setPos( (items.at() % r) * itemExtent(), y );
	   i->update();
	   mask = mask.unite( QRegion( QRect( i->pos(), QSize(itemExtent(),itemExtent()) ) ) );
       }
   }

   if ( useMask_ )
       top->setMask( mask );
   else
       top->clearMask();
   update();
}