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 // Work-around kmdi brain damage which calls showPage() in insertTab() 00153 QTab * t = new QTab(); 00154 t->setText(tablabel); 00155 QTabWidget::insertTab( w, t, to ); 00156 00157 w = page( to ); 00158 changeTab( w, tabiconset, tablabel ); 00159 setTabToolTip( w, tabtooltip ); 00160 setTabColor( w, color ); 00161 if ( current ) 00162 showPage( w ); 00163 setTabEnabled( w, enabled ); 00164 blockSignals(false); 00165 00166 emit ( movedTab( from, to ) ); 00167 } 00168 00169 bool KTabWidget::isEmptyTabbarSpace( const QPoint &p ) const 00170 { 00171 QPoint point( p ); 00172 QSize size( tabBar()->sizeHint() ); 00173 if ( ( tabPosition()==Top && point.y()< size.height() ) || ( tabPosition()==Bottom && point.y()>(height()-size.height() ) ) ) { 00174 // QTabWidget::cornerWidget isn't const even it doesn't write any data ;( 00175 KTabWidget *that = const_cast<KTabWidget*>(this); 00176 QWidget *leftcorner = that->cornerWidget( TopLeft ); 00177 if ( leftcorner ) { 00178 if ( point.x()<=leftcorner->width() ) 00179 return true; 00180 point.setX( point.x()-size.height() ); 00181 } 00182 if ( tabPosition()==Bottom ) 00183 point.setY( point.y()-( height()-size.height() ) ); 00184 QTab *tab = tabBar()->selectTab( point); 00185 if( tab== 0L ) 00186 return true; 00187 } 00188 return false; 00189 } 00190 00191 void KTabWidget::setHoverCloseButton( bool button ) 00192 { 00193 static_cast<KTabBar*>(tabBar())->setHoverCloseButton( button ); 00194 } 00195 00196 bool KTabWidget::hoverCloseButton() const 00197 { 00198 return static_cast<KTabBar*>(tabBar())->hoverCloseButton(); 00199 } 00200 00201 void KTabWidget::setHoverCloseButtonDelayed( bool delayed ) 00202 { 00203 static_cast<KTabBar*>(tabBar())->setHoverCloseButtonDelayed( delayed ); 00204 } 00205 00206 bool KTabWidget::hoverCloseButtonDelayed() const 00207 { 00208 return static_cast<KTabBar*>(tabBar())->hoverCloseButtonDelayed(); 00209 } 00210 00211 void KTabWidget::closeRequest( int index ) 00212 { 00213 emit( closeRequest( page( index ) ) ); 00214 } 00215 00216 #include "ktabwidget.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 10 18:55:10 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003