From c43d476a1d3fc67fcf47dbf21f3b45938cd2cda0 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Thu, 10 May 2007 01:09:55 +0000 Subject: [PATCH] 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 --- src/ViewManager.cpp | 23 +++++++++++++++++++++-- src/ViewManager.h | 2 ++ src/ViewSplitter.cpp | 32 ++++++++++++++++++++++++++++++++ src/ViewSplitter.h | 11 +++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 5d9b9e431..18ece15b8 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -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; } diff --git a/src/ViewManager.h b/src/ViewManager.h index 60b6efbb1..a8d22c538 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -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(); diff --git a/src/ViewSplitter.cpp b/src/ViewSplitter.cpp index 4bb77cbd2..a2ed705a3 100644 --- a/src/ViewSplitter.cpp +++ b/src/ViewSplitter.cpp @@ -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 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" ; diff --git a/src/ViewSplitter.h b/src/ViewSplitter.h index 334877213..652fd991c 100644 --- a/src/ViewSplitter.h +++ b/src/ViewSplitter.h @@ -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 */