Commit e12174c2 authored by Robert Knight's avatar Robert Knight

Re-implement Ctrl+Shift+Left/Right to move the current tab left or right. Fix...

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
parent 72241ef4
......@@ -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);
......
......@@ -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<QWidget*> 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<NavigationPosition> 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);
......
......@@ -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<QAction*> 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<QAction*> 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();
......
......@@ -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();
......
......@@ -58,7 +58,7 @@ void ViewSplitter::adjustContainerSize(ViewContainer* container , int percentage
QList<int> 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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment