|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[PATCH] Support for activate previous tab in KTabWidgetHello! 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) [ktabwidget.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 >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << |
|
|
Re: [PATCH] Support for activate previous tab in KTabWidgetOn Sun, Sep 28, 2008 at 02:02:59PM +0200, Eduardo Robles Elvira wrote:
> I *think* it doesn't break binary compatibility. > i think so, too. ;) > +++ ktabwidget.cpp (working copy) > @@ -60,11 +61,14 @@ > + // Used when tabCloseActivatePrevious is enabled > + QList<QWidget*> m_previousTabList; > QStack preferably. > +void KTabWidget::Private::removeTab( int index ) > +{ > + m_previousTabList.removeAll( m_parent->widget( index ) ); > +void KTabWidget::currentChanged( int idx ) > +{ > + // Maximum number of entries equal to the number of tabs > + if(d->m_previousTabList.count() > tabBar()->count()) > + d->m_previousTabList.removeLast(); > the only way to pop from the stack is to delete tabs. consequently it makes no sense to permit having one tab multiple times. so use removeOne() above and here before the push(). -- Hi! I'm a .signature virus! Copy me into your ~/.signature, please! -- Confusion, chaos, panic - my work here is done. >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << |
| Free Forum Powered by Nabble | Forum Help |