Menu items and keyboard shortcuts to change the size of the current view in split-view mode. Use Ctrl+Shift+[ to shrink the size of the current view by 10% and Ctrl+Shift+] to increase the size of the current view by 10%

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=663091
This commit is contained in:
Robert Knight
2007-05-10 01:09:55 +00:00
parent 9ea3227384
commit c43d476a1d
4 changed files with 66 additions and 2 deletions

View File

@@ -142,7 +142,19 @@ void ViewManager::setupActions()
detachViewAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_H) );
connect( detachViewAction , SIGNAL(triggered()) , this , SLOT(detachActiveView()) );
// Expand & Shrink Active View
KAction* expandActiveAction = new KAction( i18n("Expand View") , this );
expandActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_BracketRight) );
collection->addAction("expand-active-view",expandActiveAction);
connect( expandActiveAction , SIGNAL(triggered()) , this , SLOT(expandActiveView()) );
KAction* shrinkActiveAction = new KAction( i18n("Shrink View") , this );
shrinkActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_BracketLeft) );
collection->addAction("shrink-active-view",shrinkActiveAction);
connect( shrinkActiveAction , SIGNAL(triggered()) , this , SLOT(shrinkActiveView()) );
// Next / Previous View , Next Container
collection->addAction("next-view",nextViewAction);
collection->addAction("previous-view",previousViewAction);
collection->addAction("next-container",nextContainerAction);
@@ -316,6 +328,14 @@ void ViewManager::removeContainer(ViewContainer* container)
container->deleteLater();
emit splitViewToggle(_viewSplitter->containers().count() > 1);
}
void ViewManager::expandActiveView()
{
_viewSplitter->adjustContainerSize(_viewSplitter->activeContainer(),10);
}
void ViewManager::shrinkActiveView()
{
_viewSplitter->adjustContainerSize(_viewSplitter->activeContainer(),-10);
}
void ViewManager::closeActiveView()
{
// only do something if there is more than one container active
@@ -498,7 +518,6 @@ TerminalDisplay* ViewManager::createTerminalDisplay()
display->setCutToBeginningOfLine(true);
display->setTerminalSizeStartup(false);
display->setScrollBarLocation(TerminalDisplay::SCROLLBAR_RIGHT);
return display;
}

View File

@@ -140,6 +140,8 @@ private slots:
void splitTopBottom();
void closeActiveView();
void closeOtherViews();
void expandActiveView();
void shrinkActiveView();
// called when the "Detach View" menu item is selected
void detachActiveView();

View File

@@ -49,6 +49,38 @@ void ViewSplitter::childEmpty(ViewSplitter* splitter)
emit empty(this);
}
void ViewSplitter::adjustContainerSize(ViewContainer* container , int percentage)
{
int containerIndex = indexOf(container->containerWidget());
Q_ASSERT( containerIndex != -1 );
QList<int> containerSizes = sizes();
int oldSize = containerSizes[containerIndex];
int newSize = oldSize * ( 1.0 + percentage/100.0 );
// qDebug() << "Old container size:" << oldSize << ", new size:" << newSize;
int perContainerDelta = ( (newSize-oldSize) / (count()-1) ) * (-1);
// qDebug() << "Changing sizes of other containers by " << perContainerDelta << "pixels.";
for ( int i = 0 ; i < containerSizes.count() ; i++ )
{
//qDebug() << "Container" << i << "old size =" << containerSizes[i];
if ( i == containerIndex )
containerSizes[i] = newSize;
else
containerSizes[i] = containerSizes[i] + perContainerDelta;
//qDebug() << "Container" << i << "new size =" << containerSizes[i];
}
setSizes(containerSizes);
}
ViewSplitter* ViewSplitter::activeSplitter()
{
// qDebug() << "BEGIN activeSplitter" ;

View File

@@ -98,6 +98,17 @@ public:
*/
void activateNextContainer();
/**
* Changes the size of the specified @p container by a given @p percentage.
* @p percentage may be positive ( in which case the size of the container
* is increased ) or negative ( in which case the size of the container
* is decreased ).
*
* The sizes of the remaining containers are increased or decreased
* uniformly to maintain the width of the splitter.
*/
void adjustContainerSize(ViewContainer* container , int percentage);
/**
* Gives the focus to the active view in the previous container
*/