kdeui Library API Documentation

ktabwidget.cpp

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2003 Stephan Binner <binner@kde.org>
00003     Copyright (C) 2003 Zack Rusin <zack@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
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 }
00041 
00042 KTabWidget::~KTabWidget()
00043 {
00044     //for the futur.
00045     //delete d;
00046 }
00047 
00048 void KTabWidget::setTabColor( QWidget *w, const QColor& color )
00049 {
00050     QTab *t = tabBar()->tabAt( indexOf( w ) );
00051     if (t) {
00052         static_cast<KTabBar*>(tabBar())->setTabColor( t->identifier(), color );
00053     }
00054 }
00055 
00056 QColor KTabWidget::tabColor( QWidget *w ) const
00057 {
00058     QTab *t = tabBar()->tabAt( indexOf( w ) );
00059     if (t) {
00060         return static_cast<KTabBar*>(tabBar())->tabColor( t->identifier() );
00061     } else {
00062         return QColor();
00063     }
00064 }
00065 
00066 void KTabWidget::setTabReorderingEnabled( bool on)
00067 {
00068     static_cast<KTabBar*>(tabBar())->setTabReorderingEnabled( on );
00069 }
00070 
00071 bool KTabWidget::isTabReorderingEnabled() const
00072 {
00073     return static_cast<KTabBar*>(tabBar())->isTabReorderingEnabled();
00074 }
00075 
00076 void KTabWidget::dragMoveEvent( QDragMoveEvent *e )
00077 {
00078     if ( isEmptyTabbarSpace( e->pos() ) ) {
00079         bool accept = false;
00080         // The receivers of the testCanDecode() signal has to adjust
00081         // 'accept' accordingly.
00082         emit testCanDecode( e, accept);
00083         e->accept( accept );
00084         return;
00085     }
00086     e->accept( false );
00087     QTabWidget::dragMoveEvent( e );
00088 }
00089 
00090 void KTabWidget::dropEvent( QDropEvent *e )
00091 {
00092     if ( isEmptyTabbarSpace( e->pos() ) ) {
00093         emit ( receivedDropEvent( e ) );
00094         return;
00095     }
00096     QTabWidget::dropEvent( e );
00097 }
00098 
00099 void KTabWidget::mousePressEvent( QMouseEvent *e )
00100 {
00101     if ( e->button() == RightButton ) {
00102         if ( isEmptyTabbarSpace( e->pos() ) ) {
00103             emit( contextMenu( mapToGlobal( e->pos() ) ) );
00104             return;
00105         }
00106     } else if ( e->button() == MidButton ) {
00107         if ( isEmptyTabbarSpace( e->pos() ) ) {
00108             emit( mouseMiddleClick() );
00109             return;
00110         }
00111     }
00112     QTabWidget::mousePressEvent( e );
00113 }
00114 
00115 void KTabWidget::receivedDropEvent( int index, QDropEvent *e )
00116 {
00117     emit( receivedDropEvent( page( index ), e ) );
00118 }
00119 
00120 void KTabWidget::initiateDrag( int index )
00121 {
00122     emit( initiateDrag( page( index ) ) );
00123 }
00124 
00125 void KTabWidget::contextMenu( int index, const QPoint &p )
00126 {
00127     emit( contextMenu( page( index ), p ) );
00128 }
00129 
00130 void KTabWidget::mouseDoubleClick( int index )
00131 {
00132     emit( mouseDoubleClick( page( index ) ) );
00133 }
00134 
00135 void KTabWidget::mouseMiddleClick( int index )
00136 {
00137     emit( mouseMiddleClick( page( index ) ) );
00138 }
00139 
00140 void KTabWidget::moveTab( int from, int to )
00141 {
00142     QString tablabel = label( from );
00143     QWidget *w = page( from );
00144     QColor color = tabColor( w );
00145     QIconSet tabiconset = tabIconSet( w );
00146     QString tabtooltip = tabToolTip( w );
00147     bool current = ( w == currentPage() );
00148     bool enabled = isTabEnabled( w );
00149     blockSignals(true);
00150     removePage( w );
00151 
00152     insertTab( w, tablabel, to );
00153     w = page( to );
00154     changeTab( w, tabiconset, tablabel );
00155     setTabToolTip( w, tabtooltip );
00156     setTabColor( w, color );
00157     if ( current )
00158         showPage( w );
00159     setTabEnabled( w, enabled );
00160     blockSignals(false);
00161 
00162     emit ( movedTab( from, to ) );
00163 }
00164 
00165 bool KTabWidget::isEmptyTabbarSpace( const QPoint &p ) const
00166 {
00167     QPoint point( p );
00168     QSize size( tabBar()->sizeHint() );
00169     if ( ( tabPosition()==Top && point.y()< size.height() ) || ( tabPosition()==Bottom && point.y()>(height()-size.height() ) ) ) {
00170 #if QT_VERSION >= 0x030200
00171     // QTabWidget::cornerWidget isn't const even it doesn't write any data ;(
00172     KTabWidget *that = const_cast<KTabWidget*>(this);
00173         if ( that->cornerWidget( TopLeft ) )
00174             point.setX( point.x()-size.height() );
00175 #endif
00176     if ( tabPosition()==Bottom )
00177             point.setY( point.y()-( height()-size.height() ) );
00178         QTab *tab = tabBar()->selectTab( point);
00179         if( tab== 0L )
00180             return true;
00181     }
00182     return false;
00183 }
00184 
00185 void KTabWidget::setHoverCloseButton( bool button )
00186 {
00187     static_cast<KTabBar*>(tabBar())->setHoverCloseButton( button );
00188 }
00189 
00190 bool KTabWidget::hoverCloseButton() const
00191 {
00192     return static_cast<KTabBar*>(tabBar())->hoverCloseButton();
00193 }
00194 
00195 void KTabWidget::setHoverCloseButtonDelayed( bool delayed )
00196 {
00197     static_cast<KTabBar*>(tabBar())->setHoverCloseButtonDelayed( delayed );
00198 }
00199 
00200 bool KTabWidget::hoverCloseButtonDelayed() const
00201 {
00202     return static_cast<KTabBar*>(tabBar())->hoverCloseButtonDelayed();
00203 }
00204 
00205 void KTabWidget::closeRequest( int index )
00206 {
00207     emit( closeRequest( page( index ) ) );
00208 }
00209 
00210 #include "ktabwidget.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 22 14:23:29 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003