00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kiconloader.h>
00022
00023 #include "ktabwidget.h"
00024 #include "ktabbar.h"
00025
00026 KTabWidget::KTabWidget( QWidget *parent, const char *name, WFlags f )
00027 : QTabWidget( parent, name, f )
00028 {
00029 setTabBar( new KTabBar(this, "tabbar") );
00030 setAcceptDrops( true );
00031
00032 connect(tabBar(), SIGNAL(contextMenu( int, const QPoint & )), SLOT(contextMenu( int, const QPoint & )));
00033 connect(tabBar(), SIGNAL(mouseDoubleClick( int )), SLOT(mouseDoubleClick( int )));
00034 connect(tabBar(), SIGNAL(mouseMiddleClick( int )), SLOT(mouseMiddleClick( int )));
00035 connect(tabBar(), SIGNAL(initiateDrag( int )), SLOT(initiateDrag( int )));
00036 connect(tabBar(), SIGNAL(testCanDecode(const QDragMoveEvent *, bool & )), SIGNAL(testCanDecode(const QDragMoveEvent *, bool & )));
00037 connect(tabBar(), SIGNAL(receivedDropEvent( int, QDropEvent * )), SLOT(receivedDropEvent( int, QDropEvent * )));
00038 connect(tabBar(), SIGNAL(moveTab( int, int )), SLOT(moveTab( int, int )));
00039 connect(tabBar(), SIGNAL(closeRequest( int )), SLOT(closeRequest( int )));
00040 #ifndef QT_NO_WHEELEVENT
00041 connect(tabBar(), SIGNAL(wheelDelta( int )), SLOT(wheelDelta( int )));
00042 #endif
00043 }
00044
00045 KTabWidget::~KTabWidget()
00046 {
00047
00048
00049 }
00050
00051 void KTabWidget::setTabColor( QWidget *w, const QColor& color )
00052 {
00053 QTab *t = tabBar()->tabAt( indexOf( w ) );
00054 if (t) {
00055 static_cast<KTabBar*>(tabBar())->setTabColor( t->identifier(), color );
00056 }
00057 }
00058
00059 QColor KTabWidget::tabColor( QWidget *w ) const
00060 {
00061 QTab *t = tabBar()->tabAt( indexOf( w ) );
00062 if (t) {
00063 return static_cast<KTabBar*>(tabBar())->tabColor( t->identifier() );
00064 } else {
00065 return QColor();
00066 }
00067 }
00068
00069 void KTabWidget::setTabReorderingEnabled( bool on)
00070 {
00071 static_cast<KTabBar*>(tabBar())->setTabReorderingEnabled( on );
00072 }
00073
00074 bool KTabWidget::isTabReorderingEnabled() const
00075 {
00076 return static_cast<KTabBar*>(tabBar())->isTabReorderingEnabled();
00077 }
00078
00079 void KTabWidget::setTabCloseActivatePrevious( bool previous)
00080 {
00081 static_cast<KTabBar*>(tabBar())->setTabCloseActivatePrevious( previous );
00082 }
00083
00084 bool KTabWidget::tabCloseActivatePrevious() const
00085 {
00086 return static_cast<KTabBar*>(tabBar())->tabCloseActivatePrevious();
00087 }
00088
00089 void KTabWidget::dragMoveEvent( QDragMoveEvent *e )
00090 {
00091 if ( isEmptyTabbarSpace( e->pos() ) ) {
00092 bool accept = false;
00093
00094
00095 emit testCanDecode( e, accept);
00096 e->accept( accept );
00097 return;
00098 }
00099 e->accept( false );
00100 QTabWidget::dragMoveEvent( e );
00101 }
00102
00103 void KTabWidget::dropEvent( QDropEvent *e )
00104 {
00105 if ( isEmptyTabbarSpace( e->pos() ) ) {
00106 emit ( receivedDropEvent( e ) );
00107 return;
00108 }
00109 QTabWidget::dropEvent( e );
00110 }
00111
00112 #ifndef QT_NO_WHEELEVENT
00113 void KTabWidget::wheelEvent( QWheelEvent *e )
00114 {
00115 if ( e->orientation() == Horizontal )
00116 return;
00117
00118 if ( isEmptyTabbarSpace( e->pos() ) )
00119 wheelDelta( e->delta() );
00120 else
00121 e->ignore();
00122 }
00123
00124 void KTabWidget::wheelDelta( int delta )
00125 {
00126 if ( count() < 2 )
00127 return;
00128
00129 int page = currentPageIndex();
00130 if ( delta < 0 )
00131 page = (page + 1) % count();
00132 else {
00133 page--;
00134 if ( page < 0 )
00135 page = count() - 1;
00136 }
00137 setCurrentPage( page );
00138 }
00139 #endif
00140
00141 void KTabWidget::mouseDoubleClickEvent( QMouseEvent *e )
00142 {
00143 if ( isEmptyTabbarSpace( e->pos() ) ) {
00144 emit( mouseDoubleClick() );
00145 return;
00146 }
00147 QTabWidget::mouseDoubleClickEvent( e );
00148 }
00149
00150 void KTabWidget::mousePressEvent( QMouseEvent *e )
00151 {
00152 if ( e->button() == RightButton ) {
00153 if ( isEmptyTabbarSpace( e->pos() ) ) {
00154 emit( contextMenu( mapToGlobal( e->pos() ) ) );
00155 return;
00156 }
00157 } else if ( e->button() == MidButton ) {
00158 if ( isEmptyTabbarSpace( e->pos() ) ) {
00159 emit( mouseMiddleClick() );
00160 return;
00161 }
00162 }
00163 QTabWidget::mousePressEvent( e );
00164 }
00165
00166 void KTabWidget::receivedDropEvent( int index, QDropEvent *e )
00167 {
00168 emit( receivedDropEvent( page( index ), e ) );
00169 }
00170
00171 void KTabWidget::initiateDrag( int index )
00172 {
00173 emit( initiateDrag( page( index ) ) );
00174 }
00175
00176 void KTabWidget::contextMenu( int index, const QPoint &p )
00177 {
00178 emit( contextMenu( page( index ), p ) );
00179 }
00180
00181 void KTabWidget::mouseDoubleClick( int index )
00182 {
00183 emit( mouseDoubleClick( page( index ) ) );
00184 }
00185
00186 void KTabWidget::mouseMiddleClick( int index )
00187 {
00188 emit( mouseMiddleClick( page( index ) ) );
00189 }
00190
00191 void KTabWidget::moveTab( int from, int to )
00192 {
00193 QString tablabel = label( from );
00194 QWidget *w = page( from );
00195 QColor color = tabColor( w );
00196 QIconSet tabiconset = tabIconSet( w );
00197 QString tabtooltip = tabToolTip( w );
00198 bool current = ( w == currentPage() );
00199 bool enabled = isTabEnabled( w );
00200 blockSignals(true);
00201 removePage( w );
00202
00203
00204 QTab * t = new QTab();
00205 t->setText(tablabel);
00206 QTabWidget::insertTab( w, t, to );
00207
00208 w = page( to );
00209 changeTab( w, tabiconset, tablabel );
00210 setTabToolTip( w, tabtooltip );
00211 setTabColor( w, color );
00212 if ( current )
00213 showPage( w );
00214 setTabEnabled( w, enabled );
00215 blockSignals(false);
00216
00217 emit ( movedTab( from, to ) );
00218 }
00219
00220 bool KTabWidget::isEmptyTabbarSpace( const QPoint &p ) const
00221 {
00222 QPoint point( p );
00223 QSize size( tabBar()->sizeHint() );
00224 if ( ( tabPosition()==Top && point.y()< size.height() ) || ( tabPosition()==Bottom && point.y()>(height()-size.height() ) ) ) {
00225
00226 KTabWidget *that = const_cast<KTabWidget*>(this);
00227 QWidget *rightcorner = that->cornerWidget( TopRight );
00228 if ( rightcorner ) {
00229 if ( point.x()>=width()-rightcorner->width() )
00230 return false;
00231 }
00232 QWidget *leftcorner = that->cornerWidget( TopLeft );
00233 if ( leftcorner ) {
00234 if ( point.x()<=leftcorner->width() )
00235 return false;
00236 point.setX( point.x()-size.height() );
00237 }
00238 if ( tabPosition()==Bottom )
00239 point.setY( point.y()-( height()-size.height() ) );
00240 QTab *tab = tabBar()->selectTab( point);
00241 if( tab== 0L )
00242 return true;
00243 }
00244 return false;
00245 }
00246
00247 void KTabWidget::setHoverCloseButton( bool button )
00248 {
00249 static_cast<KTabBar*>(tabBar())->setHoverCloseButton( button );
00250 }
00251
00252 bool KTabWidget::hoverCloseButton() const
00253 {
00254 return static_cast<KTabBar*>(tabBar())->hoverCloseButton();
00255 }
00256
00257 void KTabWidget::setHoverCloseButtonDelayed( bool delayed )
00258 {
00259 static_cast<KTabBar*>(tabBar())->setHoverCloseButtonDelayed( delayed );
00260 }
00261
00262 bool KTabWidget::hoverCloseButtonDelayed() const
00263 {
00264 return static_cast<KTabBar*>(tabBar())->hoverCloseButtonDelayed();
00265 }
00266
00267 void KTabWidget::closeRequest( int index )
00268 {
00269 emit( closeRequest( page( index ) ) );
00270 }
00271
00272 #include "ktabwidget.moc"