From e12174c2ffca41cd6526ee38551212ff26b5fb58 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Tue, 3 Jul 2007 10:53:44 +0000 Subject: [PATCH] Re-implement Ctrl+Shift+Left/Right to move the current tab left or right. Fix float->int conversion warning. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=682750 --- src/ViewContainer.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/ViewContainer.h | 32 ++++++++++++++++++++++++++++++++ src/ViewManager.cpp | 30 ++++++++++++++++++++++++++++-- src/ViewManager.h | 4 ++++ src/ViewSplitter.cpp | 2 +- 5 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp index 62f910538..8131a4c29 100644 --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -62,6 +62,32 @@ ViewContainer::~ViewContainer() { emit destroyed(this); } +void ViewContainer::moveViewWidget( int , int ) {} + +void ViewContainer::moveActiveView( MoveDirection direction ) +{ + const int currentIndex = _views.indexOf( activeView() ) ; + int newIndex = -1; + + switch ( direction ) + { + case MoveViewLeft: + newIndex = qMax( currentIndex-1 , 0 ); + break; + case MoveViewRight: + newIndex = qMin( currentIndex+1 , _views.count() -1 ); + break; + } + + Q_ASSERT( newIndex != -1 ); + + moveViewWidget( currentIndex , newIndex ); + + _views.swap(currentIndex,newIndex); + + setActiveView( _views[newIndex] ); +} + void ViewContainer::setNavigationDisplayMode(NavigationDisplayMode mode) { _navigationDisplayMode = mode; @@ -537,6 +563,21 @@ void TabbedViewContainerV2::tabDoubleClicked(int tab) //emit duplicateRequest(); } } +void TabbedViewContainerV2::moveViewWidget( int fromIndex , int toIndex ) +{ + QString text = _tabBar->tabText(fromIndex); + QIcon icon = _tabBar->tabIcon(fromIndex); + + // FIXME - This will lose properties of the tab other than + // their text and icon when moving them + + _tabBar->removeTab(fromIndex); + _tabBar->insertTab(toIndex,icon,text); + + QWidget* widget = _stackWidget->widget(fromIndex); + _stackWidget->removeWidget(widget); + _stackWidget->insertWidget(toIndex,widget); +} void TabbedViewContainerV2::currentTabChanged(int index) { _stackWidget->setCurrentIndex(index); diff --git a/src/ViewContainer.h b/src/ViewContainer.h index 5944b8ad0..74b9864b2 100644 --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -204,6 +204,28 @@ public: */ void activatePreviousView(); + /** + * This enum describes the directions + * in which views can be re-arranged within the container + * using the moveActiveView() method. + */ + enum MoveDirection + { + /** Moves the view to the left. */ + MoveViewLeft, + /** Moves the view to the right. */ + MoveViewRight + }; + + /** + * Moves the active view within the container and + * updates the order in which the views are shown + * in the container's navigation widget. + * + * The default implementation does nothing. + */ + void moveActiveView( MoveDirection direction ); + signals: /** Emitted when the container is deleted */ void destroyed(ViewContainer* container); @@ -254,6 +276,14 @@ protected: /** Returns the widgets which are associated with a particular navigation item */ QList widgetsForItem( ViewProperties* item ) const; + /** + * Rearranges the order of widgets in the container. + * + * @param fromIndex Current index of the widget to move + * @param toIndex New index for the widget + */ + virtual void moveViewWidget( int fromIndex , int toIndex ); + private slots: void viewDestroyed(QObject* view); @@ -361,11 +391,13 @@ public: virtual QList supportedNavigationPositions() const; + protected: virtual void addViewWidget(QWidget* view); virtual void removeViewWidget(QWidget* view); virtual void navigationDisplayModeChanged(NavigationDisplayMode mode); virtual void navigationPositionChanged(NavigationPosition position); + virtual void moveViewWidget( int fromIndex , int toIndex ); private slots: void updateTitle(ViewProperties* item); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 7eda57e20..3875f9fa6 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -107,7 +107,10 @@ void ViewManager::setupActions() KAction* nextViewAction = new KAction( i18n("Next View") , this ); KAction* previousViewAction = new KAction( i18n("Previous View") , this ); QAction* nextContainerAction = new QAction( i18n("Next View Container") , this); - + + QAction* moveViewLeftAction = new QAction( i18n("Move View Left") , this ); + QAction* moveViewRightAction = new QAction( i18n("Move View Right") , this ); + // list of actions that should only be enabled when there are multiple view // containers open QList multiViewOnlyActions; @@ -175,7 +178,8 @@ void ViewManager::setupActions() collection->addAction("next-view",nextViewAction); collection->addAction("previous-view",previousViewAction); collection->addAction("next-container",nextContainerAction); - + collection->addAction("move-view-left",moveViewLeftAction); + collection->addAction("move-view-right",moveViewRightAction); } QListIterator iter(multiViewOnlyActions); @@ -184,6 +188,7 @@ void ViewManager::setupActions() connect( this , SIGNAL(splitViewToggle(bool)) , iter.next() , SLOT(setEnabled(bool)) ); } + // keyboard shortcut only actions KShortcut nextViewShortcut = nextViewAction->shortcut(); nextViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Right) ); nextViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageUp) ); @@ -201,8 +206,29 @@ void ViewManager::setupActions() nextContainerAction->setShortcut( QKeySequence(Qt::SHIFT+Qt::Key_Tab) ); connect( nextContainerAction , SIGNAL(triggered()) , this , SLOT(nextContainer()) ); _viewSplitter->addAction(nextContainerAction); + + moveViewLeftAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Left) ); + connect( moveViewLeftAction , SIGNAL(triggered()) , this , SLOT(moveActiveViewLeft()) ); + _viewSplitter->addAction(moveViewLeftAction); + moveViewRightAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Right) ); + connect( moveViewRightAction , SIGNAL(triggered()) , this , SLOT(moveActiveViewRight()) ); + _viewSplitter->addAction(moveViewRightAction); } +void ViewManager::moveActiveViewLeft() +{ + qDebug() << "Moving active view to the left"; + ViewContainer* container = _viewSplitter->activeContainer(); + Q_ASSERT( container ); + container->moveActiveView( ViewContainer::MoveViewLeft ); +} +void ViewManager::moveActiveViewRight() +{ + qDebug() << "Moving active view to the right"; + ViewContainer* container = _viewSplitter->activeContainer(); + Q_ASSERT( container ); + container->moveActiveView( ViewContainer::MoveViewRight ); +} void ViewManager::nextContainer() { _viewSplitter->activateNextContainer(); diff --git a/src/ViewManager.h b/src/ViewManager.h index ecb7b6c53..751c04f19 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -179,6 +179,10 @@ private slots: // sends input from active view to all sessions void sendInputToAll(); + // moves active view to the left + void moveActiveViewLeft(); + // moves active view to the right + void moveActiveViewRight(); private: void setupActions(); void focusActiveView(); diff --git a/src/ViewSplitter.cpp b/src/ViewSplitter.cpp index c8a69b688..1c0737338 100644 --- a/src/ViewSplitter.cpp +++ b/src/ViewSplitter.cpp @@ -58,7 +58,7 @@ void ViewSplitter::adjustContainerSize(ViewContainer* container , int percentage QList containerSizes = sizes(); int oldSize = containerSizes[containerIndex]; - int newSize = oldSize * ( 1.0 + percentage/100.0 ); + int newSize = (int)(oldSize * ( 1.0 + percentage/100.0 )); // qDebug() << "Old container size:" << oldSize << ", new size:" << newSize;