Index: ktabbar.h
===================================================================
--- ktabbar.h	(revision 929391)
+++ ktabbar.h	(working copy)
@@ -1,6 +1,7 @@
 /* This file is part of the KDE libraries
     Copyright (C) 2003 Stephan Binner <binner@kde.org>
     Copyright (C) 2003 Zack Rusin <zack@kde.org>
+    Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -49,13 +50,17 @@
      * Sets the tab reordering enabled or disabled. If enabled,
      * the user can reorder the tabs by drag and drop the tab
      * headers.
+     *
+     * @deprecated Use QTabBar::setMovable() instead.
      */
-    void setTabReorderingEnabled( bool enable );
+    KDE_DEPRECATED void setTabReorderingEnabled( bool enable );
 
     /**
      * Returns whether tab reordering is enabled.
+     *
+     * @deprecated Use QTabBar::isMovable() instead.
      */
-    bool isTabReorderingEnabled() const;
+    KDE_DEPRECATED bool isTabReorderingEnabled() const;
 
     /**
      * If enabled, a close button is shown above the tab icon.
@@ -63,11 +68,11 @@
      * close button has been clicked. Note that the tab must have
      * an icon to use this feature.
      *
-     * @deprecated Use KTabBar::setCloseButtonEnabled() instead.
+     * @deprecated Use QTabBar::setTabsClosable() instead.
      */
     KDE_DEPRECATED void setHoverCloseButton( bool );
 
-    /** @deprecated Use KTabBar::isCloseButtonEnabled() instead. */
+    /** @deprecated Use QTabBar::tabsClosable() instead. */
     KDE_DEPRECATED bool hoverCloseButton() const;
 
     /**
@@ -75,11 +80,11 @@
      * minor delay has been passed. This prevents that user
      * accidentally closes a tab.
      *
-     * @deprecated Use KTabBar::setCloseButtonEnabled() instead.
+     * @deprecated Use QTabBar::setTabsClosable() instead.
      */
     KDE_DEPRECATED void setHoverCloseButtonDelayed( bool );
 
-    /** @deprecated Use KTabBar::isCloseButtonEnabled() instead. */
+    /** @deprecated Use QTabBar::tabsClosable() instead. */
     KDE_DEPRECATED bool hoverCloseButtonDelayed() const;
 
     /**
@@ -88,28 +93,36 @@
      * has been clicked.
      *
      * @since 4.1
+     *
+     * @deprecated Use QTabBar::setTabsClosable() instead.
      */
-    void setCloseButtonEnabled( bool );
+    KDE_DEPRECATED void setCloseButtonEnabled( bool );
 
     /**
      * Returns true if the close button is shown on tabs.
      *
      * @since 4.1
+     *
+     * @deprecated Use QTabBar::tabsClosable() instead.
      */
-    bool isCloseButtonEnabled() const;
+    KDE_DEPRECATED bool isCloseButtonEnabled() const;
 
     /**
      * Sets the 'activate previous tab on close' feature enabled
      * or disabled. If enabled, as soon as you close a tab, the
      * previously selected tab is activated again.
+     *
+     * @deprecated Use QTabBar::setSelectionBehaviorOnRemove() instead.
      */
-    void setTabCloseActivatePrevious( bool );
+    KDE_DEPRECATED void setTabCloseActivatePrevious( bool );
 
     /**
      * Returns whether the 'activate previous tab on close' feature
      * is enabled.
+     *
+     * @deprecated Use QTabBar::selectionBehaviorOnRemove() instead.
      */
-    bool tabCloseActivatePrevious() const;
+    KDE_DEPRECATED bool tabCloseActivatePrevious() const;
 
     /**
      * Selects the tab which has a tab header at
@@ -135,8 +148,8 @@
     void initiateDrag( int );
     void testCanDecode( const QDragMoveEvent*, bool& );
     void receivedDropEvent( int, QDropEvent* );
-    void moveTab( int, int );
-    void closeRequest( int );
+    QT_MOC_COMPAT void moveTab( int, int );
+    QT_MOC_COMPAT void closeRequest( int );
 #ifndef QT_NO_WHEELEVENT
     void wheelDelta( int );
 #endif
Index: ktabwidget.cpp
===================================================================
--- ktabwidget.cpp	(revision 929391)
+++ ktabwidget.cpp	(working copy)
@@ -1,6 +1,7 @@
 /* This file is part of the KDE libraries
   Copyright (C) 2003 Stephan Binner <binner@kde.org>
   Copyright (C) 2003 Zack Rusin <zack@kde.org>
+  Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
@@ -192,7 +193,7 @@
   connect(tabBar(), SIGNAL(testCanDecode(const QDragMoveEvent *, bool & )), SIGNAL(testCanDecode(const QDragMoveEvent *, bool & )));
   connect(tabBar(), SIGNAL(receivedDropEvent( int, QDropEvent * )), SLOT(receivedDropEvent( int, QDropEvent * )));
   connect(tabBar(), SIGNAL(moveTab( int, int )), SLOT(moveTab( int, int )));
-  connect(tabBar(), SIGNAL(closeRequest( int )), SLOT(closeRequest( int )));
+  connect(tabBar(), SIGNAL(tabCloseRequested( int )), SLOT(closeRequest( int )));
   connect(tabBar(), SIGNAL(currentChanged( int )), SLOT(currentChanged( int )));
 #ifndef QT_NO_WHEELEVENT
   connect(tabBar(), SIGNAL(wheelDelta( int )), SLOT(wheelDelta( int )));
@@ -545,7 +546,7 @@
 void KTabWidget::setHoverCloseButton( bool button )
 {
   // deprecated
-  setCloseButtonEnabled( button );
+  setTabsClosable( button );
 }
 
 bool KTabWidget::hoverCloseButton() const
@@ -563,17 +564,17 @@
 bool KTabWidget::hoverCloseButtonDelayed() const
 {
   // deprecated
-  return isCloseButtonEnabled();
+  return tabsClosable();
 }
 
 void KTabWidget::setCloseButtonEnabled( bool enable )
 {
-  static_cast<KTabBar*>( tabBar() )->setCloseButtonEnabled( enable );
+  static_cast<KTabBar*>( tabBar() )->setTabsClosable( enable );
 }
 
 bool KTabWidget::isCloseButtonEnabled() const
 {
-  return static_cast<KTabBar*>( tabBar() )->isCloseButtonEnabled();
+  return static_cast<KTabBar*>( tabBar() )->tabsClosable();
 }
 
 void KTabWidget::setAutomaticResizeTabs( bool enabled )
Index: ktabbar.cpp
===================================================================
--- ktabbar.cpp	(revision 929391)
+++ ktabbar.cpp	(working copy)
@@ -1,6 +1,7 @@
 /* This file is part of the KDE libraries
     Copyright (C) 2003 Stephan Binner <binner@kde.org>
     Copyright (C) 2003 Zack Rusin <zack@kde.org>
+    Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -44,14 +45,9 @@
       : mReorderStartTab( -1 ),
         mReorderPreviousTab( -1 ),
         mDragSwitchTab( -1 ),
-        mHoveredCloseIconIndex( -1 ),
         mActivateDragSwitchTabTimer( 0 ),
-        mHoveredCloseIcon( 0 ),
-        mInactiveCloseIcon( 0 ),
-        mActiveCloseIcon( 0 ),
         mTabReorderingEnabled( false ),
-        mTabCloseActivatePrevious( false ),
-        mTabCloseButtonClicked( false )
+        mTabCloseActivatePrevious( false )
     {
     }
 
@@ -59,16 +55,10 @@
     int mReorderStartTab;
     int mReorderPreviousTab;
     int mDragSwitchTab;
-    int mHoveredCloseIconIndex;
-    //QTab *mDragSwitchTab;
     QTimer *mActivateDragSwitchTabTimer;
-    QPixmap *mHoveredCloseIcon;
-    QPixmap *mInactiveCloseIcon;
-    QPixmap *mActiveCloseIcon;
 
     bool mTabReorderingEnabled : 1;
     bool mTabCloseActivatePrevious : 1;
-    bool mTabCloseButtonClicked : 1;
 
 };
 
@@ -82,21 +72,13 @@
   d->mActivateDragSwitchTabTimer = new QTimer( this );
   d->mActivateDragSwitchTabTimer->setSingleShot( true );
   connect( d->mActivateDragSwitchTabTimer, SIGNAL( timeout() ), SLOT( activateDragSwitchTab() ) );
+  connect( this, SIGNAL(tabCloseRequested(int)), this, SIGNAL(closeRequest(int))); // just for backward compatibilty, KDE5 remove
 
   //connect( this, SIGNAL( layoutChanged() ), SLOT( onLayoutChange() ) );
 }
 
 KTabBar::~KTabBar()
 {
-  delete d->mHoveredCloseIcon;
-  d->mHoveredCloseIcon = 0;
-
-  delete d->mInactiveCloseIcon;
-  d->mInactiveCloseIcon = 0;
-
-  delete d->mActiveCloseIcon;
-  d->mActiveCloseIcon = 0;
-
   delete d;
 }
 
@@ -113,21 +95,14 @@
     emit mouseDoubleClick( tab ); //deprecated
     emit tabDoubleClicked( tab );
   }
+
+  QTabBar::mouseDoubleClickEvent( event );
 }
 
 void KTabBar::mousePressEvent( QMouseEvent *event )
 {
   if ( event->button() == Qt::LeftButton ) {
     d->mDragStart = event->pos();
-    if ( isCloseButtonEnabled() ) {
-      const QPoint pos = event->pos();
-      const int tabIndex = tabAt( pos );
-      if (closeButtonRect( tabIndex ).contains( pos )) {
-        // the close button is clicked - prevent that the tab gets activated
-        d->mTabCloseButtonClicked = true;
-        return;
-      }
-    }
   } else if( event->button() == Qt::RightButton ) {
     int tab = selectTab( event->pos() );
     if ( tab != -1 ) {
@@ -143,26 +118,6 @@
 
 void KTabBar::mouseMoveEvent( QMouseEvent *event )
 {
-  if ( isCloseButtonEnabled() ) {
-    if ( d->mHoveredCloseIconIndex >= 0) {
-      // reset previously hovered close button
-      update( closeButtonRect( d->mHoveredCloseIconIndex ));
-      d->mHoveredCloseIconIndex = -1;
-    }
-
-    const QPoint pos = event->pos();
-    const int tabCount = count();
-    for ( int i = 0; i < tabCount; ++i ) {
-      const QRect rect = closeButtonRect( i );
-      if (rect.contains( pos )) {
-        // update currently hovered close button
-        d->mHoveredCloseIconIndex = i;
-        update( rect );
-        break;
-      }
-    }
-  }
-
   if ( event->buttons() == Qt::LeftButton ) {
     int tab = selectTab( event->pos() );
     if ( d->mDragSwitchTab && tab != d->mDragSwitchTab ) {
@@ -238,16 +193,6 @@
 {
   switch ( event->button() ) {
   case Qt::LeftButton:
-    if ( isCloseButtonEnabled() ) {
-      update(closeButtonRect( d->mHoveredCloseIconIndex ));
-
-      const QPoint pos = event->pos();
-      const int tabIndex = tabAt( pos );
-      if (d->mTabCloseButtonClicked && closeButtonRect( tabIndex ).contains( pos )) {
-        d->mHoveredCloseIconIndex = -1;
-        emit closeRequest( tabIndex );
-      }
-    }
     break;
 
   case Qt::MidButton:
@@ -269,7 +214,6 @@
     break;
   }
 
-  d->mTabCloseButtonClicked = false;
   QTabBar::mouseReleaseEvent( event );
 }
 
@@ -329,38 +273,16 @@
 void KTabBar::paintEvent( QPaintEvent *event )
 {
   QTabBar::paintEvent( event );
-
-  if ( isCloseButtonEnabled() ) {
-    QPainter painter( this );
-    const int tabCount = count();
-    for ( int i = 0; i < tabCount; ++i ) {
-      QPixmap icon;
-      if ( i == d->mHoveredCloseIconIndex)
-        icon = *d->mActiveCloseIcon;
-      else if ( i == currentIndex() )
-        icon = *d->mHoveredCloseIcon;
-      else
-        icon = *d->mInactiveCloseIcon;
-
-      painter.drawPixmap( closeButtonPos( i ), icon );
-    }
-  }
 }
 
 void KTabBar::leaveEvent( QEvent *event )
 {
   QTabBar::leaveEvent( event );
-  if ( d->mHoveredCloseIconIndex >= 0 ) {
-    update( closeButtonRect( d->mHoveredCloseIconIndex ));
-    d->mHoveredCloseIconIndex = -1;
-  }
 }
 
 QSize KTabBar::tabSizeHint( int index ) const
 {
   QSize size = QTabBar::tabSizeHint( index );
-  if ( isCloseButtonEnabled() )
-      size.rwidth() += KIconLoader::SizeSmall * 3 / 2;
 
   return size;
 }
@@ -399,13 +321,13 @@
 void KTabBar::setHoverCloseButton( bool button )
 {
   // deprecated
-  setCloseButtonEnabled( button );
+  setTabsClosable(button);
 }
 
 bool KTabBar::hoverCloseButton() const
 {
   // deprecated
-  return isCloseButtonEnabled();
+  return tabsClosable();
 }
 
 void KTabBar::setHoverCloseButtonDelayed( bool delayed )
@@ -422,40 +344,12 @@
 
 void KTabBar::setCloseButtonEnabled( bool enable )
 {
-  if ( enable == isCloseButtonEnabled() )
-    return;
-
-  d->mHoveredCloseIconIndex = -1;
-  if ( enable ) {
-    Q_ASSERT( d->mHoveredCloseIcon == 0 );
-    Q_ASSERT( d->mInactiveCloseIcon == 0 );
-    Q_ASSERT( d->mActiveCloseIcon == 0 );
-
-    const QPixmap icon = KIconLoader::global()->loadIcon( "dialog-close", KIconLoader::Small );
-
-    d->mHoveredCloseIcon = new QPixmap( icon );
-    KIconEffect::semiTransparent( *d->mHoveredCloseIcon );
-
-    KIconEffect iconEffect;
-    d->mInactiveCloseIcon = new QPixmap( iconEffect.apply( icon, KIconLoader::Small, KIconLoader::DisabledState ));
-
-    KIconEffect::semiTransparent( *d->mInactiveCloseIcon );
-    d->mActiveCloseIcon = new QPixmap( icon );
-  } else {
-    delete d->mHoveredCloseIcon;
-    d->mHoveredCloseIcon = 0;
-
-    delete d->mInactiveCloseIcon;
-    d->mInactiveCloseIcon = 0;
-
-    delete d->mActiveCloseIcon;
-    d->mActiveCloseIcon = 0;
-  }
+  QTabBar::setTabsClosable(enable);
 }
 
 bool KTabBar::isCloseButtonEnabled() const
 {
-  return d->mHoveredCloseIcon != 0;
+  return QTabBar::tabsClosable();
 }
 
 void KTabBar::tabLayoutChange()
@@ -476,41 +370,14 @@
 
 QPoint KTabBar::closeButtonPos( int tabIndex ) const
 {
-  QPoint buttonPos;
-  if ( tabIndex < 0 ) {
-    return buttonPos;
-  }
-
-  int availableHeight = height();
-  if ( tabIndex == currentIndex() ) {
-    QStyleOption option;
-    option.initFrom(this);
-    availableHeight -= style()->pixelMetric( QStyle::PM_TabBarTabShiftVertical, &option, this );
-  }
-
-  const QRect tabBounds = tabRect( tabIndex );
-  const int xInc = (height() - KIconLoader::SizeSmall) / 2;
-
-  if ( layoutDirection() == Qt::RightToLeft ) {
-    buttonPos = tabBounds.topLeft();
-    buttonPos.rx() += xInc;
-  } else {
-    buttonPos = tabBounds.topRight();
-    buttonPos.rx() -= KIconLoader::SizeSmall + xInc;
-  }
-  buttonPos.ry() += (availableHeight - KIconLoader::SizeSmall) / 2;
-
-  return buttonPos;
+  Q_UNUSED(tabIndex);
+  return QPoint();
 }
 
 QRect KTabBar::closeButtonRect( int tabIndex ) const
 {
-  QRect rect;
-  if ( tabIndex >= 0 ) {
-    rect.setTopLeft(closeButtonPos( tabIndex ));
-    rect.setSize(QSize( KIconLoader::SizeSmall, KIconLoader::SizeSmall));
-  }
-  return rect;
+  Q_UNUSED(tabIndex);
+  return QRect();
 }
 
 #include "ktabbar.moc"
Index: ktabwidget.h
===================================================================
--- ktabwidget.h	(revision 929391)
+++ ktabwidget.h	(working copy)
@@ -1,6 +1,7 @@
 /* This file is part of the KDE libraries
     Copyright (C) 2003 Stephan Binner <binner@kde.org>
     Copyright (C) 2003 Zack Rusin <zack@kde.org>
+    Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -78,6 +79,8 @@
     /**
      * Returns true if tab ordering with the middle mouse button
      * has been enabled.
+     *
+     * @deprecated Use QTabWidget::isMovable() instead.
      */
     bool isTabReorderingEnabled() const;
 
@@ -85,7 +88,7 @@
      * Returns true if the close button is shown on tabs
      * when mouse is hovering over them.
      *
-     * @deprecated Use KTabWidget::isCloseButtonEnabled() instead.
+     * @deprecated Use QTabWidget::tabsClosable() instead.
      */
     KDE_DEPRECATED bool hoverCloseButton() const;
 
@@ -93,7 +96,7 @@
      * Returns true if the close button is shown on tabs
      * after a delay.
      *
-     * @deprecated Use KTabWidget::isCloseButtonEnabled() instead.
+     * @deprecated Use QTabWidget::setTabsClosable() instead.
      */
     KDE_DEPRECATED bool hoverCloseButtonDelayed() const;
 
@@ -101,14 +104,18 @@
      * Returns true if the close button is shown on tabs.
      *
      * @since 4.1
+     *
+     * @deprecated Use QTabWidget::tabsClosable() instead.
      */
-    bool isCloseButtonEnabled() const;
+    KDE_DEPRECATED bool isCloseButtonEnabled() const;
 
     /**
      * Returns true if closing the current tab activates the previous
      * actice tab instead of the one to the right.
+     *
+     * @deprecated Use QTabBar::selectionBehaviorOnRemove() instead.
      */
-    bool tabCloseActivatePrevious() const;
+    KDE_DEPRECATED bool tabCloseActivatePrevious() const;
 
     /**
      * Returns true if calling setTitle() will resize tabs
@@ -197,15 +204,17 @@
      *
      * You can connect to signal movedTab(int, int) which will notify
      * you from which index to which index a tab has been moved.
+     *
+     * @deprecated Use QTabWidget::setMovable() instead.
      */
-    void setTabReorderingEnabled( bool enable );
+    QT_MOC_COMPAT void setTabReorderingEnabled( bool enable );
 
     /**
      * If \a enable is true, a close button will be shown on mouse hover
      * over tab icons which will emit signal closeRequest( QWidget * )
      * when pressed.
      *
-     * @deprecated Use KTabWidget::setCloseButtonEnabled() instead.
+     * @deprecated Use QTabWidget::setTabsClosable() instead.
      */
     QT_MOC_COMPAT void setHoverCloseButton( bool enable );
 
@@ -213,7 +222,7 @@
      * If \a delayed is true, a close button will be shown on mouse hover
      * over tab icons after mouse double click delay else immediately.
      *
-     * @deprecated Use KTabWidget::setCloseButtonEnabled() instead.
+     * @deprecated Use QTabWidget::setTabsClosable() instead.
      */
     QT_MOC_COMPAT void setHoverCloseButtonDelayed( bool delayed );
 
@@ -223,14 +232,18 @@
      * has been clicked.
      *
      * @since 4.1
+     *
+     * @deprecated Use QTabWidget::setTabsClosable() instead.
      */
-    void setCloseButtonEnabled( bool );
+    QT_MOC_COMPAT void setCloseButtonEnabled( bool );
 
     /**
      * If \a previous is true, closing the current tab activates the
      * previous active tab instead of the one to the right.
+     *
+     * @deprecated Use QTabWidget::setSelectionBehaviorOnRemove() instead.
      */
-    void setTabCloseActivatePrevious( bool previous );
+    QT_MOC_COMPAT void setTabCloseActivatePrevious( bool previous );
 
     /**
      * If \a enable is true, tabs will be resized to the width of the tab bar.
