void TabBar::mousePressEvent(QMouseEvent *e) { if (e->button() == RightButton) { QTab *tab = selectTab( e->pos() ); QWidget* page; page = tab ? _tabWidget->page( indexOf( tab->identifier() ) ) :0; QPopupMenu popup, popup1, popup2, popup3; if (page) { TraceItemView::Position p = _tabView->tabPosition(page); if (p != TraceItemView::Top) { popup.insertItem(i18n("Move to Top"), 81); popup2.insertItem(i18n("Top"), 91); } if (p != TraceItemView::Right) { popup.insertItem(i18n("Move to Right"), 82); popup2.insertItem(i18n("Right"), 92); } if (p != TraceItemView::Bottom) { popup.insertItem(i18n("Move to Bottom"), 83); popup2.insertItem(i18n("Bottom"), 93); } if (p != TraceItemView::Left) { popup.insertItem(i18n("Move to Bottom Left"), 84); popup2.insertItem(i18n("Bottom Left"), 94); } popup.insertItem(i18n("Move Area To"), &popup2, 2); popup.insertSeparator(); popup.insertItem(i18n("Hide This Tab"), 80); popup.insertItem(i18n("Hide Area"), 90); if (_tabView->visibleTabs() <2) { popup.setItemEnabled(80, false); popup.setItemEnabled(90, false); } else if (_tabView->visibleAreas() <2) popup.setItemEnabled(90, false); } popup3.insertItem(i18n("Top"), 101); popup3.insertItem(i18n("Right"), 102); popup3.insertItem(i18n("Bottom"), 103); popup3.insertItem(i18n("Bottom Left"), 104); popup.insertItem(i18n("Show Hidden On"), &popup3, 3); int r = popup.exec( mapToGlobal( e->pos() ) ); TraceItemView::Position p = TraceItemView::Hidden; if ((r % 10) == 1) p = TraceItemView::Top; if ((r % 10) == 2) p = TraceItemView::Right; if ((r % 10) == 3) p = TraceItemView::Bottom; if ((r % 10) == 4) p = TraceItemView::Left; if (r>=80 && r<100) _tabView->moveTab(page, p, r>=90); if (r>=100 && r<110) _tabView->moveTab(0, p, true); } QTabBar::mousePressEvent( e ); }
void KTabBar::mouseDoubleClickEvent( QMouseEvent *e ) { QTab *tab = selectTab( e->pos() ); if( tab!= 0L ) { emit( mouseDoubleClick( indexOf( tab->identifier() ) ) ); return; } QTabBar::mouseDoubleClickEvent( e ); }
void KTabBar::dropEvent( QDropEvent *e ) { QTab *tab = selectTab( e->pos() ); if( tab!= 0L ) { mActivateDragSwitchTabTimer->stop(); mDragSwitchTab = 0; emit( receivedDropEvent( indexOf( tab->identifier() ) , e ) ); return; } QTabBar::dropEvent( e ); }
void KTabBar::mousePressEvent( QMouseEvent *e ) { if( e->button() == LeftButton ) { mEnableCloseButtonTimer->stop(); mDragStart = e->pos(); } else if( e->button() == RightButton ) { QTab *tab = selectTab( e->pos() ); if( tab!= 0L ) { emit( contextMenu( indexOf( tab->identifier() ), mapToGlobal( e->pos() ) ) ); return; } } QTabBar::mousePressEvent( e ); }
void KTabBar::mouseReleaseEvent( QMouseEvent *e ) { if( e->button() == MidButton ) { QTab *tab = selectTab( e->pos() ); if ( mReorderStartTab==-1 ) { if( tab!= 0L ) { emit( mouseMiddleClick( indexOf( tab->identifier() ) ) ); return; } } else { releaseMouse(); setCursor( arrowCursor ); mReorderStartTab=-1; mReorderPreviousTab=-1; } } QTabBar::mouseReleaseEvent( e ); }
void KTabBar::setTabEnabled( int id, bool enabled ) { QTab * t = tab( id ); if ( t ) { if ( t->isEnabled() != enabled ) { t->setEnabled( enabled ); QRect r( t->rect() ); if ( !enabled && id == currentTab() && count()>1 ) { int index = indexOf( id ); index += ( index+1 == count() ) ? -1 : 1; t = tabAt( index ); if ( t->isEnabled() ) { r = r.unite( t->rect() ); QPtrList<QTab> *tablist = tabList(); tablist->append( tablist->take( tablist->findRef( t ) ) ); emit selected( t->identifier() ); } } repaint( r ); } } }
void KTabBar::mouseMoveEvent( QMouseEvent *e ) { if ( e->state() == LeftButton ) { QTab *tab = selectTab( e->pos() ); if ( mDragSwitchTab && tab != mDragSwitchTab ) { mActivateDragSwitchTabTimer->stop(); mDragSwitchTab = 0; } int delay = KGlobalSettings::dndEventDelay(); QPoint newPos = e->pos(); if( newPos.x() > mDragStart.x()+delay || newPos.x() < mDragStart.x()-delay || newPos.y() > mDragStart.y()+delay || newPos.y() < mDragStart.y()-delay ) { if( tab!= 0L ) { emit( initiateDrag( indexOf( tab->identifier() ) ) ); return; } } } else if ( e->state() == MidButton ) { if (mReorderStartTab==-1) { int delay = KGlobalSettings::dndEventDelay(); QPoint newPos = e->pos(); if( newPos.x() > mDragStart.x()+delay || newPos.x() < mDragStart.x()-delay || newPos.y() > mDragStart.y()+delay || newPos.y() < mDragStart.y()-delay ) { QTab *tab = selectTab( e->pos() ); if( tab!= 0L && mTabReorderingEnabled ) { mReorderStartTab = indexOf( tab->identifier() ); grabMouse( sizeAllCursor ); return; } } } else { QTab *tab = selectTab( e->pos() ); if( tab!= 0L ) { int reorderStopTab = indexOf( tab->identifier() ); if ( mReorderStartTab!=reorderStopTab && mReorderPreviousTab!=reorderStopTab ) { emit( moveTab( mReorderStartTab, reorderStopTab ) ); mReorderPreviousTab=mReorderStartTab; mReorderStartTab=reorderStopTab; return; } } } } if ( mHoverCloseButtonEnabled && mReorderStartTab==-1) { QTab *t = selectTab( e->pos() ); //BEGIN Workaround //Qt3.2.0 (and 3.2.1) emit wrong local coordinates //for MouseMove events when the pointer leaves a widget. Discard those //to avoid enabling the wrong hover button #ifdef __GNUC__ #warning "Workaround for Qt 3.2.0, 3.2.1 bug" #endif if ( e->globalPos() != mapToGlobal( e->pos() ) ) return; //END Workaround if( t && t->iconSet() && t->isEnabled() ) { QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ); QRect rect( 0, 0, pixmap.width() + 4, pixmap.height() +4); int xoff = 0, yoff = 0; // The additional offsets were found by try and error, TODO: find the rational behind them if ( t == tab( currentTab() ) ) { #if QT_VERSION >= 0x030200 xoff = style().pixelMetric( QStyle::PM_TabBarTabShiftHorizontal, this ) + 3; yoff = style().pixelMetric( QStyle::PM_TabBarTabShiftVertical, this ) - 4; #else xoff = 3; yoff = -4; #endif } else { xoff = 7; yoff = 0; } rect.moveLeft( t->rect().left() + 2 + xoff ); rect.moveTop( t->rect().center().y()-pixmap.height()/2 + yoff ); if ( rect.contains( e->pos() ) ) { if ( mHoverCloseButton ) { if ( mHoverCloseButtonTab == t ) return; mEnableCloseButtonTimer->stop(); delete mHoverCloseButton; } mHoverCloseButton = new QPushButton( this ); mHoverCloseButton->setIconSet( KGlobal::iconLoader()->loadIcon("fileclose", KIcon::Toolbar, KIcon::SizeSmall, KIcon::ActiveState) ); mHoverCloseButton->setGeometry( rect ); QToolTip::add(mHoverCloseButton,i18n("Close this tab")); mHoverCloseButton->setFlat(true); mHoverCloseButton->show(); if ( mHoverCloseButtonDelayed ) { mHoverCloseButton->setEnabled(false); mEnableCloseButtonTimer->start( QApplication::doubleClickInterval(), true ); } mHoverCloseButtonTab = t; connect( mHoverCloseButton, SIGNAL( clicked() ), SLOT( closeButtonClicked() ) ); return; } } if ( mHoverCloseButton ) { mEnableCloseButtonTimer->stop(); delete mHoverCloseButton; mHoverCloseButton = 0; } } QTabBar::mouseMoveEvent( e ); }