KasItem *KasGrouper::maybeAddToDesktopGroup( Task::Ptr t ) { if ( t->isOnCurrentDesktop() ) return 0; KasItem *item = 0; for ( uint i = 0; i < kasbar->itemCount(); i++ ) { KasItem *ei = kasbar->itemAt( i ); if ( ei->inherits( "KasTaskItem" ) ) { KasTaskItem *eti = static_cast<KasTaskItem *> (ei); if ( eti->task()->desktop() == t->desktop() ) { KasGroupItem *egi = kasbar->convertToGroup( eti->task() ); egi->setGroupType( KasGroupItem::GroupDesktop ); egi->addTask( t ); item = egi; } } else if ( ei->inherits( "KasGroupItem" ) ) { KasGroupItem *egi = static_cast<KasGroupItem *> (ei); if ( egi->groupType() == KasGroupItem::GroupDesktop ) { if ( egi->task(0)->desktop() == t->desktop() ) { egi->addTask( t ); item = egi; } } } } return item; }
void KasBar::mousePressEvent(QMouseEvent *ev) { KasItem *i = itemAt( ev->pos() ); if ( i ) i->mousePressEvent( ev ); pressPos = ev->globalPos(); }
void KasBar::dragMoveEvent ( QDragMoveEvent *ev ) { KasItem *i = itemAt( ev->pos() ); if ( itemUnderMouse_ != i ) { if ( itemUnderMouse_ ) itemUnderMouse_->dragLeave(); if ( i ) i->dragEnter(); itemUnderMouse_ = i; } }
void KasBar::addTestItems() { KasItem *i = new KasItem( this ); insert( 0, i ); i->setText( "Animated" ); i->setIcon( KGlobal::iconLoader()->loadIcon( "icons", KIconLoader::NoGroup, KIconLoader::SizeMedium ) ); i->setAnimation( resources()->startupAnimation() ); QTimer *aniTimer = new QTimer( i ); connect( aniTimer, SIGNAL( timeout() ), i, SLOT( advanceAnimation() ) ); aniTimer->start( 100 ); i->setShowAnimation( true ); updateLayout(); }
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; }
void KasBar::mouseReleaseEvent(QMouseEvent *ev) { if ( !inDrag ) { KasItem *i = itemAt( ev->pos() ); if ( i ) i->mouseReleaseEvent( ev ); } else if ( detached ) { setDetachedPosition( pos() ); emit configChanged(); } pressPos = QPoint(); inDrag = false; }
void KasBar::updateMouseOver( QPoint pos ) { KasItem *i = itemAt(pos); if ( i == itemUnderMouse_ ) return; if ( itemUnderMouse_ ) itemUnderMouse_->mouseLeave(); if ( i ) i->mouseEnter(); if ( i && itemUnderMouse_ ) itemUnderMouse_->hidePopup(); itemUnderMouse_ = i; }
void KasTaskItem::refreshThumbnail() { if ( !kasbar()->thumbnailsEnabled() ) return; if ( !task_->isActive() ) return; // TODO: Check if the popup obscures the window KasItem *i = kasbar()->itemUnderMouse(); if ( i && i->isShowingPopup() ) { QTimer::singleShot( 200, this, SLOT( refreshThumbnail() ) ); return; } task_->setThumbnailSize( kasbar()->thumbnailSize() ); task_->updateThumbnail(); }
KasItem *KasGrouper::maybeAddToGroup( Task::Ptr t ) { KasItem *item = 0; TQString taskClass = t->className().lower(); for ( uint i = 0; (!item) && (i < kasbar->itemCount()); i++ ) { KasItem *ei = kasbar->itemAt( i ); if ( ei->inherits( "KasTaskItem" ) ) { KasTaskItem *eti = static_cast<KasTaskItem *> (ei); // NB This calls Task::className() not TQObject::className() TQString currClass = eti->task()->className().lower(); if ( Task::idMatch( currClass, taskClass ) ) { KasGroupItem *egi = kasbar->convertToGroup( eti->task() ); egi->addTask( t ); item = egi; break; } } else if ( ei->inherits( "KasGroupItem" ) ) { KasGroupItem *egi = static_cast<KasGroupItem *> (ei); for ( int i = 0; i < egi->taskCount(); i++ ) { // NB This calls Task::className() not TQObject::className() TQString currClass = egi->task( i )->className().lower(); if ( Task::idMatch( currClass, taskClass ) ) { egi->addTask( t ); item = egi; break; } } } } return item; }
void KasAboutDialog::addDemoBar() { TQHBox *box = new TQHBox( this ); box->setLineWidth(2); box->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); box->setSpacing( spacingHint() ); box->setMargin( marginHint() ); KasBar *bar = new KasBar( Qt::Horizontal, box ); bar->setItemSize( KasBar::Large ); bar->setMasked( false ); KasItem *ci = new KasItem( bar ); ci->setIcon( LargeIcon( "icons" ) ); bar->append( ci ); KasPopup *pop = new KasPopup( ci ); ci->setPopup( pop ); ci->setCustomPopup( true ); connect( ci, TQT_SIGNAL(leftButtonClicked(TQMouseEvent *)), ci, TQT_SLOT(togglePopup()) ); KasBar *groupbar = bar->createChildBar( ( bar->orientation() == Qt::Horizontal ) ? Qt::Vertical : Qt::Horizontal, pop ); KasItem *i = 0; KasClockItem *clk = new KasClockItem( groupbar ); groupbar->append( clk ); i = new KasLoadItem( groupbar ); groupbar->append( i ); groupbar->addTestItems(); pop->resize( groupbar->size() ); bar->setFixedSize( bar->itemExtent(), bar->itemExtent() ); addWidgetBelowList( box ); }
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(); }