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( e->button() != LeftButton )
00144
return;
00145
00146
if ( isEmptyTabbarSpace( e->pos() ) ) {
00147 emit(
mouseDoubleClick() );
00148
return;
00149 }
00150 QTabWidget::mouseDoubleClickEvent( e );
00151 }
00152
00153
void KTabWidget::mousePressEvent(
QMouseEvent *e )
00154 {
00155
if ( e->button() == RightButton ) {
00156
if ( isEmptyTabbarSpace( e->pos() ) ) {
00157 emit(
contextMenu( mapToGlobal( e->pos() ) ) );
00158
return;
00159 }
00160 }
else if ( e->button() == MidButton ) {
00161
if ( isEmptyTabbarSpace( e->pos() ) ) {
00162 emit(
mouseMiddleClick() );
00163
return;
00164 }
00165 }
00166 QTabWidget::mousePressEvent( e );
00167 }
00168
00169
void KTabWidget::receivedDropEvent(
int index,
QDropEvent *e )
00170 {
00171 emit(
receivedDropEvent( page( index ), e ) );
00172 }
00173
00174
void KTabWidget::initiateDrag(
int index )
00175 {
00176 emit(
initiateDrag( page( index ) ) );
00177 }
00178
00179
void KTabWidget::contextMenu(
int index,
const QPoint &p )
00180 {
00181 emit(
contextMenu( page( index ), p ) );
00182 }
00183
00184
void KTabWidget::mouseDoubleClick(
int index )
00185 {
00186 emit(
mouseDoubleClick( page( index ) ) );
00187 }
00188
00189
void KTabWidget::mouseMiddleClick(
int index )
00190 {
00191 emit(
mouseMiddleClick( page( index ) ) );
00192 }
00193
00194 void KTabWidget::moveTab(
int from,
int to )
00195 {
00196
QString tablabel = label( from );
00197
QWidget *w = page( from );
00198
QColor color = tabColor( w );
00199
QIconSet tabiconset = tabIconSet( w );
00200
QString tabtooltip = tabToolTip( w );
00201
bool current = ( w == currentPage() );
00202
bool enabled = isTabEnabled( w );
00203 blockSignals(
true);
00204 removePage( w );
00205
00206
00207
QTab * t =
new QTab();
00208 t->setText(tablabel);
00209 QTabWidget::insertTab( w, t, to );
00210
00211 w = page( to );
00212 changeTab( w, tabiconset, tablabel );
00213 setTabToolTip( w, tabtooltip );
00214
setTabColor( w, color );
00215
if ( current )
00216 showPage( w );
00217 setTabEnabled( w, enabled );
00218 blockSignals(
false);
00219
00220 emit (
movedTab( from, to ) );
00221 }
00222
00223
bool KTabWidget::isEmptyTabbarSpace(
const QPoint &p )
const
00224
{
00225
QPoint point( p );
00226
QSize size( tabBar()->sizeHint() );
00227
if ( ( tabPosition()==Top && point.y()< size.height() ) || ( tabPosition()==Bottom && point.y()>(height()-size.height() ) ) ) {
00228
00229
KTabWidget *that = const_cast<KTabWidget*>(
this);
00230
QWidget *rightcorner = that->cornerWidget( TopRight );
00231
if ( rightcorner ) {
00232
if ( point.x()>=width()-rightcorner->width() )
00233
return false;
00234 }
00235
QWidget *leftcorner = that->cornerWidget( TopLeft );
00236
if ( leftcorner ) {
00237
if ( point.x()<=leftcorner->width() )
00238
return false;
00239 point.setX( point.x()-size.height() );
00240 }
00241
if ( tabPosition()==Bottom )
00242 point.setY( point.y()-( height()-size.height() ) );
00243
QTab *tab = tabBar()->selectTab( point);
00244
if( tab== 0L )
00245
return true;
00246 }
00247
return false;
00248 }
00249
00250 void KTabWidget::setHoverCloseButton(
bool button )
00251 {
00252 static_cast<KTabBar*>(tabBar())->setHoverCloseButton( button );
00253 }
00254
00255
bool KTabWidget::hoverCloseButton()
const
00256
{
00257
return static_cast<KTabBar*>(tabBar())->hoverCloseButton();
00258 }
00259
00260 void KTabWidget::setHoverCloseButtonDelayed(
bool delayed )
00261 {
00262 static_cast<KTabBar*>(tabBar())->setHoverCloseButtonDelayed( delayed );
00263 }
00264
00265
bool KTabWidget::hoverCloseButtonDelayed()
const
00266
{
00267
return static_cast<KTabBar*>(tabBar())->hoverCloseButtonDelayed();
00268 }
00269
00270
void KTabWidget::closeRequest(
int index )
00271 {
00272 emit(
closeRequest( page( index ) ) );
00273 }
00274
00275
#include "ktabwidget.moc"