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
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
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"