void TabBar::mousePressEvent(QMouseEvent* ev) { if (d->tabs.count() == 0) { update(); return; } d->layoutTabs(); QPoint pos = ev->pos(); if (!isRightToLeft()) pos = pos - QPoint(d->offset, 0); int tab = d->tabAt(pos) + 1; if ((tab > 0) && (tab != d->activeTab)) { d->activeTab = tab; update(); emit tabChanged(d->tabs[ d->activeTab-1]); // scroll if partially visible if (d->tabRects[ tab-1 ].right() > width() - d->offset) scrollForward(); } if (ev->button() == Qt::RightButton) if (!d->readOnly) emit contextMenu(ev->globalPos()); }
// 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::autoScrollForward() { if (!d->autoScroll) return; scrollForward(); if (!canScrollForward()) d->autoScroll = false; else QTimer::singleShot(400, this, SLOT(autoScrollForward())); }
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] ); }
KarbonPaletteBarWidget::KarbonPaletteBarWidget(Qt::Orientation orientation, QWidget *parent) : QWidget(parent) , m_prevButton(0), m_nextButton(0), m_choosePalette(0), m_colorBar(0) , m_palettes(KoResourceServerProvider::instance()->paletteServer()) { m_palettes.connectToResourceServer(); m_prevButton = new QToolButton(this); m_prevButton->setAutoRepeat(true); m_prevButton->setAutoRepeatInterval(ScrollUpdateIntervall); m_nextButton = new QToolButton(this); m_nextButton->setAutoRepeat(true); m_nextButton->setAutoRepeatInterval(ScrollUpdateIntervall); m_choosePalette = new QToolButton(this); m_choosePalette->setToolTip(i18n("Select palette")); m_choosePalette->setArrowType(Qt::DownArrow); m_colorBar = new KarbonPaletteWidget(this); m_colorBar->setOrientation(orientation); connect(m_prevButton, SIGNAL(clicked()), m_colorBar, SLOT(scrollBackward())); connect(m_nextButton, SIGNAL(clicked()), m_colorBar, SLOT(scrollForward())); connect(m_colorBar, SIGNAL(colorSelected(KoColor)), this, SIGNAL(colorSelected(KoColor))); connect(m_colorBar, SIGNAL(scrollOffsetChanged()), this, SLOT(updateButtons())); connect(m_choosePalette, SIGNAL(clicked()), this, SLOT(selectPalette())); setMinimumSize(FixedWidgetSize, FixedWidgetSize); m_colorBar->setMinimumSize(FixedWidgetSize, FixedWidgetSize); createLayout(); m_documentColors.setName(DocumentColorsName); QList<KoResource*> resources = m_palettes.resources(); if (resources.count()) { KConfigGroup paletteGroup = KGlobal::mainComponent().config()->group("PaletteBar"); QString lastPalette = paletteGroup.readEntry("LastPalette", "SVG Colors"); KoResource *r = resources.first(); if (lastPalette == DocumentColorsName) { r = &m_documentColors; } else { foreach(KoResource *res, resources) { if (res->name() == lastPalette) { r = res; break; } } } m_colorBar->setPalette(dynamic_cast<KoColorSet*>(r)); updateDocumentColors(); }
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(); }