// creates a new tabbar TabBar::TabBar(QWidget* parent, const char* /*name*/) : QWidget(parent) , d(new TabBarPrivate) { d->tabbar = this; d->readOnly = false; d->firstTab = 1; d->lastTab = 0; d->activeTab = 0; d->targetTab = 0; d->wheelDelta = 0; d->autoScroll = false; d->offset = 64; // initialize the scroll buttons d->scrollFirstButton = new QToolButton(this); connect(d->scrollFirstButton, SIGNAL(clicked()), this, SLOT(scrollFirst())); d->scrollLastButton = new QToolButton(this); connect(d->scrollLastButton, SIGNAL(clicked()), this, SLOT(scrollLast())); d->scrollBackButton = new QToolButton(this); connect(d->scrollBackButton, SIGNAL(clicked()), this, SLOT(scrollBack())); d->scrollForwardButton = new QToolButton(this); connect(d->scrollForwardButton, SIGNAL(clicked()), this, SLOT(scrollForward())); d->layoutButtons(); d->updateButtons(); }
void TabBar::autoScrollBack() { if (!d->autoScroll) return; scrollBack(); if (!canScrollBack()) d->autoScroll = false; else QTimer::singleShot(400, this, SLOT(autoScrollBack())); }
void KoTabBar::wheelEvent( QWheelEvent * e ) { if ( d->tabs.count() == 0 ) { update(); return; } // Currently one wheel movement is a delta of 120. // The 'unused' delta is stored for devices that allow // a higher scrolling resolution. // The delta required to move one tab is one wheel movement: const int deltaRequired = 120; d->wheelDelta += e->delta(); int tabDelta = - (d->wheelDelta / deltaRequired); d->wheelDelta = d->wheelDelta % deltaRequired; int numTabs = d->tabs.size(); if(d->activeTab + tabDelta > numTabs) { // Would take us past the last tab d->activeTab = numTabs; } else if (d->activeTab + tabDelta < 1) { // Would take us before the first tab d->activeTab = 1; } else { d->activeTab = d->activeTab + tabDelta; } // Find the left and right edge of the new tab. If we're // going forward, and the right of the new tab isn't visible // then scroll forward. Likewise, if going back, and the // left of the new tab isn't visible, then scroll back. int activeTabRight = d->tabRects[ d->activeTab-1 ].right(); int activeTabLeft = d->tabRects[ d->activeTab-1 ].left(); if(tabDelta > 0 && activeTabRight > width() - d->offset ) { scrollForward(); } else if(tabDelta < 0 && activeTabLeft < width() - d->offset ) { scrollBack(); } update(); emit tabChanged( d->tabs[ d->activeTab-1] ); }
void TabBar::ensureVisible(const QString& tab) { int i = d->tabs.indexOf(tab); if (i == -1) return; i++; // already visible, then do nothing if ((i >= d->firstTab) && (i <= d->lastTab)) return; if (i < d->firstTab) while (i < d->firstTab) scrollBack(); if (i > d->lastTab) while (i > d->lastTab) scrollForward(); }