ktabwidget.cpp
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 }
00041
00042 KTabWidget::~KTabWidget()
00043 {
00044
00045
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
00081
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
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"
This file is part of the documentation for kdeui Library Version 3.2.2.