[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    [PATCH] Support for activate previous tab in KTabWidget
From:       Eduardo RE <edulix () gmail ! com>
Date:       2008-09-28 12:02:59
Message-ID: 200809281403.08962.edulix () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]

[Attachment #6 (multipart/alternative)]


Hello!

As seen in http://bugs.kde.org/show_bug.cgi?id=171369 KTabWidget lost the 
feature of activate previous tab when switching from Qt 3 to Qt 4. This patch 
tries to fix that. Is it ok to commit? I *think* it doesn't break binary 
compatibility.

Regards,
      Eduardo Robles Elvira.
-- 
"The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man." (George Bernard Shaw)

[Attachment #9 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; \
font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Hello!</p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">As seen in http://bugs.kde.org/show_bug.cgi?id=171369 \
KTabWidget lost the feature of activate previous tab when switching from Qt 3 to Qt 4. This \
patch tries to fix that. Is it ok to commit? I *think* it doesn't break binary \
compatibility.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p> \
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Regards,</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">      Eduardo Robles Elvira.</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">-- </p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">"The reasonable man \
adapts himself to the world; the unreasonable one</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">persists in trying to adapt the world to himself. Therefore all progress</p> \
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">depends on the unreasonable man." \
(George Bernard Shaw)</p></body></html>


["ktabwidget.patch" (text/x-patch)]

Index: ktabwidget.cpp
===================================================================
--- ktabwidget.cpp	(revision 865523)
+++ ktabwidget.cpp	(working copy)
@@ -28,6 +28,7 @@
 #include <QtGui/QStyleOption>
 #include <QtGui/QTextDocument>
 #include <QtGui/QWheelEvent>
+#include <QtCore/QList>
 
 #include <ksharedconfig.h>
 #include <kiconloader.h>
@@ -60,11 +61,14 @@
     //holds the full names of the tab, otherwise all we
     //know about is the shortened name
     QStringList m_tabNames;
+    
+    // Used when tabCloseActivatePrevious is enabled
+    QList<QWidget*> m_previousTabList;
 
-
     bool isEmptyTabbarSpace( const QPoint & )  const;
     void resizeTabs( int changedTabIndex = -1 );
     void updateTab( int index );
+    void removeTab( int index );
 };
 
 bool KTabWidget::Private::isEmptyTabbarSpace( const QPoint &point ) const
@@ -95,6 +99,21 @@
   return false;
 }
 
+void KTabWidget::Private::removeTab( int index )
+{
+  int prevIndex = -1;
+  m_previousTabList.removeAll( m_parent->widget( index ) );
+  if ( !m_previousTabList.isEmpty() )
+  {
+    prevIndex =  m_parent->indexOf( m_previousTabList.takeFirst() );
+  }
+  
+  m_parent->QTabWidget::removeTab( index );
+  
+  if ( prevIndex != -1 && m_parent->tabCloseActivatePrevious() )
+    m_parent->setCurrentIndex( prevIndex );
+}
+
 void KTabWidget::Private::resizeTabs( int changeTabIndex )
 {
   int newMaxLength;
@@ -164,6 +183,7 @@
   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(currentChanged( int )), SLOT(currentChanged( int )));
 #ifndef QT_NO_WHEELEVENT
   connect(tabBar(), SIGNAL(wheelDelta( int )), SLOT(wheelDelta( int )));
 #endif
@@ -491,13 +511,13 @@
 
     setUpdatesEnabled(false);
 
-    QTabWidget::removeTab( indexOf( widget ) );
+    d->removeTab( indexOf( widget ) );
     d->resizeTabs();
 
     setUpdatesEnabled(true);
 
   } else {
-    QTabWidget::removeTab( indexOf( widget ) );
+    d->removeTab( indexOf( widget ) );
   }
 }
 
@@ -507,13 +527,13 @@
 
     setUpdatesEnabled(false);
 
-    QTabWidget::removeTab( index );
+    d->removeTab( index );
     d->resizeTabs();
 
     setUpdatesEnabled(true);
 
   } else {
-    QTabWidget::removeTab( index );
+    d->removeTab( index );
   }
 }
 
@@ -598,4 +618,13 @@
    d->m_tabNames.removeAt( idx );
 }
 
+void KTabWidget::currentChanged( int idx )
+{
+   d->m_previousTabList.prepend( widget(idx) );
+   
+   // Maximum number of entries equal to the number of tabs
+   if(d->m_previousTabList.count() > tabBar()->count())
+        d->m_previousTabList.removeLast();
+}
+
 #include "ktabwidget.moc"
Index: ktabwidget.h
===================================================================
--- ktabwidget.h	(revision 865523)
+++ ktabwidget.h	(working copy)
@@ -327,6 +327,7 @@
     virtual void mouseDoubleClick( int );
     virtual void mouseMiddleClick( int );
     virtual void closeRequest( int );
+    void currentChanged( int );
 #ifndef QT_NO_WHEELEVENT
     virtual void wheelDelta( int );
 #endif

["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic