void KoTabBar::mouseMoveEvent( QMouseEvent* ev ) { if ( d->readOnly ) return; QPoint pos = ev->pos(); if( !d->reverseLayout) pos = pos - QPoint( d->offset,0 ); // check if user drags a tab to move it int i = d->tabAt( pos ) + 1; if( ( i > 0 ) && ( i != d->targetTab ) ) { if( i == d->activeTab ) i = 0; if( i == d->activeTab+1 ) i = 0; if( i != d->targetTab ) { d->targetTab = i; d->autoScroll = false; update(); } } // drag past the very latest visible tab // e.g move a tab to the last ordering position QRect r = d->tabRects[ d->tabRects.count()-1 ]; bool moveToLast = false; if( r.isValid() ) { if( !d->reverseLayout ) if( pos.x() > r.right() ) if( pos.x() < width() ) moveToLast = true; if( d->reverseLayout ) if( pos.x() < r.x() ) if( pos.x() > 0 ) moveToLast = true; } if( moveToLast ) if( d->targetTab != (int)d->tabRects.count()+1 ) { d->targetTab = d->tabRects.count()+1; d->autoScroll = false; update(); } // outside far too left ? activate autoscroll... if ( pos.x() < 0 && !d->autoScroll ) { d->autoScroll = true; autoScrollBack(); } // outside far too right ? activate autoscroll... int w = width() - d->offset; if ( pos.x() > w && !d->autoScroll ) { d->autoScroll = true; autoScrollForward(); } }
void TabBar::autoScrollBack() { if (!d->autoScroll) return; scrollBack(); if (!canScrollBack()) d->autoScroll = false; else QTimer::singleShot(400, this, SLOT(autoScrollBack())); }